upgrading test suite

dev
Nick Dumas 1 year ago
parent 4735f0b36d
commit d377070fe1

@ -16,26 +16,67 @@ func Test_Lexer(t *testing.T) {
{ {
name: "wikilink", in: "[[wikilink]]", expected: []wikilink.Item{ name: "wikilink", in: "[[wikilink]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["}, {Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemText, Val: "wikilink"}, {Typ: wikilink.ItemIdent, Val: "wikilink"},
{Typ: wikilink.ItemCloseLink, Val: "]]"}, {Typ: wikilink.ItemCloseLink, Val: "]]"},
}, },
}, },
{ {
name: "wikilink|display name", in: "[[wikilink|display name]]", expected: []wikilink.Item{ name: "wikilink|display name", in: "[[wikilink|display name]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["}, {Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemText, Val: "wikilink"}, {Typ: wikilink.ItemIdent, Val: "wikilink"},
{Typ: wikilink.ItemAlias, Val: "|"}, {Typ: wikilink.ItemAlias, Val: "|"},
{Typ: wikilink.ItemText, Val: "display name"}, {Typ: wikilink.ItemIdent, Val: "display name"},
{Typ: wikilink.ItemCloseLink, Val: "]]"},
},
},
{
name: "wikilink|display name|second pipe", in: "[[wikilink|display name|second pipe]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemIdent, Val: "wikilink"},
{Typ: wikilink.ItemAlias, Val: "|"},
{Typ: wikilink.ItemIdent, Val: "display name"},
{Typ: wikilink.ItemAlias, Val: "|"},
{Typ: wikilink.ItemIdent, Val: "second pipe"},
{Typ: wikilink.ItemCloseLink, Val: "]]"},
},
},
{
name: "wikilink with numeric alias|420|second pipe", in: "[[wikilink|420|second pipe]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemIdent, Val: "wikilink"},
{Typ: wikilink.ItemAlias, Val: "|"},
{Typ: wikilink.ItemIdent, Val: "420"},
{Typ: wikilink.ItemAlias, Val: "|"},
{Typ: wikilink.ItemIdent, Val: "second pipe"},
{Typ: wikilink.ItemCloseLink, Val: "]]"},
},
},
{
name: "wikilink with spaces in filename", in: "[[wikilink spaces]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemIdent, Val: "wikilink spaces"},
{Typ: wikilink.ItemCloseLink, Val: "]]"},
},
},
{
name: "#heading", in: "[[#heading]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemHeading, Val: "#"},
{Typ: wikilink.ItemIdent, Val: "heading"},
{Typ: wikilink.ItemCloseLink, Val: "]]"},
},
},
{
name: "wikilink#heading", in: "[[wikilink#heading]]", expected: []wikilink.Item{
{Typ: wikilink.ItemOpenLink, Val: "[["},
{Typ: wikilink.ItemIdent, Val: "wikilink"},
{Typ: wikilink.ItemHeading, Val: "#"},
{Typ: wikilink.ItemIdent, Val: "heading"},
{Typ: wikilink.ItemCloseLink, Val: "]]"}, {Typ: wikilink.ItemCloseLink, Val: "]]"},
}, },
}, },
// {name: "", in: "", expected: []wikilink.ItemType{wikilink.ItemOpenLink, wikilink.ItemText, wikilink.ItemAlias, wikilink.ItemText, wikilink.ItemCloseLink}},
/* /*
{name: "wikilink|display name|second pipe", in: "[[wikilink|display name|second pipe]]", expected: []wikilink.ItemType{}}, {name: "", in: "", 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", 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#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: "wikilink with numeric aliases#heading|420|display name", in: "[[wikilink#heading|420|second pipe]]", expected: []wikilink.ItemType{}},
@ -55,12 +96,12 @@ func Test_Lexer(t *testing.T) {
for _, e := range tc.expected { for _, e := range tc.expected {
n := l.NextItem() n := l.NextItem()
if e.Typ != n.Typ { if e.Typ != n.Typ {
t.Logf("expected Type %s, received %s with raw value %q", e.String(), n, n.Val) t.Logf("expected Type %s, received %s", e.Typ.String(), n.Typ.String())
t.Fail() t.Fail()
} }
if e.Val != n.Val { if e.Val != n.Val {
t.Logf("expected Value %s, received %s with raw value %q", e.String(), n, n.Val) t.Logf("expected Value %q, received %q", e.Val, n.Val)
t.Fail() t.Fail()
} }
} }

Loading…
Cancel
Save