Commit eebfc9c2

eebfc9c2c66eMerged

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

Description

test: collapse 5 constant_path_* tests into one constant_path.rb

Five separate tests each covering a slice of ConstantPath access. Merge into one file. The class-method section's A::B (a class) collided with the nested-read section's A::B::C (where A::B is a module) so the class-method classes are renamed CmA::CmB. The top-level class C from constant_path_new collided with M::C from constant_path_nested_read so the standalone one is renamed TopC.

5 .rb → 1. ~6s saved on Windows test step at the ~1.2s/test rate.

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

Details

Commit
eebfc9c2c66e
Parent
212e85d1645e

test/constant_path.rbaddedView file

1+# ConstantPath access — covers ARGV (top-level builtin), built-in
2+# constructors (::Array.new etc.), nested const reads (A::B::C),
3+# class-method dispatch (A::B.create), and the relative-vs-root
4+# scope distinction (RootNS::Mid::LEAF vs ::RootNS::Mid::LEAF).
5+# Merged from constant_path_{argv,builtin_new,class_method,
6+# nested_read,new}.rb. The class-method section's `A::B` (a class)
7+# would collide with the nested-read section's `A::B::C` (where
8+# A::B is a module), so the class-method section is namespaced as
9+# CmA::CmB to keep both shapes co-resident.
10+
11+# ---- ARGV access via ConstantPath ----
12+# Runs at top-level scope so sp_argv is in scope (sp_argv is only
13+# declared in main()).
14+puts ARGV.length
15+puts ::ARGV.length
16+puts(ARGV[0] == nil)
17+puts(::ARGV[0] == nil)
18+
19+# ---- Built-in constructors via absolute ConstantPath ----
20+require "stringio"
21+
22+bia = ::Array.new(3, 2)
23+puts bia[0] + bia[2]
24+
25+bih = ::Hash.new
26+bih["k"] = bia[1]
27+puts bih["k"]
28+
29+bip = ::Proc.new { |x| x + 1 }
30+puts bip.call(5)
31+
32+bis = ::StringIO.new("ab")
33+puts bis.getc
34+
35+bif = ::Fiber.new { |x|
36+ ::Fiber.yield(x + 1)
37+ x + 2
38+}
39+puts bif.resume(4)
40+puts bif.resume(4)
41+
42+bicur = ::Fiber.current
43+puts bicur.alive?
44+
45+# ---- ConstantPath class-method dispatch (A::B.create) ----
46+module CmA
47+ class CmB
48+ def self.create(x)
49+ x + 1
50+ end
51+ end
52+end
53+puts CmA::CmB.create(41)
54+puts ::CmA::CmB.create(99)
55+
56+# ---- Nested ConstantPath reads (A::B::C, M::C::X) ----
57+module A
58+ module B
59+ C = 7
60+ end
61+end
62+module M
63+ class C
64+ X = 11
65+ end
66+end
67+puts A::B::C
68+puts ::A::B::C
69+puts M::C::X
70+puts ::M::C::X
71+
72+# Relative path prefers lexical scope; `::` forces root scope.
73+module RootNS
74+ module Mid
75+ LEAF = 31
76+ end
77+end
78+module Lex
79+ module RootNS
80+ module Mid
81+ LEAF = 47
82+ end
83+ end
84+ def self.pick_relative
85+ RootNS::Mid::LEAF
86+ end
87+ def self.pick_root
88+ ::RootNS::Mid::LEAF
89+ end
90+end
91+puts Lex.pick_relative
92+puts Lex.pick_root
93+
94+# ---- Top-level constructor via absolute ConstantPath (::TopC.new) ----
95+# Renamed from `class C` to TopC to keep it distinct from M::C above.
96+class TopC
97+ def initialize
98+ puts "init"
99+ end
100+end
101+puts "start"
102+::TopC.new