You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.3 KiB
Go
50 lines
2.3 KiB
Go
1 year ago
|
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()
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|