macro(if normalize): add print-if normalization golden and runner
This commit is contained in:
2
apps/tests/macro_golden_if_print.nyash
Normal file
2
apps/tests/macro_golden_if_print.nyash
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
print(if (1 < 2) { 10 } else { 20 })
|
||||||
|
|
||||||
8
tools/test/golden/macro/if_print.expanded.json
Normal file
8
tools/test/golden/macro/if_print.expanded.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{"kind":"Program","statements":[
|
||||||
|
{"kind":"If","condition":{"kind":"BinaryOp","op":"<","left":{"kind":"Literal","value":{"type":"int","value":1}},"right":{"kind":"Literal","value":{"type":"int","value":2}}},"then":[
|
||||||
|
{"kind":"Print","expression":{"kind":"Literal","value":{"type":"int","value":10}}}
|
||||||
|
],"else":[
|
||||||
|
{"kind":"Print","expression":{"kind":"Literal","value":{"type":"int","value":20}}}
|
||||||
|
]}
|
||||||
|
]}
|
||||||
|
|
||||||
32
tools/test/golden/macro/if_print_user_macro_golden.sh
Normal file
32
tools/test/golden/macro/if_print_user_macro_golden.sh
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
|
||||||
|
bin="$root/target/release/nyash"
|
||||||
|
src="apps/tests/macro_golden_if_print.nyash"
|
||||||
|
golden="$root/tools/test/golden/macro/if_print.expanded.json"
|
||||||
|
|
||||||
|
if [ ! -x "$bin" ]; then
|
||||||
|
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
export NYASH_MACRO_ENABLE=1
|
||||||
|
export NYASH_MACRO_PATHS="apps/macros/examples/if_match_normalize_macro.nyash"
|
||||||
|
|
||||||
|
normalize_json() {
|
||||||
|
python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",",":")))'
|
||||||
|
}
|
||||||
|
|
||||||
|
out_raw=$("$bin" --dump-expanded-ast-json "$src")
|
||||||
|
out_norm=$(printf '%s' "$out_raw" | normalize_json)
|
||||||
|
gold_norm=$(normalize_json < "$golden")
|
||||||
|
|
||||||
|
if [ "$out_norm" != "$gold_norm" ]; then
|
||||||
|
echo "Golden mismatch (if-print normalization)" >&2
|
||||||
|
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[OK] golden if-print normalization matched"
|
||||||
|
|
||||||
Reference in New Issue
Block a user