diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/parcom_spec.cr | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index ceb7de8..05fd12d 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -79,29 +79,10 @@ describe Result do end end -pending Parser do - describe "#assert" do - p = Basic(Char, Char).any_token.assert { |c| c == 'a' } - - it "succeeds if the parser succeeds and if the predicate passes" do - tokens = Tokens.from_string("abcd") - result = p.parse(tokens) - - result.value.should eq(tokens[0]) - result.tokens.should eq(tokens[1..]) - end - - it "fails if the predicate fails" do - tokens = Tokens.from_string("bbcd") - expect_raises(ParserFail) { p.parse(tokens) } - end - end -end - -describe Basic do - describe "Basic.pure" do +describe Parser do + describe "Parser.pure" do v = 'a' - p = Basic(Char, Char).pure(v) + p = Parser(Char, Char).pure(v) tokens = Tokens.from_string("____") result = p.parse(tokens) @@ -114,15 +95,15 @@ describe Basic do end end - describe "Basic.flunk" do - p = Basic(Char, Char).flunk + describe "Parser.flunk" do + p = Parser(Char, Char).flunk it "always fails" do expect_raises(ParserFail) { p.parse(Tokens.from_string("arbitrary")) } end end - describe "Basic.any_token" do - p = Basic(Char, Nil).any_token + describe "Parser.any_token" do + p = Parser(Char, Nil).any_token it "parses the first token in the input stream" do tokens = Tokens.from_string("abcd") @@ -138,8 +119,8 @@ describe Basic do end end - describe "Basic.eof" do - p = Basic(Char, Nil).eof + describe "Parser.eof" do + p = Parser(Char, Nil).eof it "succeeds with nil if the input stream is empty" do tokens = Tokens.from_string("") @@ -155,14 +136,12 @@ describe Basic do end end - # TODO: the type checker hates me - describe "Basic.satisfy" do - #p = Basic.satisfy(Char) { |c| c == 'a' } - p = Basic(Char, Char).satisfy(->(c : Char) { c == 'a' }) + describe "Parser.satisfy" do + p = Parser(Char, Char).satisfy { |c| c == 'a' } it "succeeds if the token passes the predicate" do tokens = Tokens.from_string("abcd") - result = p.parse(tokens).as_a(Result(Char, Char)) + result = p.parse(tokens) result.value.should eq(tokens[0]) result.tokens.should eq(tokens[1..]) @@ -173,5 +152,25 @@ describe Basic do expect_raises(ParserFail) { p.parse(tokens) } end end + + describe "#assert" do + p = Parser(Char, Char).any_token.assert { |c| c == 'a' } + + it "succeeds if the parser succeeds and if the predicate passes" do + tokens = Tokens.from_string("abcd") + result = p.parse(tokens) + + result.value.should eq(tokens[0]) + result.tokens.should eq(tokens[1..]) + end + + it "fails if the predicate fails" do + tokens = Tokens.from_string("bbcd") + expect_raises(ParserFail) { p.parse(tokens) } + end + end end +#pending Basic do +##end + |
