Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Jan 23, 2025
1 parent 6e62e3f commit f20cd7c
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 160 deletions.
13 changes: 13 additions & 0 deletions Content.IntegrationTests/DMProject/Tests/string_interpolation.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/obj/blombo
name = "Blombo"
gender = FEMALE

/obj/blorpo
name = "Blorpo"
gender = MALE

/proc/test_string_interpolation()
var/obj/blombo/b = new
var/obj/blorpo/b2 = new
var/result_text = "[b]? Nobody likes \him. \He is awful! Unlike [b2]. \He is pretty cool!"
ASSERT(result_text == "Blombo? Nobody likes her. She is awful! Unlike Blorpo. He is pretty cool!")
1 change: 1 addition & 0 deletions Content.IntegrationTests/DMProject/code.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
test_nonlocal_var()
test_images()
test_filter_init()
test_string_interpolation()
world.log << "IntegrationTests successful, /world/New() exiting..."
14 changes: 8 additions & 6 deletions Content.Tests/DMProject/Tests/Preprocessor/macro_newline_var.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/datum/var/name

#define DEFINE_FLOORS(_PATH, _VARS) \
/obj/simulated/floor/_PATH{_VARS};\
/obj/unsimulated/floor/_PATH{_VARS};\
/obj/simulated/floor/airless/_PATH{_VARS};\
/obj/unsimulated/floor/airless/_PATH{_VARS};
/datum/simulated/floor/_PATH{_VARS};\
/datum/unsimulated/floor/_PATH{_VARS};\
/datum/simulated/floor/airless/_PATH{_VARS};\
/datum/unsimulated/floor/airless/_PATH{_VARS};

var/list/gvars_datum_init_order = list()

Expand Down Expand Up @@ -42,8 +44,8 @@ proc/RunTest()
ASSERT(test.len == 4)
InitGlobaltest2()
ASSERT(test2.len == 2)
var/obj/simulated/floor/carpet/regalcarpet/C1 = new()
var/obj/simulated/floor/carpet/regalcarpet/border/C2 = new()
var/datum/simulated/floor/carpet/regalcarpet/C1 = new()
var/datum/simulated/floor/carpet/regalcarpet/border/C2 = new()
ASSERT(C1.name == "regal carpet")
ASSERT(C2.name == "regal carpet border")

12 changes: 7 additions & 5 deletions Content.Tests/DMProject/Tests/Preprocessor/macro_numeric_path.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/obj/thing_1/dodaa
/datum/var/name

/datum/thing_1/dodaa
name = "underscore 1 test"

#define NUMPATH_OBJDEF(num) /obj/thing_##num/name = #num
#define NUMPATH_OBJDEF(num) /datum/thing_##num/name = #num

NUMPATH_OBJDEF(4)
NUMPATH_OBJDEF(stuff)

/proc/RunTest()
var/obj/thing_1/dodaa/D = new
var/datum/thing_1/dodaa/D = new
ASSERT(D.name == "underscore 1 test")
var/obj/thing_4/T = new
var/datum/thing_4/T = new
ASSERT(T.name == "4")
var/obj/thing_stuff/Y = new
var/datum/thing_stuff/Y = new
ASSERT(Y.name == "stuff")
6 changes: 3 additions & 3 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation2.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

/obj/blombo
name = "Blombo"
/datum/blombo
var/name = "Blombo"

/proc/RunTest()
var/obj/blombo/b = new
var/datum/blombo/b = new
var/result_text = "Nobody likes [b]!"
ASSERT(result_text == "Nobody likes Blombo!")
31 changes: 20 additions & 11 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation3.dm
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
/datum/test/var/name

/obj/blombo
name = "Blombo"
gender = FEMALE

/obj/blorpo
name = "Blorpo"
gender = MALE
/datum/test/test1
name = ""
/datum/test/test2
name = " " // 3 spaces
/datum/test/test3
name = "\t"

