More tests

main
Nick Dumas 1 year ago
parent 04458800d1
commit 82dd27bd06

@ -7,7 +7,7 @@ import (
) )
func main() { func main() {
l := wikilink.Lex("debugLexer", `[[#heading]]`) l := wikilink.Lex("debugLexer", `this is a [[wikilink]]`)
for _, item := range l.Items { for _, item := range l.Items {
item := item item := item
log.Printf("%#+v\n", item) log.Printf("%#+v\n", item)

@ -150,7 +150,7 @@ func (l *Lexer) emit(t LexemeType) {
L := l.L.Named("emit").With( L := l.L.Named("emit").With(
zap.String("item", i.String()), zap.String("item", i.String()),
) )
L.Info("emitting lexeme") L.Debug("emitting lexeme")
l.Items = append(l.Items, i) l.Items = append(l.Items, i)
l.SetStart(l.GetPos()) l.SetStart(l.GetPos())
/* original concurrent implementation /* original concurrent implementation

@ -209,16 +209,34 @@ var testCases = []tc{
}, },
} }
func Test_ObsidianWikilinks_LinksStartOfInput(t *testing.T) {
for _, tc := range testCases {
mut, test := mutateTestCase(
tc,
"",
" test data please ignore",
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: ""},
},
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: " test data please ignore"},
},
)
t.Run(mut.name, test)
}
}
func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) { func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
mut, test := mutateTestCase(tc, mut, test := mutateTestCase(
tc,
"this is a ", "this is a ",
"", "",
[]wikilink.Lexeme{ []wikilink.Lexeme{
{Typ: wikilink.LexText, Val: "this is a "}, {Typ: wikilink.LexText, Val: "this is a "},
}, },
nil, nil,
"",
) )
t.Run(mut.name, test) t.Run(mut.name, test)
} }
@ -228,7 +246,15 @@ func Test_ObsidianWikilinks_Basic(t *testing.T) {
// t.Parallel() // t.Parallel()
for _, tc := range testCases { for _, tc := range testCases {
mut, test := mutateTestCase(tc, "", "", nil, nil, "") mut, test := mutateTestCase(
tc,
"",
"",
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: ""},
},
nil,
)
t.Run(mut.name, test) t.Run(mut.name, test)
} }
} }
@ -239,8 +265,7 @@ type tc struct {
expected []wikilink.Lexeme expected []wikilink.Lexeme
} }
func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix []wikilink.Lexeme, name string) (tc, func(t *testing.T)) { func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix []wikilink.Lexeme) (tc, func(t *testing.T)) {
tc.name = tc.name + "/" + name
tc.in = prefix + tc.in tc.in = prefix + tc.in
tc.in = tc.in + suffix tc.in = tc.in + suffix
if expectedPrefix != nil { if expectedPrefix != nil {
@ -256,6 +281,7 @@ func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix
defer l.L.Sync() defer l.L.Sync()
if len(tc.expected) != len(l.Items) { if len(tc.expected) != len(l.Items) {
t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items)) t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items))
t.Logf("expected items: %#v\n", tc.expected)
t.Logf("raw items: %#v\n", l.Items) t.Logf("raw items: %#v\n", l.Items)
t.Fail() t.Fail()

@ -87,6 +87,7 @@ func lexText(l *Lexer) stateFn {
for { for {
if isOpenLink(l.input[l.GetPos():]) { if isOpenLink(l.input[l.GetPos():]) {
L.Debug("found openLink") L.Debug("found openLink")
l.emit(LexText)
return lexOpenLink return lexOpenLink
} }
r := l.next() r := l.next()

Loading…
Cancel
Save