From 9f373d49acc122137024e98043d0a9961836e66a Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Sun, 17 Aug 2025 13:52:58 -0400 Subject: [PATCH] Add more tests for edge-case macro and interpolation expansion behavior Fixes #1803 --- test/asm/blue-paint-limits.asm | 43 ++++++++++++++++++++++++++++++ test/asm/blue-paint-limits.err | 3 +++ test/asm/blue-paint-limits.out | 8 ++++++ test/asm/delayed-interpolation.asm | 32 ++++++++++++++++++++++ test/asm/delayed-interpolation.out | 9 +++++++ 5 files changed, 95 insertions(+) create mode 100644 test/asm/blue-paint-limits.asm create mode 100644 test/asm/blue-paint-limits.err create mode 100644 test/asm/blue-paint-limits.out create mode 100644 test/asm/delayed-interpolation.asm create mode 100644 test/asm/delayed-interpolation.out diff --git a/test/asm/blue-paint-limits.asm b/test/asm/blue-paint-limits.asm new file mode 100644 index 00000000..00d1167f --- /dev/null +++ b/test/asm/blue-paint-limits.asm @@ -0,0 +1,43 @@ +macro outer_interp + def s equs "macro inner_interp\1\nprintln \"interp: \1 and \\1\"\nendm" + {s} + purge s +endm +; this prints "1 and red" and "2 and blue"... +outer_interp 1 +inner_interp1 red +outer_interp 2 +inner_interp2 blue + +macro do + \# +endm +macro outer_mac + do macro inner_mac\1\nprintln "mac: \1 and \\1"\nendm +endm +; ...but this prints "1 and \1" and "2 and \1" +outer_mac 1 +inner_mac1 red +outer_mac 2 +inner_mac2 blue + +macro outer_concat + do macro inner_concat\1\nprintln "concat: \1 and "++\\1\nendm +endm +; this does print "1 and red" and "2 and blue" though +outer_concat 1 +inner_concat1 "red" +outer_concat 2 +inner_concat2 "blue" + +macro simple + println "(\1)" +endm +; this prints """("\\1")""", not """("\1")""" +simple "\\1" + +macro nth + println \1 +endm +; this does not print "lol", it's an error +nth \\2, lol diff --git a/test/asm/blue-paint-limits.err b/test/asm/blue-paint-limits.err new file mode 100644 index 00000000..a8672803 --- /dev/null +++ b/test/asm/blue-paint-limits.err @@ -0,0 +1,3 @@ +error: Invalid character '2' after line continuation + at blue-paint-limits.asm::nth(40) <- blue-paint-limits.asm(43) +Assembly aborted with 1 error! diff --git a/test/asm/blue-paint-limits.out b/test/asm/blue-paint-limits.out new file mode 100644 index 00000000..2c55cf40 --- /dev/null +++ b/test/asm/blue-paint-limits.out @@ -0,0 +1,8 @@ +interp: 1 and red +interp: 2 and blue +mac: 1 and \1 +mac: 2 and \1 +concat: 1 and red +concat: 2 and blue +("\\1") +$2 diff --git a/test/asm/delayed-interpolation.asm b/test/asm/delayed-interpolation.asm new file mode 100644 index 00000000..8b60b685 --- /dev/null +++ b/test/asm/delayed-interpolation.asm @@ -0,0 +1,32 @@ +DEF SLIME_HP EQU 35 +DEF SLIME_ATK EQU 15 +DEF SLIME_DEF EQU 26 +DEF MIMIC_HP EQU 20 +DEF MIMIC_ATK EQU 21 +DEF MIMIC_DEF EQU 28 + +MACRO with_each + for i, 1, _NARG + REDEF temp EQUS STRRPL(\<_NARG>, "?", "\") + {temp} + endr +ENDM + +DEF with_each_stat EQUS "with_each HP, ATK, DEF," + +with_each_stat """ + println STRFMT("Average ? is %d", (SLIME_? + MIMIC_?) / 2) +""" + +MACRO buff_monster + REDEF monster EQUS STRUPR(STRSLICE("\1", 0, 1)) ++ STRLWR(STRSLICE("\1", 1)) + ; delayed \{interpolation\} is necessary here + ; escaping the '}' is not essential (same as '>' in HTML) + with_each_stat """ + DEF buffed = \1_? * 120 / 100 + println "{monster}'s ? went from \{d:\1_?\} to \{d:buffed}!" + """ +ENDM + +buff_monster MIMIC +buff_monster SLIME diff --git a/test/asm/delayed-interpolation.out b/test/asm/delayed-interpolation.out new file mode 100644 index 00000000..987ed0af --- /dev/null +++ b/test/asm/delayed-interpolation.out @@ -0,0 +1,9 @@ +Average HP is 27 +Average ATK is 18 +Average DEF is 27 +Mimic's HP went from 20 to 24! +Mimic's ATK went from 21 to 25! +Mimic's DEF went from 28 to 33! +Slime's HP went from 35 to 42! +Slime's ATK went from 15 to 18! +Slime's DEF went from 26 to 31!