Commit ba658047

ba65804740deMerged

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

Description

test: bundle 8 def-bearing standalone tests into bundle_misc_c_37

Fold kw_nil_default_string_call, optional_string_param_method, poly_box_int_array, poly_or_returns_value, each_with_object_seed_ shadow, fetch_nil_default_int_lv, no_keywords_param, sym_case into a single bundle. Each test's top-level method gets a per-test name prefix (show -> t_kw_show, parse -> t_osp_parse, etc.) so they don't collide across tests; the per-test driver function calls the prefixed name and the bundle invokes the driver.

Tests: default 441/0/0 (was 448, -8 standalone + the bundle).

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
ba65804740de
Parent
8b20804e40ef

test/bundle_misc_c_37.rbaddedView file

1+# Bundled tests:
2+# - kw_nil_default_string_call (show -> t_kw_show)
3+# - optional_string_param_method (parse -> t_osp_parse)
4+# - poly_box_int_array (kind_of -> t_pbia_kind_of)
5+# - poly_or_returns_value (pick / pick_int -> t_porv_*)
6+# - each_with_object_seed_shadow (f -> t_ewoss_f)
7+# - fetch_nil_default_int_lv (f -> t_fndi_f)
8+# - no_keywords_param (add -> t_nkp_add)
9+# - sym_case (classify -> t_sc_classify)
10+#
11+# Each inner top-level def is renamed with a per-test prefix to
12+# avoid cross-test collisions when the bundle is compiled.
13+
14+# === kw_nil_default_string_call ===
15+def t_kw_show(x: nil)
16+ puts x
17+end
18+
19+def t_kw_nil_default_string_call
20+ t_kw_show(x: "hi")
21+ t_kw_show(x: nil)
22+end
23+t_kw_nil_default_string_call
24+
25+# === optional_string_param_method ===
26+def t_osp_parse(source, file_path = nil)
27+ if file_path
28+ puts file_path.length
29+ else
30+ puts source.length
31+ end
32+end
33+
34+def t_optional_string_param_method
35+ t_osp_parse("abc", "name.rb")
36+ t_osp_parse("abc")
37+ t_osp_parse("longer", "another_name.rb")
38+end
39+t_optional_string_param_method
40+
41+# === poly_box_int_array ===
42+def t_pbia_kind_of(a)
43+ a.nil? ? "nil" : "something"
44+end
45+
46+def t_poly_box_int_array
47+ puts t_pbia_kind_of(Object.new)
48+ puts t_pbia_kind_of([1, 2, 3])
49+end
50+t_poly_box_int_array
51+
52+# === poly_or_returns_value ===
53+def t_porv_pick(a, b)
54+ a || b
55+end
56+
57+def t_porv_pick_int(a, b)
58+ a || b
59+end
60+
61+def t_poly_or_returns_value
62+ puts t_porv_pick(nil, "fallback")
63+ puts t_porv_pick("actual", "fallback")
64+ puts t_porv_pick_int(0, 5)
65+ puts(nil || "direct")
66+end
67+t_poly_or_returns_value
68+
69+# === each_with_object_seed_shadow ===
70+def t_ewoss_f
71+ obj = 42
72+ out = [1, 2, 3].each_with_object([]) { |x, obj| obj.push(x * 2) }
73+ puts out[0] # 2
74+ puts out[1] # 4
75+ puts out[2] # 6
76+ puts obj # 42
77+end
78+t_ewoss_f
79+
80+# === fetch_nil_default_int_lv ===
81+def t_fndi_f(opts = {})
82+ v = opts.fetch(:k, nil)
83+ v.nil? ? "missing" : "found"
84+end
85+
86+def t_fetch_nil_default_int_lv
87+ puts t_fndi_f
88+end
89+t_fetch_nil_default_int_lv
90+
91+# === no_keywords_param ===
92+def t_nkp_add(a, b, **nil)
93+ a + b
94+end
95+
96+def t_no_keywords_param
97+ puts t_nkp_add(1, 2)
98+ puts t_nkp_add(10, 20)
99+end
100+t_no_keywords_param
101+
102+# === sym_case ===
103+def t_sc_classify(sym)
104+ case sym
105+ when :red then "warm"
106+ when :orange then "warm"
107+ when :blue then "cool"
108+ when :green then "cool"
109+ else "unknown"
110+ end
111+end
112+
113+def t_sym_case
114+ puts t_sc_classify(:red)
115+ puts t_sc_classify(:orange)
116+ puts t_sc_classify(:blue)
117+ puts t_sc_classify(:purple)
118+end
119+t_sym_case