Module: Pione::TestHelper::Parser
- Defined in:
- lib/pione/test-helper/parser-helper.rb
Class Method Summary collapse
-
.make_test_parser(parser_module) ⇒ Object
Make a test parser class by the sub-parser module.
-
.spec(rb, context, parser = Pione::Lang::DocumentParser) ⇒ Object
Make specifications of parser.
Class Method Details
.make_test_parser(parser_module) ⇒ Object
Make a test parser class by the sub-parser module.
5 6 7 8 9 10 11 |
# File 'lib/pione/test-helper/parser-helper.rb', line 5 def make_test_parser(parser_module) klass = Class.new(Parslet::Parser) klass.instance_eval do include parser_module end return klass end |
.spec(rb, context, parser = Pione::Lang::DocumentParser) ⇒ Object
Make specifications of parser.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pione/test-helper/parser-helper.rb', line 15 def spec(rb, context, parser=Pione::Lang::DocumentParser) basename = File.basename(rb, ".rb") path = File.join(File.dirname(rb), "data", basename[5..-1] + ".yml") YAML.load(File.read(path)).each do |name, testcase| context.describe name do if strings = testcase["valid"] strings.each do |string| it "should parse as %s:%s%s" % [name, string.include?("\n") ? "\n" : " ", string.chomp] do should.not.raise(Parslet::ParseFailed) do parser.new.send(name).parse(string) end end end end if strings = testcase["invalid"] strings.each do |string| it "should fail when parsing as %s:%s%s" % [name, string.include?("\n") ? "\n" : " ", string.chomp] do should.raise(Parslet::ParseFailed) do parser.new.send(name).parse(string) end end end end end end end |