first round of tests for the lexer

dev
Nick Dumas 2 years ago
parent 9f110fff78
commit 8138ae6e54

@ -0,0 +1,49 @@
package wikilink_test
import (
"testing"
"code.ndumas.com/ndumas/wikilink-parser"
)
func Test_Lexer(t *testing.T) {
// t.Parallel()
tcs := []struct {
name string
in string
expected []wikilink.ItemType
}{
{name: "wikilink", in: "[[wikilink]]", expected: []wikilink.ItemType{wikilink.ItemOpenLink, wikilink.ItemText, wikilink.ItemCloseLink}},
/*
{name: "wikilink|display name", in: "[[wikilink|display name]]", expected: []wikilink.ItemType{}},
{name: "wikilink|display name|second pipe", in: "[[wikilink|display name|second pipe]]", expected: []wikilink.ItemType{}},
{name: "wikilink with numeric alias|420|second pipe", in: "[[wikilink|420|second pipe]]", expected: []wikilink.ItemType{}},
{name: "wikilink with spaces in filename", in: "[[wikilink spaces]]", expected: []wikilink.ItemType{}},
{name: "#heading", in: "[[#heading]]", expected: []wikilink.ItemType{}},
{name: "wikilink#heading", in: "[[wikilink#heading]]", expected: []wikilink.ItemType{}},
{name: "wikilink#heading|display name", in: "[[wikilink#heading|display name]]", expected: []wikilink.ItemType{}},
{name: "wikilink#heading|display name|second pipe", in: "[[wikilink#heading|display name|second pipe]]", expected: []wikilink.ItemType{}},
{name: "wikilink with numeric aliases#heading|420|display name", in: "[[wikilink#heading|420|second pipe]]", expected: []wikilink.ItemType{}},
{name: "^blockRef", in: "[[^blockRef]]", expected: []wikilink.ItemType{}},
{name: "wikilink^blockRef", in: "[[wikilink^blockRef]]", expected: []wikilink.ItemType{}},
{name: "wikilink^blockRef|display name", in: "[[wikilink#^blockRef|display name]]", expected: []wikilink.ItemType{}},
{name: "wikilink^blockRef|display name|second pipe", in: "[[wikilink#^blockRef|display name|second pipe]]", expected: []wikilink.ItemType{}},
{name: "wikilink with numeric aliases^blockRef|420|second pipe", in: "[[wikilink#^blockRef|420|second pipe]]", expected: []wikilink.ItemType{}},
*/
}
for _, tc := range tcs {
tc := tc
t.Run(tc.name, func(t *testing.T) {
// t.Parallel()
l := wikilink.Lex("testLexer", tc.in)
for _, e := range tc.expected {
n := l.NextItem()
if e != n.Typ {
t.Logf("expected %s, received %s\n with raw value %q", e, n, n.Val)
t.Fail()
}
}
})
}
}
Loading…
Cancel
Save