Fixed / inside of a char class generating a bad regex
[treetop.git] / spec / compiler / character_class_spec.rb
blobb7b652412b5a2897675bc585097b600c618af7eb
1 require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3 module CharacterClassSpec
4   class Foo < Treetop::Runtime::SyntaxNode
5   end
7   describe "a character class followed by a node class declaration and a block" do
9     testing_expression "[A-Z] <CharacterClassSpec::Foo> { def a_method; end }"
11     it "matches single characters within that range, returning instances of the declared node class that respond to the method defined in the inline module" do
12       result = parse('A')
13       result.should be_an_instance_of(Foo)
14       result.should respond_to(:a_method)
15       result = parse('N')
16       result.should be_an_instance_of(Foo)
17       result.should respond_to(:a_method)
18       result = parse('Z')
19       result.should be_an_instance_of(Foo)
20       result.should respond_to(:a_method)
21     end
22   
23     it "does not match single characters outside of that range" do
24       parse('8').should be_nil
25       parse('a').should be_nil
26     end
27   
28     it "matches a single character within that range at index 1" do
29       parse(' A', :index => 1).should_not be_nil
30     end
31   
32     it "fails to match a single character out of that range at index 1" do
33       parse(' 1', :index => 1).should be_nil
34     end
35   end
37   describe "A character class containing quotes" do
38     testing_expression "[\"']"
39   
40     it "matches a quote" do
41       parse("'").should_not be_nil
42     end
43   
44     it "matches a double-quote" do
45       parse('"').should_not be_nil
46     end
47   end
49   describe "A character class containing a /" do
50     testing_expression "[/]"
52     it "matches a /" do
53       parse("/").should_not be_nil
54     end
55   end
56 end