Skip to content

Commit 784b5cc

Browse files
authored
test(WO80/A4): rulings for contexts, maybe, and capture (#820)
Six more normative rulings pinned as vectors: before/after are zero-width lookbehind/lookahead; maybe is zero-or-one within longest-match; capture/ref round-trips in sequential rules; capture inside parallel raises (the WO80 capture-support gap -- now with two motivating cases: the RTGS compound vowels and the parallel capture crash).
1 parent d59ee95 commit 784b5cc

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

‎spec/isc/semantics_spec.rb‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,86 @@ def with_map(name, body)
5656
end
5757
end
5858
end
59+
60+
RSpec.describe "ISC semantics — contexts, maybe, capture" do
61+
def with_map(name, body)
62+
dir = Dir.mktmpdir
63+
File.write(File.join(dir, name), body)
64+
Interscript.load_path.unshift(dir)
65+
yield
66+
ensure
67+
Interscript.load_path.delete(dir) if dir
68+
end
69+
70+
def context_map(id, rule)
71+
<<~ISC
72+
system "TST:xx-Latn:Latn:#{id}" {
73+
metadata {
74+
authority_id tst
75+
id #{id}
76+
language iso-639-2:xx
77+
source_script Latn
78+
destination_script Latn
79+
}
80+
stage main { parallel { sub { #{rule} } } }
81+
}
82+
ISC
83+
end
84+
85+
it "rules: before is a zero-width lookbehind (not consumed)" do
86+
with_map("tst-before-2.isc", context_map(11, 'from "a" to "X" before "b"')) do
87+
expect(Interscript.transliterate("tst-before-2", "ba")).to eq("bX")
88+
expect(Interscript.transliterate("tst-before-2", "ab")).to eq("ab")
89+
end
90+
end
91+
92+
it "rules: after is a zero-width lookahead (not consumed)" do
93+
with_map("tst-after-2.isc", context_map(12, 'from "b" to "Y" after "a"')) do
94+
expect(Interscript.transliterate("tst-after-2", "ba")).to eq("Ya")
95+
expect(Interscript.transliterate("tst-after-2", "ab")).to eq("ab")
96+
end
97+
end
98+
99+
it "rules: maybe is zero-or-one and participates in longest-match" do
100+
with_map("tst-maybe-2.isc", <<~ISC) do
101+
system "TST:xx-Latn:Latn:13" {
102+
metadata {
103+
authority_id tst
104+
id 13
105+
language iso-639-2:xx
106+
source_script Latn
107+
destination_script Latn
108+
}
109+
stage main { parallel { sub { from "k" + maybe("h") to "X" } } }
110+
}
111+
ISC
112+
expect(Interscript.transliterate("tst-maybe-2", "k")).to eq("X")
113+
expect(Interscript.transliterate("tst-maybe-2", "kh")).to eq("X")
114+
expect(Interscript.transliterate("tst-maybe-2", "kk")).to eq("XX")
115+
end
116+
end
117+
118+
it "rules: capture/ref round-trips in sequential rules" do
119+
with_map("tst-capseq-2.isc", <<~ISC) do
120+
system "TST:xx-Latn:Latn:14" {
121+
metadata {
122+
authority_id tst
123+
id 14
124+
language iso-639-2:xx
125+
source_script Latn
126+
destination_script Latn
127+
}
128+
stage main { sub { from capture(any("0".."9")) to ref(1) } }
129+
}
130+
ISC
131+
expect(Interscript.transliterate("tst-capseq-2", "77a9")).to eq("77a9")
132+
end
133+
end
134+
135+
it "rules: capture inside parallel is pending capture support (WO80)" do
136+
with_map("tst-cappar-1.isc", context_map(15, 'from capture(any("0".."9")) to ref(1)')) do
137+
expect { Interscript.transliterate("tst-cappar-1", "5") }
138+
.to raise_error(NoMethodError, /max_length/)
139+
end
140+
end
141+
end

0 commit comments

Comments
 (0)