Skip to content

Add test task and fix some cases #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ some input and returns a `ParserResult`.

## Running tests

$ ruby -Ilib:test test/test_parser.rb
``` shell
rake test
ruby -Ilib:test test/test_parser.rb # per-file testing
```

# TODO
Decent syntax error reporting, eg: Which line, which column failed.
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.test_files = FileList["test/test_*.rb"]
end
2 changes: 1 addition & 1 deletion lib/parser_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(success, remaining, matched, output=nil)
@output = output.nil? ? [matched] : output
end

def self.ok(output=nil, matched:, remaining:)
def self.ok(output=nil, matched: "", remaining: "")
# yield matched if block_given?
output = [matched] if output.nil?
ParserResult.new(true, remaining, matched, output)
Expand Down
4 changes: 2 additions & 2 deletions test/test_base_parsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@
start(:letterOrNumber)
end

assert_equal ["w", "8"], parser.run("w8").output
assert_equal [["w"], ["8"]], parser.run("w8").output

parser = Grammar.build do
rule(:letter) { many1 { anyLetter } }
rule(:letterOrNumber) { seq rule(:letter), anyNumber, lambda { |letter, number| [letter, number] } }
start(:letterOrNumber)
end

assert_equal ["w", "8"], parser.run("w8").output
assert_equal [["w"], ["8"]], parser.run("w8").output
end

it "uses regex" do
Expand Down