Lexer can now handle multi-line inputs

main
Nick Dumas 1 year ago
parent 17699a114c
commit 3f3696eb9f

@ -196,6 +196,48 @@ var testCases = []tc{
},
}
func Test_ObsidianWikilinks_LinksEndOfMultiLineInput(t *testing.T) {
for _, tc := range testCases {
mut, test := mutateTestCase(
tc,
" test data please ignore.\nbling blonk more lines\nbling blong\nthis is a",
"",
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: " test data please ignore.\n"},
{Typ: wikilink.LexText, Val: "bling blonk more lines\n"},
{Typ: wikilink.LexText, Val: "bling blong\n"},
{Typ: wikilink.LexText, Val: "this is a"},
},
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: ""},
},
)
t.Run(mut.name, test)
}
}
func Test_ObsidianWikilinks_LinksStartOfMultiLineInput(t *testing.T) {
for _, tc := range testCases {
mut, test := mutateTestCase(
tc,
"",
" test data please ignore.\nbling blonk more lines\nbling blong\nthis is a",
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: ""},
},
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: " test data please ignore.\n"},
{Typ: wikilink.LexText, Val: "bling blonk more lines\n"},
{Typ: wikilink.LexText, Val: "bling blong\n"},
{Typ: wikilink.LexText, Val: "this is a"},
},
)
t.Run(mut.name, test)
}
}
func Test_ObsidianWikilinks_LinksStartOfInput(t *testing.T) {
for _, tc := range testCases {
mut, test := mutateTestCase(

@ -92,9 +92,12 @@ func lexText(l *Lexer) stateFn {
}
r := l.next()
switch {
case r == EOF || r == '\n':
case r == EOF:
l.emit(LexText)
return nil
case r == '\n':
l.emit(LexText)
return lexText
}
}
}

Loading…
Cancel
Save