/proc/RunTest()
var/obj/blombo/b = new
var/obj/blorpo/b2 = new
var/result_text = "[b]? Nobody likes \him. \He is awful! Unlike [b2]. \He is pretty cool!"
ASSERT(result_text == "Blombo? Nobody likes her. She is awful! Unlike Blorpo. He is pretty cool!")
var/list/correct = list(
"/datum/test/test1: ",
"/datum/test/test2: ",
"/datum/test/test3: \t"
)
var/i = 1
for (var/T in typesof(/datum/test))
if(T == /datum/test)
continue
var/datum/test/D = new T()
var/true_text = correct[i]
ASSERT(true_text == "[T]: \the [D]")
++i
32 changes: 13 additions & 19 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation4.dm
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
/obj/test1
name = ""
/obj/test2
name = " " // 3 spaces
/obj/test3
name = "\t"


/proc/RunTest()
var/list/correct = list(
"/obj/test1: ",
"/obj/test2: ",
"/obj/test3: \t"
)
var/i = 1
for (var/T in typesof(/obj))
if(T == /obj)
continue
var/obj/O = new T()
var/true_text = correct[i]
ASSERT(true_text == "[T]: \the [O]")
++i
var/text = "["1"]\s"
ASSERT(text == "1s")
text = "[0]\s"
ASSERT(text == "0s")
text = "[null]\s"
ASSERT(text == "s")
text = "[1]\s"
ASSERT(text == "1")
text = "[1.00000001]\s"
ASSERT(text == "1")
text = "[1.0001]\s"
ASSERT(text == "1.0001s")
35 changes: 27 additions & 8 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation5.dm
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@


/proc/RunTest()
var/atom/O = new()
O.name = "foo"
O.gender = FEMALE
var/atom/O2 = new
O2.name = "foob"
O2.gender = MALE
var/text = "[O2], \ref[O], \his"
ASSERT(findtextEx(text,", his") != 0)
var/text = "[0]\th"
ASSERT(text == "0th")
text = "[1]\th"
ASSERT(text == "1st")
text = "[2]\th"
ASSERT(text == "2nd")
text = "[3]\th"
ASSERT(text == "3rd")
text = "[4]\th"
ASSERT(text == "4th")
text = "[-1]\th"
ASSERT(text == "-1th")
text = "[4.52]\th"
ASSERT(text == "4th")
text = "the fitness [1.7]\th is a"
ASSERT(text == "the fitness 1st is a")
text = "the fitness [99999999]\th is a"
ASSERT(text == "the fitness 100000000th is a")
text = "[null]\th"
ASSERT(text == "0th")
var/datum/D = new
text = "[D]\th"
ASSERT(text == "0th")
var/foo = "bar"
text = "[foo]\th"
ASSERT(text == "0th")

26 changes: 11 additions & 15 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation6.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@


/proc/RunTest()
var/text = "["1"]\s"
ASSERT(text == "1s")
text = "[0]\s"
ASSERT(text == "0s")
text = "[null]\s"
ASSERT(text == "s")
text = "[1]\s"
ASSERT(text == "1")
text = "[1.00000001]\s"
ASSERT(text == "1")
text = "[1.0001]\s"
ASSERT(text == "1.0001s")
/proc/RunTest()
ASSERT("\roman[1.5]" == "i")
ASSERT("\roman [1.5]" == " i")
ASSERT("\Roman[1.5]" == "I")
ASSERT("\Roman [1.5]" == " I")
ASSERT("\roman shitposts [1]" == " shitposts i")
ASSERT("\roman shitposts [1] \the [2] [3]\s" == " shitposts i 3s")
ASSERT("\roman[1.#INF]" == "")
ASSERT("\roman[-1.#INF]" == "-∞")
ASSERT("\roman [-1.#INF]" == " -∞")
ASSERT("\roman[1.#IND]" == "")
61 changes: 35 additions & 26 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation7.dm
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
/datum/thing
var/name = "thing"

/datum/Thing
var/name = "Thing"

/datum/proper_thing
var/name = "\proper thing"

/datum/plural_things
var/name = "things"
var/gender = PLURAL

