Add CodePointRange class
This commit is contained in:
1 parent
3a1650906e
commit
3987f08cd7
6 files changed
+142
-64
No files matched your search
+23
-23
@@ -114,7 +114,7 @@ module Imbecile
|
||||
expect(m_unit.min_count).to eq 5
|
||||
expect(m_unit.max_count).to eq 8
|
||||
expect(m_unit.unit).to be_a Regex::CharacterRangeUnit
|
||||
expect(m_unit.unit.range.first).to eq "a".ord
|
||||
expect(m_unit.unit.first).to eq "a".ord
|
||||
end
|
||||
|
||||
it "parses an escaped *" do
|
||||
@@ -125,9 +125,9 @@ module Imbecile
|
||||
seq_unit = regex.unit.alternates[0]
|
||||
expect(seq_unit.size).to eq 2
|
||||
expect(seq_unit[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(seq_unit[0].min_code_point).to eq "a".ord
|
||||
expect(seq_unit[0].first).to eq "a".ord
|
||||
expect(seq_unit[1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(seq_unit[1].min_code_point).to eq "*".ord
|
||||
expect(seq_unit[1].first).to eq "*".ord
|
||||
end
|
||||
|
||||
it "parses an escaped +" do
|
||||
@@ -138,9 +138,9 @@ module Imbecile
|
||||
seq_unit = regex.unit.alternates[0]
|
||||
expect(seq_unit.size).to eq 2
|
||||
expect(seq_unit[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(seq_unit[0].min_code_point).to eq "a".ord
|
||||
expect(seq_unit[0].first).to eq "a".ord
|
||||
expect(seq_unit[1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(seq_unit[1].min_code_point).to eq "+".ord
|
||||
expect(seq_unit[1].first).to eq "+".ord
|
||||
end
|
||||
|
||||
it "parses an escaped \\" do
|
||||
@@ -151,9 +151,9 @@ module Imbecile
|
||||
seq_unit = regex.unit.alternates[0]
|
||||
expect(seq_unit.size).to eq 2
|
||||
expect(seq_unit[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(seq_unit[0].min_code_point).to eq "\\".ord
|
||||
expect(seq_unit[0].first).to eq "\\".ord
|
||||
expect(seq_unit[1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(seq_unit[1].min_code_point).to eq "d".ord
|
||||
expect(seq_unit[1].first).to eq "d".ord
|
||||
end
|
||||
|
||||
it "parses a character class" do
|
||||
@@ -168,10 +168,10 @@ module Imbecile
|
||||
expect(ccu.negate).to be_falsey
|
||||
expect(ccu.size).to eq 2
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq "a".ord
|
||||
expect(ccu[0].max_code_point).to eq "z".ord
|
||||
expect(ccu[0].first).to eq "a".ord
|
||||
expect(ccu[0].last).to eq "z".ord
|
||||
expect(ccu[1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[1].min_code_point).to eq "_".ord
|
||||
expect(ccu[1].first).to eq "_".ord
|
||||
end
|
||||
|
||||
it "parses a negated character class" do
|
||||
@@ -186,7 +186,7 @@ module Imbecile
|
||||
expect(ccu.negate).to be_truthy
|
||||
expect(ccu.size).to eq 3
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq "x".ord
|
||||
expect(ccu[0].first).to eq "x".ord
|
||||
end
|
||||
|
||||
it "parses - as a plain character at beginning of a character class" do
|
||||
@@ -200,7 +200,7 @@ module Imbecile
|
||||
ccu = seq_unit[0]
|
||||
expect(ccu.size).to eq 2
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq "-".ord
|
||||
expect(ccu[0].first).to eq "-".ord
|
||||
end
|
||||
|
||||
it "parses - as a plain character at end of a character class" do
|
||||
@@ -214,9 +214,9 @@ module Imbecile
|
||||
ccu = seq_unit[0]
|
||||
expect(ccu.size).to eq 2
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq "0".ord
|
||||
expect(ccu[0].first).to eq "0".ord
|
||||
expect(ccu[1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[1].min_code_point).to eq "-".ord
|
||||
expect(ccu[1].first).to eq "-".ord
|
||||
end
|
||||
|
||||
it "parses - as a plain character at beginning of a negated character class" do
|
||||
@@ -231,7 +231,7 @@ module Imbecile
|
||||
expect(ccu.negate).to be_truthy
|
||||
expect(ccu.size).to eq 2
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq "-".ord
|
||||
expect(ccu[0].first).to eq "-".ord
|
||||
end
|
||||
|
||||
it "parses . as a plain character in a character class" do
|
||||
@@ -246,7 +246,7 @@ module Imbecile
|
||||
expect(ccu.negate).to be_falsey
|
||||
expect(ccu.size).to eq 1
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq ".".ord
|
||||
expect(ccu[0].first).to eq ".".ord
|
||||
end
|
||||
|
||||
it "parses - as a plain character when escaped in middle of character class" do
|
||||
@@ -261,11 +261,11 @@ module Imbecile
|
||||
expect(ccu.negate).to be_falsey
|
||||
expect(ccu.size).to eq 3
|
||||
expect(ccu[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[0].min_code_point).to eq "0".ord
|
||||
expect(ccu[0].first).to eq "0".ord
|
||||
expect(ccu[1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[1].min_code_point).to eq "-".ord
|
||||
expect(ccu[1].first).to eq "-".ord
|
||||
expect(ccu[2]).to be_a Regex::CharacterRangeUnit
|
||||
expect(ccu[2].min_code_point).to eq "9".ord
|
||||
expect(ccu[2].first).to eq "9".ord
|
||||
end
|
||||
|
||||
it "parses alternates" do
|
||||
@@ -314,9 +314,9 @@ module Imbecile
|
||||
expect(regex.unit.alternates[2]).to be_a Regex::SequenceUnit
|
||||
expect(regex.unit.alternates[2].size).to eq 2
|
||||
expect(regex.unit.alternates[2][0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(regex.unit.alternates[2][0].min_code_point).to eq "|".ord
|
||||
expect(regex.unit.alternates[2][0].first).to eq "|".ord
|
||||
expect(regex.unit.alternates[2][1]).to be_a Regex::CharacterRangeUnit
|
||||
expect(regex.unit.alternates[2][1].min_code_point).to eq "v".ord
|
||||
expect(regex.unit.alternates[2][1].first).to eq "v".ord
|
||||
expect(regex.unit.alternates[3]).to be_a Regex::SequenceUnit
|
||||
expect(regex.unit.alternates[3].size).to eq 1
|
||||
expect(regex.unit.alternates[3][0]).to be_a Regex::MultiplicityUnit
|
||||
@@ -325,8 +325,8 @@ module Imbecile
|
||||
expect(regex.unit.alternates[3][0].unit).to be_a Regex::CharacterClassUnit
|
||||
expect(regex.unit.alternates[3][0].unit.size).to eq 1
|
||||
expect(regex.unit.alternates[3][0].unit[0]).to be_a Regex::CharacterRangeUnit
|
||||
expect(regex.unit.alternates[3][0].unit[0].min_code_point).to eq "x".ord
|
||||
expect(regex.unit.alternates[3][0].unit[0].max_code_point).to eq "y".ord
|
||||
expect(regex.unit.alternates[3][0].unit[0].first).to eq "x".ord
|
||||
expect(regex.unit.alternates[3][0].unit[0].last).to eq "y".ord
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user