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
# ConstantPath access — covers ARGV (top-level builtin), built-in# constructors (::Array.new etc.), nested const reads (A::B::C),# class-method dispatch (A::B.create), and the relative-vs-root# scope distinction (RootNS::Mid::LEAF vs ::RootNS::Mid::LEAF).# Merged from constant_path_{argv,builtin_new,class_method,# nested_read,new}.rb. The class-method section's `A::B` (a class)# would collide with the nested-read section's `A::B::C` (where# A::B is a module), so the class-method section is namespaced as# CmA::CmB to keep both shapes co-resident.# ---- ARGV access via ConstantPath ----# Runs at top-level scope so sp_argv is in scope (sp_argv is only# declared in main()).puts ARGV.lengthputs ::ARGV.lengthputs(ARGV[0] == nil)puts(::ARGV[0] == nil)# ---- Built-in constructors via absolute ConstantPath ----require "stringio"bia = ::Array.new(3, 2)puts bia[0] + bia[2]bih = ::Hash.newbih["k"] = bia[1]puts bih["k"]bip = ::Proc.new { |x| x + 1 }puts bip.call(5)bis = ::StringIO.new("ab")puts bis.getcbif = ::Fiber.new { |x| ::Fiber.yield(x + 1) x + 2}puts bif.resume(4)puts bif.resume(4)bicur = ::Fiber.currentputs bicur.alive?# ---- ConstantPath class-method dispatch (A::B.create) ----module CmA class CmB def self.create(x) x + 1 end endendputs CmA::CmB.create(41)puts ::CmA::CmB.create(99)# ---- Nested ConstantPath reads (A::B::C, M::C::X) ----module A module B C = 7 endendmodule M class C X = 11 endendputs A::B::Cputs ::A::B::Cputs M::C::Xputs ::M::C::X# Relative path prefers lexical scope; `::` forces root scope.module RootNS module Mid LEAF = 31 endendmodule Lex module RootNS module Mid LEAF = 47 end end def self.pick_relative RootNS::Mid::LEAF end def self.pick_root ::RootNS::Mid::LEAF endendputs Lex.pick_relativeputs Lex.pick_root# ---- Top-level constructor via absolute ConstantPath (::TopC.new) ----# Renamed from `class C` to TopC to keep it distinct from M::C above.class TopC def initialize puts "init" endendputs "start"::TopC.newtest/constant_path.rb.expectedaddedView file
Loading diff…
test/constant_path_argv.rbdeleted
Loading diff…
test/constant_path_argv.rb.expecteddeleted
Loading diff…
test/constant_path_builtin_new.rbdeleted
Loading diff…
test/constant_path_builtin_new.rb.expecteddeleted
Loading diff…
test/constant_path_class_method.rbdeleted
Loading diff…
test/constant_path_class_method.rb.expecteddeleted
Loading diff…
test/constant_path_nested_read.rbdeleted
Loading diff…
test/constant_path_nested_read.rb.expecteddeleted
Loading diff…
test/constant_path_new.rbdeleted
Loading diff…
test/constant_path_new.rb.expecteddeleted
Loading diff…