/proc/RunTest()
var/text = "[0]\th"
ASSERT(text == "0th")
text = "[1]\th"
ASSERT(text == "1st")
text = "[2]\th"
ASSERT(text == "2nd")
text = "[3]\th"
ASSERT(text == "3rd")
text = "[4]\th"
ASSERT(text == "4th")
text = "[-1]\th"
ASSERT(text == "-1th")
text = "[4.52]\th"
ASSERT(text == "4th")
text = "the fitness [1.7]\th is a"
ASSERT(text == "the fitness 1st is a")
text = "the fitness [99999999]\th is a"
ASSERT(text == "the fitness 100000000th is a")
text = "[null]\th"
ASSERT(text == "0th")
var/datum/D = new
text = "[D]\th"
ASSERT(text == "0th")
var/foo = "bar"
text = "[foo]\th"
ASSERT(text == "0th")
// Lowercase \a on datums
ASSERT("\a [new /datum/thing]" == "a thing")
ASSERT("\a [new /datum/Thing]" == "Thing")
ASSERT("\a [new /datum/proper_thing]" == "thing")
ASSERT("\a [new /datum/plural_things]" == "some things")

// Uppercase \A on datums
ASSERT("\A [new /datum/thing]" == "A thing")
ASSERT("\A [new /datum/Thing]" == "Thing")
ASSERT("\A [new /datum/proper_thing]" == "thing")
ASSERT("\A [new /datum/plural_things]" == "Some things")

// Lowercase \a on strings
ASSERT("\a ["thing"]" == "a thing")
ASSERT("\a ["Thing"]" == "Thing")
ASSERT("\a ["\proper thing"]" == "thing")

// Uppercase \A on strings
ASSERT("\A ["thing"]" == "A thing")
ASSERT("\A ["Thing"]" == "Thing")
ASSERT("\A ["\proper thing"]" == "thing")

// Invalid \a
ASSERT("\a [123]" == "")
ASSERT("\A [123]" == "")
11 changes: 0 additions & 11 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation8.dm

This file was deleted.

39 changes: 0 additions & 39 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation9.dm

This file was deleted.

1 change: 1 addition & 0 deletions OpenDream.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AABB/@EntryIndexedValue">AABB</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RT/@EntryIndexedValue">RT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DM/@EntryIndexedValue">DM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DMF/@EntryIndexedValue">DMF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DMI/@EntryIndexedValue">DMI</s:String>
Expand Down
21 changes: 10 additions & 11 deletions OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,9 @@ public DreamValue GetAppearanceVar(ImmutableAppearance appearance, string varNam
/// <param name="atom">The atom to find the appearance of.</param>
public ImmutableAppearance MustGetAppearance(DreamObject atom) {
return atom switch {
DreamObjectArea area => area.Appearance,
DreamObjectTurf turf => turf.Appearance,
DreamObjectMovable movable => movable.SpriteComponent.Appearance!,
DreamObjectArea area => area.Appearance,
DreamObjectImage image => image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerAppearance: false) : image.SpriteComponent!.Appearance!,
_ => throw new Exception($"Cannot get appearance of {atom}")
};
Expand All @@ -572,16 +572,15 @@ public ImmutableAppearance MustGetAppearance(DreamObject atom) {
/// Optionally looks up for an appearance. Does not try to create a new one when one is not found for this atom.
/// </summary>
public bool TryGetAppearance(DreamObject atom, [NotNullWhen(true)] out ImmutableAppearance? appearance) {
if (atom is DreamObjectTurf turf)
appearance = turf.Appearance;
else if (atom is DreamObjectMovable { SpriteComponent.Appearance: not null } movable)
appearance = movable.SpriteComponent.Appearance;
else if (atom is DreamObjectImage image)
appearance = image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerAppearance: false) : image.SpriteComponent?.Appearance;
else if (atom is DreamObjectArea area)
appearance = area.Appearance;
else
appearance = null;
appearance = atom switch {
DreamObjectArea area => area.Appearance,
DreamObjectTurf turf => turf.Appearance,
DreamObjectMovable { SpriteComponent.Appearance: { } movableAppearance } => movableAppearance,
DreamObjectImage image => image.IsMutableAppearance
? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerAppearance: false)
: image.SpriteComponent?.Appearance,
_ => null
};

return appearance is not null;
}
Expand Down
Loading

0 comments on commit f20cd7c

Please sign in to comment.