Browse files

some more tests for the grammar

  • Loading branch information...
1 parent 9b20b20 commit 74f7741c54a8a87e8bd5659b87535aabfcbfb92c @adamjmurray committed Jun 30, 2011
Showing with 41 additions and 4 deletions.
  1. +6 −2 lib/mtk/lang/mtk.citrus
  2. +35 −2 spec/mtk/lang/grammar_spec.rb
View
8 lib/mtk/lang/mtk.citrus
@@ -19,7 +19,11 @@ grammar MTK_Grammar
}
end
- rule float do
+ rule number
+ float | int
+ end
+
+ rule float
( '-'? [0-9]+ '.' [0-9]+ ) {
to_f
}
@@ -32,7 +36,7 @@ grammar MTK_Grammar
end
rule space
- [\s]+
+ [\s]+ { nil }
end
end
View
37 spec/mtk/lang/grammar_spec.rb
@@ -8,12 +8,45 @@ def parse syntax, root
end
describe ".parse" do
+
+ it "should parse pitch sequences" do
+ parse("C4 D4 E4", :pitch_sequence).should == Pattern.PitchSequence(C4, D4, E4)
+ end
+
it "should parse pitch classes" do
parse("Db", :pitch_class).should == Db
end
- it do
- parse("C4 D4 E4", :pitch_sequence).should == Pattern.PitchSequence(C4, D4, E4)
+ it "should parse ints as numbers" do
+ parse("123", :number).should == 123
+ end
+
+ it "should parse floats as numbers" do
+ parse("1.23", :number).should == 1.23
+ end
+
+ it "should parse floats" do
+ parse("1.23", :float).should == 1.23
+ end
+
+ it "should parse negative floats" do
+ parse("-1.23", :float).should == -1.23
+ end
+
+ it "should parse ints" do
+ parse("123", :int).should == 123
+ end
+
+ it "should parse negative ints" do
+ parse("-123", :int).should == -123
+ end
+
+ it "should parse negative ints" do
+ parse("-123", :int).should == -123
+ end
+
+ it "should give nil as the value for whitespace" do
+ parse(" \t\n", :space).should == nil
end
end
end

0 comments on commit 74f7741

Please sign in to comment.