diff --git a/lexer_test.go b/lexer_test.go index 51e589a..e32c292 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -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( diff --git a/states.go b/states.go index 7ad8451..7f21fb3 100644 --- a/states.go +++ b/states.go @@ -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 } } }