Sha256: 546ccb7fb02fc594aba362397a992a8f213c8c9977a26372f898935b3d46d460
Contents?: true
Size: 1.18 KB
Versions: 7
Compression:
Stored size: 1.18 KB
Contents
require 'spec_helper' describe "Tree output" do extend Parslet def self.hash_examples(h) h.each do |atom, expected| it "should convert #{atom} to #{expected.inspect}" do atom.parse(input).should == expected end end end context "when parsing the empty string" do let(:input) { '' } hash_examples( # No naming str('a').maybe => '', str('a').repeat => '', # Named contents: maybe yields nil str('a').maybe.as(:f) => {:f => nil}, str('a').repeat.as(:f) => {:f => []}, # Contents that aren't simple strings (str('a') >> str('b')).maybe.as(:f) => {:f => nil}, (str('a') >> str('b')).repeat.as(:f) => {:f => []}, # The other way around: Contents would be tagged, but nil result isn't (str('a') >> str('b')).as(:f).maybe => '', (str('a') >> str('b')).as(:f).repeat => '' ) end context "when parsing 'aa'" do let(:input) { 'aa' } hash_examples( # since they're not named, repetitions get merged together. str('a').as(:a).repeat >> str('a').as(:a).repeat => [{:a=>'a'},{:a=>'a'}] ) end end
Version data entries
7 entries across 7 versions & 2 rubygems