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 files3+
# happened to reuse `$count`, so this file picks distinct names per4+
# section so the merged script's accumulated state doesn't change5+
# the per-section semantics.6+
7+
# === Operator-write ($x += / -= / *= / /= ... ) ===8+
# Mirror of LocalVariableOperatorWriteNode but the storage is a9+
# C-level global symbol via sanitize_gvar(name).10+
$counter = 011+
$counter += 112+
$counter += 513+
puts $counter # 614+
$counter -= 215+
puts $counter # 416+
$counter *= 317+
puts $counter # 1218+
$counter /= 419+
puts $counter # 320+
21+
# === Or-write ($x ||= val) ===22+
# Mirror of LocalVariableOrWriteNode. Only assigns if the global23+
# is currently falsy.24+
#25+
# Note: Spinel uses C-truthy semantics (any zero is falsy), which26+
# diverges from CRuby (only nil/false are falsy). For unassigned27+
# globals (default 0/nil) the two agree on the first assignment;28+
# subsequent ||= against truthy non-zero ints also agree. This29+
# test exercises only the agreement region.30+
$or_count ||= 5 # never assigned, fires31+
puts $or_count # 532+
$or_count ||= 99 # already 5 (truthy in both), doesn't fire33+
puts $or_count # 534+
35+
# === And-write ($x &&= val) ===36+
# Mirror of LocalVariableAndWriteNode. Only assigns if the global37+
# is currently truthy.38+
$and_count = 539+
$and_count &&= 10 # 5 is truthy, fires40+
puts $and_count # 1041+
$and_count &&= 0 # 10 is truthy in C, fires42+
puts $and_count # 043+
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 the47+
# same g_<name> C-level storage GlobalVariableWriteNode uses.48+
$ga, $gb = 1, 249+
puts $ga # 150+
puts $gb # 251+
$ga, $gb = $gb, $ga # swap52+
puts $ga # 253+
puts $gb # 1test/global_var.rb.expectedaddedView file
Loading diff…
test/global_var_and_write.rbdeleted
Loading diff…
test/global_var_and_write.rb.expecteddeleted
Loading diff…
test/global_var_op_write.rbdeleted
Loading diff…
test/global_var_op_write.rb.expecteddeleted
Loading diff…
test/global_var_or_write.rbdeleted
Loading diff…
test/global_var_or_write.rb.expecteddeleted
Loading diff…
test/global_var_target.rbdeleted
Loading diff…
test/global_var_target.rb.expecteddeleted
Loading diff…