examples/general/SRL/spec/integration_spec.rb in rley-0.6.00 vs examples/general/SRL/spec/integration_spec.rb in rley-0.6.01
- old
+ new
@@ -10,11 +10,11 @@
end
def regexp_repr(aResult)
# Generate an abstract syntax parse tree from the parse result
tree = @engine.convert(aResult)
- regexp = tree.root
+ tree.root
end
before(:each) do
@engine = Rley::Engine.new do |config|
config.repr_builder = ASTBuilder
@@ -194,11 +194,11 @@
expect(regexp.to_str).to eq('(?:\w|[._%\-+])')
end
end # context
context 'Parsing concatenation:' do
- it "should reject dangling comma" do
+ it 'should reject dangling comma' do
source = 'literally "a",'
result = parse(source)
expect(result).not_to be_success
message_prefix = /Premature end of input after ','/
expect(result.failure_reason.message).to match(message_prefix)
@@ -210,11 +210,11 @@
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('(?:sample|(?:\d+))')
end
- it "should parse a long sequence of patterns" do
+ it 'should parse a long sequence of patterns' do
source = <<-ENDS
any of (any character, one of "._%-+") once or more,
literally "@",
any of (digit, letter, one of ".-") once or more,
literally ".",
@@ -223,12 +223,13 @@
result = parse(source)
expect(result).to be_success
regexp = regexp_repr(result)
- # SRL expect: (?:\w|[\._%\-\+])+(?:@)(?:[0-9]|[a-z]|[\.\-])+(?:\.)[a-z]{2,}
- expect(regexp.to_str).to eq('(?:\w|[._%\-+])+@(?:\d|[a-z]|[.\-])+\.[a-z]{2,}')
+ # SRL: (?:\w|[\._%\-\+])+(?:@)(?:[0-9]|[a-z]|[\.\-])+(?:\.)[a-z]{2,}
+ expectation = '(?:\w|[._%\-+])+@(?:\d|[a-z]|[.\-])+\.[a-z]{2,}'
+ expect(regexp.to_str).to eq(expectation)
end
end # context
context 'Parsing quantifiers:' do
let(:prefix) { 'letter from p to t ' }
@@ -343,11 +344,12 @@
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('(sample)')
end
it 'should parse complex anonymous capturing group' do
- result = parse('capture(any of (literally "sample", (digit once or more)))')
+ source = 'capture(any of (literally "sample", (digit once or more)))'
+ result = parse(source)
expect(result).to be_success
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('((?:sample|(?:\d+)))')
end
@@ -359,11 +361,15 @@
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('(.+)!')
end
it 'should parse complex named capturing group' do
- result = parse('capture(any of (literally "sample", (digit once or more))) as "foo"')
+ source = <<-END_SRL
+capture(any of (literally "sample", (digit once or more)))
+ as "foo"
+END_SRL
+ result = parse(source)
expect(result).to be_success
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('(?<foo>(?:sample|(?:\d+)))')
end
@@ -380,11 +386,12 @@
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('(?<first>.+) - (?<second>second part)')
end
it 'should parse complex named until capturing group' do
- result = parse('capture (anything once or more) as "foo" until literally "m"')
+ source = 'capture (anything once or more) as "foo" until literally "m"'
+ result = parse(source)
expect(result).to be_success
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('(?<foo>.+)m')
end
@@ -421,23 +428,21 @@
regexp = regexp_repr(result)
expect(regexp.to_str).to eq('^match$')
end
- it "should accept anchor with a sequence of patterns" do
+ it 'should accept anchor with a sequence of patterns' do
source = <<-ENDS
begin with any of (digit, letter, one of ".-") once or more,
literally ".",
letter at least 2 times must end
ENDS
result = parse(source)
expect(result).to be_success
regexp = regexp_repr(result)
- # SRL expect: (?:\w|[\._%\-\+])+(?:@)(?:[0-9]|[a-z]|[\.\-])+(?:\.)[a-z]{2,}
+ # SRL: (?:\w|[\._%\-\+])+(?:@)(?:[0-9]|[a-z]|[\.\-])+(?:\.)[a-z]{2,}
expect(regexp.to_str).to eq('^(?:\d|[a-z]|[.\-])+\.[a-z]{2,}$')
end
end # context
end # describe
-
-