mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Add more tests for edge-case macro and interpolation expansion behavior
Fixes #1803
This commit is contained in:
43
test/asm/blue-paint-limits.asm
Normal file
43
test/asm/blue-paint-limits.asm
Normal file
@@ -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
|
||||
3
test/asm/blue-paint-limits.err
Normal file
3
test/asm/blue-paint-limits.err
Normal file
@@ -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!
|
||||
8
test/asm/blue-paint-limits.out
Normal file
8
test/asm/blue-paint-limits.out
Normal file
@@ -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
|
||||
32
test/asm/delayed-interpolation.asm
Normal file
32
test/asm/delayed-interpolation.asm
Normal file
@@ -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>, "?", "\<i>")
|
||||
{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
|
||||
9
test/asm/delayed-interpolation.out
Normal file
9
test/asm/delayed-interpolation.out
Normal file
@@ -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!
|
||||
Reference in New Issue
Block a user