Commit 0def5fc1

0def5fc1ff38Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 16 files · ~6 modified · -10 deleted

Description

test: collapse sym_hash, mutable_str, lrama_features groups

Three more natural merges (5 .rb files removed, 3 kept and grown):

  • sym_hash + sym_str_hash: same operator surface ([], length, has_key?, []=) on int-valued vs string-valued sym hashes. Use hi / hs to keep per-type locals distinct.

  • mutable_str{,2,3}: numbered split was just three batches of the same coverage — << mutation, replace/clear, [], gsub/sub/split, +, to_s, downcase/strip/.../start_with?/.../empty?/include?, to_i, ljust/rjust. Renamed locals across sections (block param i no longer collides with a i = "test" later in the file — spinel unified them to poly across the script and the C compile rejected slot = mrb_int).

  • lrama_features{,2,3}: explicit "part 1/2/3" of the same lrama feature matrix. Class names already distinct (Foo / Writer / Weight). Local names disambiguated where they would have collided (arr → arr_new / arr_dup; h → mrg / tv).

Net: 8 .rb → 3. Continuing the per-test cc -c amortization at ~1.2s/test on Windows (~6s saved this commit).

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

Details

Commit
0def5fc1ff38
Parent
e0f7bac7c300

test/lrama_features.rbmodifiedView file

@@ -1,4 +1,8 @@
1-# Test lrama-required features
1+# lrama-required features. Combines what was previously split across
2+# lrama_features.rb / _2.rb / _3.rb (the sections were "part 1/2/3"
3+# of the same coverage matrix).
4+
5+# === Part 1 ===
26
37 # private (should be ignored)
48 class Foo
@@ -11,18 +15,18 @@
1115
1216 # bare case (case without expression)
1317 x = 5
14-result = case
15- when x > 10 then "big"
16- when x > 3 then "medium"
17- else "small"
18- end
19-puts result
18+result_x = case
19+ when x > 10 then "big"
20+ when x > 3 then "medium"
21+ else "small"
22+ end
23+puts result_x
2024
2125 # Array.new(n, val)
22-arr = Array.new(5, 42)
23-puts arr.length # 5
24-puts arr[0] # 42
25-puts arr[4] # 42
26+arr_new = Array.new(5, 42)
27+puts arr_new.length # 5
28+puts arr_new[0] # 42
29+puts arr_new[4] # 42
2630
2731 # Array#compact (no-op for IntArray)
2832 a2 = [1, 2, 3]
@@ -47,3 +51,92 @@
4751 puts Float::INFINITY > 999999 # true
4852
4953 puts "done"
54+
55+# === Part 2 ===
56+
57+# A9: Hash#merge (sp_StrIntHash)
58+mrg1 = {"a" => 1, "b" => 2}
59+mrg2 = {"b" => 3, "c" => 4}
60+mrg3 = mrg1.merge(mrg2)
61+puts mrg3["a"] # 1
62+puts mrg3["b"] # 3 (mrg2 overrides mrg1)
63+puts mrg3["c"] # 4
64+
65+# A19: Array#dup
66+arr_dup = [10, 20, 30]
67+arr_dup2 = arr_dup.dup
68+puts arr_dup2[0] # 10
69+puts arr_dup2.length # 3
70+
71+# A19: String#dup (const string)
72+sd1 = "hello"
73+sd2 = sd1.dup
74+puts sd2 # hello
75+
76+# A20: Hash.new(0) with default value
77+counter = Hash.new(0)
78+counter["x"] = counter["x"] + 1
79+counter["x"] = counter["x"] + 1
80+counter["y"] = counter["y"] + 1
81+puts counter["x"] # 2
82+puts counter["y"] # 1
83+puts counter["z"] # 0 (default)
84+
85+# B2: attr_writer
86+class Writer
87+ attr_reader :name
88+ attr_writer :name
89+ def initialize(n)
90+ @name = n
91+ end
92+end
93+w = Writer.new("before")
94+puts w.name # before
95+w.name = "after"
96+puts w.name # after
97+
98+# B3: Comparable (include Comparable + def <=>)
99+class Weight
100+ include Comparable
101+ attr_reader :grams
102+ def initialize(g)
103+ @grams = g
104+ end
105+ def <=>(other)
106+ @grams - other.grams
107+ end
108+end
109+w1 = Weight.new(100)
110+w2 = Weight.new(200)
111+w3 = Weight.new(100)
112+puts w1 < w2 # true
113+puts w2 > w1 # true
114+puts w1 == w3 # true
115+puts w1 > w2 # false
116+puts w1 <= w3 # true
117+puts w2 >= w1 # true
118+
119+puts "done"
120+
121+# === Part 3 ===
122+
123+# A10: Hash#transform_values (sp_StrIntHash)
124+tv = {"a" => 1, "b" => 2, "c" => 3}
125+tv2 = tv.transform_values { |v| v * 10 }
126+puts tv2["a"] # 10
127+puts tv2["b"] # 20
128+puts tv2["c"] # 30
129+puts tv["a"] # 1 (original unchanged)
130+
131+# A18: Array#zip
132+za = [1, 2, 3]
133+zb = [4, 5, 6]
134+zipped = za.zip(zb)
135+puts zipped.length # 3
136+
137+# Zip with different lengths
138+zc = [10, 20]
139+zipped2 = za.zip(zc)
140+puts zipped2.length # 3
141+
142+puts "done"