1 require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3 module CharacterClassSpec
4 class Foo < Treetop::Runtime::SyntaxNode
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
13 result.should be_an_instance_of(Foo)
14 result.should respond_to(:a_method)
16 result.should be_an_instance_of(Foo)
17 result.should respond_to(:a_method)
19 result.should be_an_instance_of(Foo)
20 result.should respond_to(:a_method)
23 it "does not match single characters outside of that range" do
24 parse('8').should be_nil
25 parse('a').should be_nil
28 it "matches a single character within that range at index 1" do
29 parse(' A', :index => 1).should_not be_nil
32 it "fails to match a single character out of that range at index 1" do
33 parse(' 1', :index => 1).should be_nil
37 describe "A character class containing quotes" do
38 testing_expression "[\"']"
40 it "matches a quote" do
41 parse("'").should_not be_nil
44 it "matches a double-quote" do
45 parse('"').should_not be_nil
49 describe "A character class containing a /" do
50 testing_expression "[/]"
53 parse("/").should_not be_nil