spec/d-mark/parser_spec.rb in d-mark-0.2.0 vs spec/d-mark/parser_spec.rb in d-mark-1.0.0a1
- old
+ new
@@ -1,11 +1,11 @@
def parse(s)
DMark::Parser.new(s).parse
end
def element(name, attributes, children)
- DMark::Parser::ElementNode.new(name, attributes, children)
+ DMark::ElementNode.new(name, attributes, children)
end
describe 'DMark::Parser#parser' do
it 'parses' do
expect(parse('')).to eq []
@@ -256,9 +256,40 @@
[
element('li', { 'foo' => 'foo' }, [])
]
)
]
+ end
+
+ it 'parses document starting with blank lines' do
+ expect(parse(" \n \np. Hi!")).to eq [
+ element('p', {}, ['Hi!'])
+ ]
+ end
+
+ it 'does not parse percent escapes' do
+ expect { parse('p. %ref[url=https://github.com/pulls?q=is%3Aopen+user%3Ananoc]{eek}') }
+ .to raise_error(DMark::Parser::ParserError, 'parse error at line 1, col 43: expected "%", "," or "]" after "%", but got "3"')
+ end
+
+ it 'does not parse attribute values ending with an end-of-file' do
+ expect { parse('p. %ref[url=hello') }
+ .to raise_error(DMark::Parser::ParserError, 'parse error at line 1, col 18: unexpected file end in attribute value')
+ end
+
+ it 'does not parse attribute values ending with a line break' do
+ expect { parse("p. %ref[url=hello\n") }
+ .to raise_error(DMark::Parser::ParserError, 'parse error at line 1, col 18: unexpected line break in attribute value')
+ end
+
+ it 'does not parse escaped attribute values ending with an end-of-file' do
+ expect { parse('p. %ref[url=hello%') }
+ .to raise_error(DMark::Parser::ParserError, 'parse error at line 1, col 19: unexpected file end in attribute value')
+ end
+
+ it 'does not parse escaped attribute values ending with a line break' do
+ expect { parse("p. %ref[url=hello%\n") }
+ .to raise_error(DMark::Parser::ParserError, 'parse error at line 1, col 19: unexpected line break in attribute value')
end
it 'does not parse' do
expect { parse('p') }.to raise_error(DMark::Parser::ParserError)
expect { parse('0') }.to raise_error(DMark::Parser::ParserError)