More tests

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

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

@ -150,7 +150,7 @@ func (l *Lexer) emit(t LexemeType) {
L := l.L.Named("emit").With(
zap.String("item", i.String()),
)
L.Info("emitting lexeme")
L.Debug("emitting lexeme")
l.Items = append(l.Items, i)
l.SetStart(l.GetPos())
/* 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) {
for _, tc := range testCases {
mut, test := mutateTestCase(tc,
mut, test := mutateTestCase(
tc,
"this is a ",
"",
[]wikilink.Lexeme{
{Typ: wikilink.LexText, Val: "this is a "},
},
nil,
"",
)
t.Run(mut.name, test)
}
@ -228,7 +246,15 @@ func Test_ObsidianWikilinks_Basic(t *testing.T) {
// t.Parallel()
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)
}
}
@ -239,8 +265,7 @@ type tc struct {
expected []wikilink.Lexeme
}
func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix []wikilink.Lexeme, name string) (tc, func(t *testing.T)) {
tc.name = tc.name + "/" + name
func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix []wikilink.Lexeme) (tc, func(t *testing.T)) {
tc.in = prefix + tc.in
tc.in = tc.in + suffix
if expectedPrefix != nil {
@ -256,6 +281,7 @@ func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix
defer l.L.Sync()
if 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.Fail()

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

Loading…
Cancel
Save