more tests

parslet
Jordan Orelli 9 years ago
parent 4b785b6034
commit bb0084e198

@ -29,7 +29,7 @@ module Bristlecode
rule(:tag_delim) { tag_open | tag_close } rule(:tag_delim) { tag_open | tag_close }
rule(:text) { (tag_delim.absent? >> any).repeat(1).as(:text) } rule(:text) { (tag_delim.absent? >> any).repeat(1).as(:text) }
rule(:children) { space? >> elem.repeat(1) } rule(:children) { space? >> elem.repeat }
rule(:doc) { space? >> elem.repeat.as(:doc) } rule(:doc) { space? >> elem.repeat.as(:doc) }
root(:doc) root(:doc)
end end

@ -10,6 +10,10 @@ module Bristlecode
expect(parser).to parse('') expect(parser).to parse('')
end end
it 'can parse whitespace' do
expect(parser).to parse(' ')
end
it 'can parse plain text' do it 'can parse plain text' do
expect(parser).to parse('this is some plain text') expect(parser).to parse('this is some plain text')
end end
@ -23,6 +27,15 @@ module Bristlecode
expect(parser.bold).to parse('[B]bolded contents here[/B]') expect(parser.bold).to parse('[B]bolded contents here[/B]')
end end
it 'can parse an empty bold tag' do
expect(parser.bold).to parse('[b][/b]')
end
it 'can parse nested tags' do
expect(parser.bold).to parse('[b] one [b] two [/b] three [/b]')
expect(parser.bold).to parse('[b] one [i] two [/i] three [/b]')
end
it 'can parse an unclosed tag' do it 'can parse an unclosed tag' do
expect(parser.bold).to parse('[b]bolded contents here') expect(parser.bold).to parse('[b]bolded contents here')
expect(parser.bold).to parse('[B]bolded contents here') expect(parser.bold).to parse('[B]bolded contents here')
@ -49,6 +62,15 @@ module Bristlecode
expect(parser.italic).to parse('[I]italiced contents here[/I]') expect(parser.italic).to parse('[I]italiced contents here[/I]')
end end
it 'can parse an empty italic tag' do
expect(parser.italic).to parse('[i][/i]')
end
it 'can parse nested tags' do
expect(parser.italic).to parse('[i] one [i] two [/i] three [/i]')
expect(parser.italic).to parse('[i] one [b] two [/b] three [/i]')
end
it 'can parse an unclosed tag' do it 'can parse an unclosed tag' do
expect(parser.italic).to parse('[i]italiced contents here') expect(parser.italic).to parse('[i]italiced contents here')
expect(parser.italic).to parse('[I]italiced contents here') expect(parser.italic).to parse('[I]italiced contents here')

Loading…
Cancel
Save