|
|
|
@ -11,11 +11,26 @@ func Test_Lexer(t *testing.T) {
|
|
|
|
|
tcs := []struct {
|
|
|
|
|
name string
|
|
|
|
|
in string
|
|
|
|
|
expected []wikilink.ItemType
|
|
|
|
|
expected []wikilink.Item
|
|
|
|
|
}{
|
|
|
|
|
{name: "wikilink", in: "[[wikilink]]", expected: []wikilink.ItemType{wikilink.ItemOpenLink, wikilink.ItemText, wikilink.ItemCloseLink}},
|
|
|
|
|
{
|
|
|
|
|
name: "wikilink", in: "[[wikilink]]", expected: []wikilink.Item{
|
|
|
|
|
{Typ: wikilink.ItemOpenLink, Val: "[["},
|
|
|
|
|
{Typ: wikilink.ItemText, Val: "wikilink"},
|
|
|
|
|
{Typ: wikilink.ItemCloseLink, Val: "]]"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "wikilink|display name", in: "[[wikilink|display name]]", expected: []wikilink.Item{
|
|
|
|
|
{Typ: wikilink.ItemOpenLink, Val: "[["},
|
|
|
|
|
{Typ: wikilink.ItemText, Val: "wikilink"},
|
|
|
|
|
{Typ: wikilink.ItemAlias, Val: "|"},
|
|
|
|
|
{Typ: wikilink.ItemText, Val: "display name"},
|
|
|
|
|
{Typ: wikilink.ItemCloseLink, Val: "]]"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// {name: "", in: "", expected: []wikilink.ItemType{wikilink.ItemOpenLink, wikilink.ItemText, wikilink.ItemAlias, 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{}},
|
|
|
|
@ -39,8 +54,13 @@ func Test_Lexer(t *testing.T) {
|
|
|
|
|
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)
|
|
|
|
|
if e.Typ != n.Typ {
|
|
|
|
|
t.Logf("expected Type %s, received %s\n with raw value %q", e.String(), n, n.Val)
|
|
|
|
|
t.Fail()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if e.Val != n.Val {
|
|
|
|
|
t.Logf("expected Value %s, received %s\n with raw value %q", e.String(), n, n.Val)
|
|
|
|
|
t.Fail()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|