Commit ab028d86

ab028d866ed6Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 10 files · +2 added · -8 deleted

Description

test: collapse 4 global_var_* tests into one global_var.rb

Compound writes on globals — Or / And / Operator / Target. Four parallel tests; merged. Global names that overlapped in the originals ($count was reused for both And-write and Or-write with different semantics in each file) are renamed to distinct per-section names so the merged script's accumulated state doesn't perturb later sections.

4 .rb → 1. ~5s saved on Windows test step at the ~1.2s/test rate.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
ab028d866ed6
Parent
93a5db6f3426

test/global_var.rbaddedView file

1+# Global variable compound writes — Or / And / Operator / Target.
2+# Was four tests; merged here. Globals across the original files
3+# happened to reuse `$count`, so this file picks distinct names per
4+# section so the merged script's accumulated state doesn't change
5+# the per-section semantics.
6+
7+# === Operator-write ($x += / -= / *= / /= ... ) ===
8+# Mirror of LocalVariableOperatorWriteNode but the storage is a
9+# C-level global symbol via sanitize_gvar(name).
10+$counter = 0
11+$counter += 1
12+$counter += 5
13+puts $counter # 6
14+$counter -= 2
15+puts $counter # 4
16+$counter *= 3
17+puts $counter # 12
18+$counter /= 4
19+puts $counter # 3
20+
21+# === Or-write ($x ||= val) ===
22+# Mirror of LocalVariableOrWriteNode. Only assigns if the global
23+# is currently falsy.
24+#
25+# Note: Spinel uses C-truthy semantics (any zero is falsy), which
26+# diverges from CRuby (only nil/false are falsy). For unassigned
27+# globals (default 0/nil) the two agree on the first assignment;
28+# subsequent ||= against truthy non-zero ints also agree. This
29+# test exercises only the agreement region.
30+$or_count ||= 5 # never assigned, fires
31+puts $or_count # 5
32+$or_count ||= 99 # already 5 (truthy in both), doesn't fire
33+puts $or_count # 5
34+
35+# === And-write ($x &&= val) ===
36+# Mirror of LocalVariableAndWriteNode. Only assigns if the global
37+# is currently truthy.
38+$and_count = 5
39+$and_count &&= 10 # 5 is truthy, fires
40+puts $and_count # 10
41+$and_count &&= 0 # 10 is truthy in C, fires
42+puts $and_count # 0
43+
44+# === Target (multi-assign LHS for globals) ===
45+# `$a, $b = 1, 2` -- each LHS slot is a GlobalVariableTargetNode.
46+# Routes through MultiWriteNode's emit_multi_write_target to the
47+# same g_<name> C-level storage GlobalVariableWriteNode uses.
48+$ga, $gb = 1, 2
49+puts $ga # 1
50+puts $gb # 2
51+$ga, $gb = $gb, $ga # swap
52+puts $ga # 2
53+puts $gb # 1