|
|
@ -6,458 +6,229 @@ import (
|
|
|
|
"code.ndumas.com/ndumas/wikilink-parser"
|
|
|
|
"code.ndumas.com/ndumas/wikilink-parser"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
|
|
|
|
var testCases = []tc{
|
|
|
|
tcs := []struct {
|
|
|
|
{
|
|
|
|
name string
|
|
|
|
name: "wikilink",
|
|
|
|
in string
|
|
|
|
in: "[[wikilink]]",
|
|
|
|
expected []wikilink.Lexeme
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
}{
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
name: "wikilink",
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
in: "[[wikilink]]",
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: "this is a "},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink|display name",
|
|
|
|
{
|
|
|
|
in: "is a [[wikilink|display name]]",
|
|
|
|
name: "wikilink|display name",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink|display name]]",
|
|
|
|
{Typ: wikilink.LexText, Val: "this is a "},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink|display name|second pipe",
|
|
|
|
{
|
|
|
|
in: "[[wikilink|display name|second pipe]]",
|
|
|
|
name: "wikilink|display name|second pipe",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink|display name|second pipe]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink with numeric alias|420|second pipe",
|
|
|
|
{
|
|
|
|
in: "[[wikilink|420|second pipe]]",
|
|
|
|
name: "wikilink with numeric alias|420|second pipe",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink|420|second pipe]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink with spaces in filename",
|
|
|
|
{
|
|
|
|
in: "[[wikilink spaces]]",
|
|
|
|
name: "wikilink with spaces in filename",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink spaces]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink spaces"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink spaces"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "#heading",
|
|
|
|
{
|
|
|
|
in: "[[#heading]]",
|
|
|
|
name: "#heading",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[#heading]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: ""},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: ""},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink#heading",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#heading]]",
|
|
|
|
name: "wikilink#heading",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#heading]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink#heading|display name",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#heading|display name]]",
|
|
|
|
name: "wikilink#heading|display name",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#heading|display name]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink#heading|display name|second pipe",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#heading|display name|second pipe]]",
|
|
|
|
name: "wikilink#heading|display name|second pipe",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#heading|display name|second pipe]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink with numeric aliases#heading|420|display name",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#heading|420|second pipe]]",
|
|
|
|
name: "wikilink with numeric aliases#heading|420|display name",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#heading|420|second pipe]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "#^blockRef",
|
|
|
|
{
|
|
|
|
in: "[[#^blockRef]]",
|
|
|
|
name: "#^blockRef",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[#^blockRef]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: ""},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: ""},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink#^blockRef",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#^blockRef]]",
|
|
|
|
name: "wikilink#^blockRef",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#^blockRef]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink#^blockRef|display name",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#^blockRef|display name]]",
|
|
|
|
name: "wikilink#^blockRef|display name",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#^blockRef|display name]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink#^blockRef|display name|second pipe",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#^blockRef|display name|second pipe]]",
|
|
|
|
name: "wikilink#^blockRef|display name|second pipe",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#^blockRef|display name|second pipe]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: "wikilink with numeric aliases#^blockRef|420|second pipe",
|
|
|
|
{
|
|
|
|
in: "[[wikilink#^blockRef|420|second pipe]]",
|
|
|
|
name: "wikilink with numeric aliases#^blockRef|420|second pipe",
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
in: "[[wikilink#^blockRef|420|second pipe]]",
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
},
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
for _, tc := range tcs {
|
|
|
|
}
|
|
|
|
tc := tc
|
|
|
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
// t.Parallel()
|
|
|
|
|
|
|
|
l := wikilink.Lex("testLexer", tc.in)
|
|
|
|
|
|
|
|
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.Fail()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, e := range tc.expected {
|
|
|
|
|
|
|
|
n := l.Items[i]
|
|
|
|
|
|
|
|
if e.Typ != n.Typ {
|
|
|
|
|
|
|
|
t.Logf("expected Type %s, received %s", e.Typ.String(), n.Typ.String())
|
|
|
|
|
|
|
|
t.Fail()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if e.Val != n.Val {
|
|
|
|
|
|
|
|
t.Logf("expected Value %q, received %q", e.Val, n.Val)
|
|
|
|
|
|
|
|
t.Fail()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
}
|
|
|
|
mut, test := mutateTestCase(tc,
|
|
|
|
})
|
|
|
|
"this is a ",
|
|
|
|
|
|
|
|
"",
|
|
|
|
|
|
|
|
[]wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: "this is a "},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
"",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
t.Run(mut.name, test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Test_ObsidianWikilinks_Basic(t *testing.T) {
|
|
|
|
func Test_ObsidianWikilinks_Basic(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
// t.Parallel()
|
|
|
|
tcs := []struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
in string
|
|
|
|
|
|
|
|
expected []wikilink.Lexeme
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink",
|
|
|
|
|
|
|
|
in: "[[wikilink]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink|display name",
|
|
|
|
|
|
|
|
in: "[[wikilink|display name]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink|display name|second pipe",
|
|
|
|
|
|
|
|
in: "[[wikilink|display name|second pipe]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink with numeric alias|420|second pipe",
|
|
|
|
|
|
|
|
in: "[[wikilink|420|second pipe]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink with spaces in filename",
|
|
|
|
|
|
|
|
in: "[[wikilink spaces]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink spaces"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "#heading",
|
|
|
|
|
|
|
|
in: "[[#heading]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: ""},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink#heading",
|
|
|
|
|
|
|
|
in: "[[wikilink#heading]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink#heading|display name",
|
|
|
|
|
|
|
|
in: "[[wikilink#heading|display name]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink#heading|display name|second pipe",
|
|
|
|
|
|
|
|
in: "[[wikilink#heading|display name|second pipe]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink with numeric aliases#heading|420|display name",
|
|
|
|
|
|
|
|
in: "[[wikilink#heading|420|second pipe]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexHeading, Val: "#"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "heading"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "#^blockRef",
|
|
|
|
|
|
|
|
in: "[[#^blockRef]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: ""},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink#^blockRef",
|
|
|
|
|
|
|
|
in: "[[wikilink#^blockRef]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink#^blockRef|display name",
|
|
|
|
|
|
|
|
in: "[[wikilink#^blockRef|display name]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink#^blockRef|display name|second pipe",
|
|
|
|
|
|
|
|
in: "[[wikilink#^blockRef|display name|second pipe]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "display name"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wikilink with numeric aliases#^blockRef|420|second pipe",
|
|
|
|
|
|
|
|
in: "[[wikilink#^blockRef|420|second pipe]]",
|
|
|
|
|
|
|
|
expected: []wikilink.Lexeme{
|
|
|
|
|
|
|
|
{Typ: wikilink.LexOpenLink, Val: "[["},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "wikilink"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexBlockRef, Val: "#^"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "blockRef"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "420"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexAlias, Val: "|"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexIdent, Val: "second pipe"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexCloseLink, Val: "]]"},
|
|
|
|
|
|
|
|
{Typ: wikilink.LexText, Val: ""},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, tc := range tcs {
|
|
|
|
for _, tc := range testCases {
|
|
|
|
mut, test := mutateTestCase(tc, "", "")
|
|
|
|
mut, test := mutateTestCase(tc, "", "", nil, nil, "")
|
|
|
|
t.Run(mut.name, test)
|
|
|
|
t.Run(mut.name, test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -468,15 +239,24 @@ type tc struct {
|
|
|
|
expected []wikilink.Lexeme
|
|
|
|
expected []wikilink.Lexeme
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func mutateTestCase(tc tc, prefix, suffix string) (tc, func(t *testing.T)) {
|
|
|
|
func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix []wikilink.Lexeme, name string) (tc, func(t *testing.T)) {
|
|
|
|
|
|
|
|
tc.name = tc.name + "/" + name
|
|
|
|
tc.in = prefix + tc.in
|
|
|
|
tc.in = prefix + tc.in
|
|
|
|
tc.in = tc.in + suffix
|
|
|
|
tc.in = tc.in + suffix
|
|
|
|
|
|
|
|
if expectedPrefix != nil {
|
|
|
|
|
|
|
|
tc.expected = append(expectedPrefix, tc.expected...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if expectedSuffix != nil {
|
|
|
|
|
|
|
|
tc.expected = append(tc.expected, expectedSuffix...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tc, func(t *testing.T) {
|
|
|
|
return tc, func(t *testing.T) {
|
|
|
|
// t.Parallel()
|
|
|
|
// t.Parallel()
|
|
|
|
l := wikilink.Lex("testLexer", tc.in)
|
|
|
|
l := wikilink.Lex("testLexer", tc.in)
|
|
|
|
defer l.L.Sync()
|
|
|
|
defer l.L.Sync()
|
|
|
|
if len(tc.expected) != len(l.Items) {
|
|
|
|
if len(tc.expected) != len(l.Items) {
|
|
|
|
t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items))
|
|
|
|
t.Logf("expected %d tokens, got %d\n", len(tc.expected), len(l.Items))
|
|
|
|
|
|
|
|
t.Logf("raw items: %#v\n", l.Items)
|
|
|
|
t.Fail()
|
|
|
|
t.Fail()
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|