Commit 9dcaf5fb

9dcaf5fbd5eaMerged

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

Description

test: collapse 6 regex_* tests into one regex.rb

Issue #61's five stages plus literal-form coverage. Six separate tests; class names didn't collide. The only top-level def (find from local_var) is unique within the file. Local-name collisions (re, re2 reused for different regex literals) get per-section prefixes so spinel's local-type inference can't unify them across the script and widen to poly.

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

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

Details

Commit
9dcaf5fbd5ea
Parent
3a9e73d804ac

test/regex.rbaddedView file

1+# Regex coverage — issue #61's five stages plus literal-form
2+# tests. Was six tests; class names didn't collide and the only
3+# top-level `def` (regex_local_var's `find`) is unique within this
4+# file. Local-name collisions (`re`, `re2` reused across files for
5+# different regex literals) are dodged with per-section prefixes
6+# so spinel's local-type inference doesn't unify them across the
7+# script and widen to poly.
8+
9+# === Stage 1: UTF-8 source byte-length ===
10+# A regex source containing multi-byte UTF-8 chars must reach the
11+# runtime with the correct byte length. This section just verifies
12+# the binary runs past regex init.
13+re_s1a = /[₀₁₂₃₄₅₆₇₈₉]+/
14+re_s1b = /\A→\z/
15+re_s1c = /[αβγ]/
16+puts "ok"
17+
18+# === Stage 2: UTF-8 character class ===
19+puts(("₁" =~ /[₀-₉]/) ? "ok1" : "fail1")
20+puts(("α" =~ /[α-ω]/) ? "ok2" : "fail2")
21+puts(("abc₁def" =~ /[₀₁₂₃₄₅₆₇₈₉]+/) ? "ok3" : "fail3")
22+puts(("a" =~ /[^₀-₉]/) ? "ok4" : "fail4")
23+puts(("₁" =~ /[^₀-₉]/) ? "fail5" : "ok5")
24+puts(("z" =~ /[a-z₀-₉]/) ? "ok6" : "fail6")
25+puts(("₅" =~ /[a-z₀-₉]/) ? "ok7" : "fail7")
26+puts(("₁" =~ /[α-ω]/) ? "fail8" : "ok8")
27+puts(("a" =~ /[α-ω]/) ? "fail9" : "ok9")
28+m_s2 = "abc₁₂₃def" =~ /[₀-₉]+/
29+puts(m_s2 ? "ok10" : "fail10")
30+
31+# === Stage 3: regex via constant ===
32+RX = /[₀₁₂₃₄₅₆₇₈₉ₐₑₒₓₔ]+/
33+puts RX.match?("₁₂")
34+puts RX.match?("abc")
35+if "₁₂" =~ RX
36+ puts "lhs match"
37+else
38+ puts "lhs miss"
39+end
40+if RX =~ "₁₂"
41+ puts "rhs match"
42+else
43+ puts "rhs miss"
44+end
45+m_s3 = RX.match("₁₂")
46+puts m_s3 ? "match ok" : "match fail"
47+
48+# === Stage 4: regex via local variable ===
49+re_lv = /[₀₁₂₃₄₅₆₇₈₉]+/
50+puts re_lv.match?("₁₂")
51+puts re_lv.match?("abc")
52+if "abc₁def" =~ re_lv
53+ puts "lhs match"
54+else
55+ puts "lhs miss"
56+end
57+if re_lv =~ "abc₁def"
58+ puts "rhs match"
59+else
60+ puts "rhs miss"
61+end
62+
63+# Inside a method body — fresh scope, fresh local.
64+def find(s)
65+ rx = /[a-z]+/
66+ rx.match?(s)
67+end
68+puts find("hello")
69+puts find("123")
70+
71+# Multi-write disqualifies dispatch; the fall-through still compiles.
72+re2_lv = /a/
73+re2_lv = "not a regex"
74+puts re2_lv
75+
76+# === Stage 5: UTF-8 quantifier ===
77+puts "abc₁₂def".gsub(/[₀-₉]+/, "N")
78+puts "abc₁₂₃def".gsub(/[₀-₉]+/, "N")
79+puts "₁abc₂₃def₄₅₆".scan(/[₀-₉]+/).length
80+puts "₀₁".match?(/[₀-₉]{2}/) ? "ok2" : "fail2"
81+puts "₀".match?(/[₀-₉]{2}/) ? "fail3" : "ok3"
82+puts "a₁b₂c".scan(/[a-z₀-₉]+/).length
83+puts "₁₂₃".scan(/[₀-₉]/).length
84+puts "αβ".match?(/[α-ω]+/) ? "ok7" : "fail7"
85+
86+# === Multi-line / escape patterns ===
87+re_ml1 = /
88+ bar
89+/x
90+if re_ml1 =~ "barbar"
91+ puts "ok1"
92+else
93+ puts "no1"
94+end
95+
96+re_ml_t = /a\tb/
97+if re_ml_t =~ "a\tb"
98+ puts "ok2"
99+else
100+ puts "no2"
101+end
102+
103+re_ml_n = /a\nb/
104+if re_ml_n =~ "a\nb"
105+ puts "ok3"
106+else
107+ puts "no3"
108+end
109+
110+re_ml_r = /a\rb/
111+if re_ml_r =~ "a\rb"
112+ puts "ok4"
113+else
114+ puts "no4"
115+end