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. Usehi/hsto 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 paramino longer collides with ai = "test"later in the file — spinel unified them to poly across the script and the C compile rejectedslot = 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
# Test lrama-required features# lrama-required features. Combines what was previously split across# lrama_features.rb / _2.rb / _3.rb (the sections were "part 1/2/3"# of the same coverage matrix).# === Part 1 ===# private (should be ignored)class Foo# bare case (case without expression)x = 5result = case when x > 10 then "big" when x > 3 then "medium" else "small" endputs resultresult_x = case when x > 10 then "big" when x > 3 then "medium" else "small" endputs result_x# Array.new(n, val)arr = Array.new(5, 42)puts arr.length # 5puts arr[0] # 42puts arr[4] # 42arr_new = Array.new(5, 42)puts arr_new.length # 5puts arr_new[0] # 42puts arr_new[4] # 42# Array#compact (no-op for IntArray)a2 = [1, 2, 3]puts Float::INFINITY > 999999 # trueputs "done"# === Part 2 ===# A9: Hash#merge (sp_StrIntHash)mrg1 = {"a" => 1, "b" => 2}mrg2 = {"b" => 3, "c" => 4}mrg3 = mrg1.merge(mrg2)puts mrg3["a"] # 1puts mrg3["b"] # 3 (mrg2 overrides mrg1)puts mrg3["c"] # 4# A19: Array#duparr_dup = [10, 20, 30]arr_dup2 = arr_dup.dupputs arr_dup2[0] # 10puts arr_dup2.length # 3# A19: String#dup (const string)sd1 = "hello"sd2 = sd1.dupputs sd2 # hello# A20: Hash.new(0) with default valuecounter = Hash.new(0)counter["x"] = counter["x"] + 1counter["x"] = counter["x"] + 1counter["y"] = counter["y"] + 1puts counter["x"] # 2puts counter["y"] # 1puts counter["z"] # 0 (default)# B2: attr_writerclass Writer attr_reader :name attr_writer :name def initialize(n) @name = n endendw = Writer.new("before")puts w.name # beforew.name = "after"puts w.name # after# B3: Comparable (include Comparable + def <=>)class Weight include Comparable attr_reader :grams def initialize(g) @grams = g end def <=>(other) @grams - other.grams endendw1 = Weight.new(100)w2 = Weight.new(200)w3 = Weight.new(100)puts w1 < w2 # trueputs w2 > w1 # trueputs w1 == w3 # trueputs w1 > w2 # falseputs w1 <= w3 # trueputs w2 >= w1 # trueputs "done"# === Part 3 ===# A10: Hash#transform_values (sp_StrIntHash)tv = {"a" => 1, "b" => 2, "c" => 3}tv2 = tv.transform_values { |v| v * 10 }puts tv2["a"] # 10puts tv2["b"] # 20puts tv2["c"] # 30puts tv["a"] # 1 (original unchanged)# A18: Array#zipza = [1, 2, 3]zb = [4, 5, 6]zipped = za.zip(zb)puts zipped.length # 3# Zip with different lengthszc = [10, 20]zipped2 = za.zip(zc)puts zipped2.length # 3puts "done"test/lrama_features.rb.expectedmodifiedView file
Loading diff…
test/lrama_features2.rbdeleted
Loading diff…
test/lrama_features2.rb.expecteddeleted
Loading diff…
test/lrama_features3.rbdeleted
Loading diff…
test/lrama_features3.rb.expecteddeleted
Loading diff…
test/mutable_str.rbmodifiedView file
Loading diff…
test/mutable_str.rb.expectedmodifiedView file
Loading diff…
test/mutable_str2.rbdeleted
Loading diff…
test/mutable_str2.rb.expecteddeleted
Loading diff…
test/mutable_str3.rbdeleted
Loading diff…
test/mutable_str3.rb.expecteddeleted
Loading diff…
test/sym_hash.rbmodifiedView file
Loading diff…
test/sym_hash.rb.expectedmodifiedView file
Loading diff…
test/sym_str_hash.rbdeleted
Loading diff…
test/sym_str_hash.rb.expecteddeleted
Loading diff…