Commit 57409b7d

57409b7d3815Merged

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

Description

test: collapse 4 index_* tests into one index_write.rb

Indexed-slot compound writes (a[i] OP= v, a[i] &&= v, a[i] ||= v, a[i], b[j] = ...). Four parallel tests; merged. The op_assign section's class Vec is unique. Locals reused across the originals (xs, counts, etc.) get per-section prefixes (xs_aw / xs_t, counts_op / counts_aw / counts_or / counts_t) so spinel's local-type inference doesn't unify them and so the merged script's accumulated state doesn't carry hash content across 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
57409b7d3815
Parent
ab028d866ed6

test/index_and_write.rbdeleted

1-# IndexAndWriteNode -- `a[i] &&= val`.
2-#
3-# Reads `a[i]`; if truthy, sets a[i] = val. Mirror of IndexOrWriteNode
4-# with condition inverted. Same temp pattern keeps receiver and
5-# index evaluated exactly once.
6-
7-# Int array with non-zero slots: avoid the C-truthy vs Ruby-truthy
8-# divergence by sticking to non-zero values that are truthy in both.
9-xs = [1, 2, 3, 4, 5]
10-xs[0] &&= 10 # truthy -> fires
11-xs[2] &&= 30 # truthy -> fires
12-xs[4] &&= xs[4] * 100 # truthy -> fires; receiver/index evaluated once
13-
14-puts xs[0] # 10
15-puts xs[1] # 2 (untouched)
16-puts xs[2] # 30
17-puts xs[3] # 4 (untouched)
18-puts xs[4] # 500
19-
20-# Hash with int values: each set value is non-zero, so &&= behaves
21-# the same in C and Ruby for these slots.
22-counts = {"alice" => 30, "bob" => 25}
23-counts["alice"] &&= 31 # truthy -> fires
24-counts["carol"] &&= 50 # never-set (sp_StrIntHash_get returns 0) -> doesn't fire
25-puts counts["alice"] # 31
26-puts counts["bob"] # 25 (untouched)
27-puts counts.length # 2 (carol not added)