Compare commits
No commits in common. 'main' and 'v0.0.2' have entirely different histories.
@ -1,33 +0,0 @@
|
||||
load("@rules_go//go:def.bzl", "go_library", "go_test")
|
||||
load("@gazelle//:def.bzl", "gazelle")
|
||||
|
||||
gazelle(name = "gazelle")
|
||||
|
||||
go_library(
|
||||
name = "obsidian-markdown",
|
||||
srcs = [
|
||||
"lexemetype_string.go",
|
||||
"lexer.go",
|
||||
"states.go",
|
||||
"wikilink.go",
|
||||
],
|
||||
importpath = "code.ndumas.com/ndumas/obsidian-markdown",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@org_uber_go_zap//:zap",
|
||||
"@org_uber_go_zap//zapcore",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "obsidian-markdown_test",
|
||||
srcs = [
|
||||
"lexer_test.go",
|
||||
"wikilink_test.go",
|
||||
],
|
||||
deps = [
|
||||
":obsidian-markdown",
|
||||
"@com_github_stretchr_testify//assert",
|
||||
"@org_uber_go_zap//zapcore",
|
||||
],
|
||||
)
|
@ -1,12 +0,0 @@
|
||||
module(
|
||||
name = "obsidian-markdown",
|
||||
repo_name = "code.ndumas.com_ndumas_obsidian-markdown",
|
||||
)
|
||||
|
||||
bazel_dep(name = "gazelle", version = "0.32.0")
|
||||
bazel_dep(name = "rules_go", version = "0.41.0")
|
||||
bazel_dep(name = "rules_oci", version = "1.2.0")
|
||||
|
||||
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
|
||||
go_deps.from_file(go_mod = "//:go.mod")
|
||||
use_repo(go_deps, "com_github_stretchr_testify", "org_uber_go_zap")
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +0,0 @@
|
||||
load("@rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "demo_lib",
|
||||
srcs = ["main.go"],
|
||||
importpath = "code.ndumas.com/ndumas/obsidian-markdown/cmd/demo",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//:obsidian-markdown",
|
||||
"@org_uber_go_zap//zapcore",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "demo",
|
||||
embed = [":demo_lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
@ -1,16 +1,10 @@
|
||||
module code.ndumas.com/ndumas/obsidian-markdown
|
||||
module code.ndumas.com/ndumas/wikilink-parser
|
||||
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/stretchr/testify v1.8.0
|
||||
go.uber.org/zap v1.24.0
|
||||
)
|
||||
require go.uber.org/zap v1.24.0
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
@ -1,442 +1,248 @@
|
||||
package markdown_test
|
||||
package wikilink_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"code.ndumas.com/ndumas/obsidian-markdown"
|
||||
"code.ndumas.com/ndumas/wikilink-parser"
|
||||
)
|
||||
|
||||
var wikilinkWithEscapeCharacters = []tc{
|
||||
{
|
||||
name: "wikilink with escaped close link",
|
||||
in: `[[wiki\]\]link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\]\]link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with partial escaped close link",
|
||||
in: `[[wiki\]link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\]link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with escaped open link",
|
||||
in: `[[wiki\[\[link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\[\[link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with partial escaped open link",
|
||||
in: `[[wiki\[link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\[link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with escaped alias",
|
||||
in: `[[wiki\|link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\|link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with escaped blockref",
|
||||
in: `[[wiki\#\^link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\#\^link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with partial escaped blockref",
|
||||
in: `[[wiki\^link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\^link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with escaped header",
|
||||
in: `[[wiki\#link]]`,
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: `wiki\#link`},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var singleWikilink = []tc{
|
||||
{
|
||||
name: "wikilink",
|
||||
in: "[[wikilink]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink|display name",
|
||||
in: "[[wikilink|display name]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "display name"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink|display name|second pipe",
|
||||
in: "[[wikilink|display name|second pipe]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "display name"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "second pipe"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with numeric alias|420|second pipe",
|
||||
in: "[[wikilink|420|second pipe]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "420"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "second pipe"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with spaces in filename",
|
||||
in: "[[wikilink spaces]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink spaces"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "#heading",
|
||||
in: "[[#heading]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: ""},
|
||||
{Typ: markdown.LexHeading, Val: "#"},
|
||||
{Typ: markdown.LexIdent, Val: "heading"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink#heading",
|
||||
in: "[[wikilink#heading]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexHeading, Val: "#"},
|
||||
{Typ: markdown.LexIdent, Val: "heading"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink#heading|display name",
|
||||
in: "[[wikilink#heading|display name]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexHeading, Val: "#"},
|
||||
{Typ: markdown.LexIdent, Val: "heading"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "display name"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink#heading|display name|second pipe",
|
||||
in: "[[wikilink#heading|display name|second pipe]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexHeading, Val: "#"},
|
||||
{Typ: markdown.LexIdent, Val: "heading"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "display name"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "second pipe"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with numeric aliases#heading|420|display name",
|
||||
in: "[[wikilink#heading|420|second pipe]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexHeading, Val: "#"},
|
||||
{Typ: markdown.LexIdent, Val: "heading"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "420"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "second pipe"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "#^blockRef",
|
||||
in: "[[#^blockRef]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: ""},
|
||||
{Typ: markdown.LexBlockRef, Val: "#^"},
|
||||
{Typ: markdown.LexIdent, Val: "blockRef"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink#^blockRef",
|
||||
in: "[[wikilink#^blockRef]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexBlockRef, Val: "#^"},
|
||||
{Typ: markdown.LexIdent, Val: "blockRef"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink#^blockRef|display name",
|
||||
in: "[[wikilink#^blockRef|display name]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexBlockRef, Val: "#^"},
|
||||
{Typ: markdown.LexIdent, Val: "blockRef"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "display name"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink#^blockRef|display name|second pipe",
|
||||
in: "[[wikilink#^blockRef|display name|second pipe]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexBlockRef, Val: "#^"},
|
||||
{Typ: markdown.LexIdent, Val: "blockRef"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "display name"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "second pipe"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wikilink with numeric aliases#^blockRef|420|second pipe",
|
||||
in: "[[wikilink#^blockRef|420|second pipe]]",
|
||||
expected: []markdown.Lexeme{
|
||||
{Typ: markdown.LexOpenLink, Val: "[["},
|
||||
{Typ: markdown.LexIdent, Val: "wikilink"},
|
||||
{Typ: markdown.LexBlockRef, Val: "#^"},
|
||||
{Typ: markdown.LexIdent, Val: "blockRef"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "420"},
|
||||
{Typ: markdown.LexAlias, Val: "|"},
|
||||
{Typ: markdown.LexIdent, Val: "second pipe"},
|
||||
{Typ: markdown.LexCloseLink, Val: "]]"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_TextWithEscapeCharacters(t *testing.T) {
|
||||
for _, tc := range singleWikilink {
|
||||
tc.name = "escape characters preceding " + tc.name
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
`foo\[\[not a link, but this is`,
|
||||
"",
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: `foo\[\[not a link, but this is`},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
|
||||
for _, tc := range singleWikilink {
|
||||
tc.name = "escape characters following " + tc.name
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
"",
|
||||
`foo\[\[not a link, but this is`,
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: `foo\[\[not a link, but this is`},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_EscapeCharacters(t *testing.T) {
|
||||
for _, tc := range wikilinkWithEscapeCharacters {
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
"",
|
||||
"",
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
func Test_ObsidianWikilinks(t *testing.T) {
|
||||
// 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: ""},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_LinksEndOfMultiLineInput(t *testing.T) {
|
||||
for _, tc := range singleWikilink {
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
" test data please ignore.\nbling blonk more lines\nbling blong\nthis is a",
|
||||
"",
|
||||
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: " test data please ignore.\n"},
|
||||
{Typ: markdown.LexText, Val: "bling blonk more lines\n"},
|
||||
{Typ: markdown.LexText, Val: "bling blong\n"},
|
||||
{Typ: markdown.LexText, Val: "this is a"},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_LinksStartOfMultiLineInput(t *testing.T) {
|
||||
for _, tc := range singleWikilink {
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
"",
|
||||
" test data please ignore.\nbling blonk more lines\nbling blong\nthis is a",
|
||||
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: " test data please ignore.\n"},
|
||||
{Typ: markdown.LexText, Val: "bling blonk more lines\n"},
|
||||
{Typ: markdown.LexText, Val: "bling blong\n"},
|
||||
{Typ: markdown.LexText, Val: "this is a"},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_LinksStartOfInput(t *testing.T) {
|
||||
for _, tc := range singleWikilink {
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
"",
|
||||
" test data please ignore",
|
||||
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: " test data please ignore"},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
|
||||
for _, tc := range singleWikilink {
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
"this is a ",
|
||||
"",
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: "this is a "},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ObsidianWikilinks_Basic(t *testing.T) {
|
||||
|
||||
for _, tc := range singleWikilink {
|
||||
mut, test := mutateTestCase(
|
||||
tc,
|
||||
"",
|
||||
"",
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
[]markdown.Lexeme{
|
||||
{Typ: markdown.LexText, Val: ""},
|
||||
},
|
||||
)
|
||||
t.Run(mut.name, test)
|
||||
}
|
||||
}
|
||||
|
||||
type tc struct {
|
||||
name string
|
||||
in string
|
||||
expected []markdown.Lexeme
|
||||
}
|
||||
|
||||
func mutateTestCase(tc tc, prefix, suffix string, expectedPrefix, expectedSuffix []markdown.Lexeme) (tc, func(t *testing.T)) {
|
||||
tc.in = prefix + tc.in
|
||||
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) {
|
||||
l := markdown.Lex("testLexer", tc.in, zapcore.WarnLevel)
|
||||
defer l.L.Sync()
|
||||
assert.Equal(t, tc.expected, l.Items, "token stream mismatch")
|
||||
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
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,275 @@
|
||||
mkdir -p "/home/ndumas/work/wikilink-parser/reports"
|
||||
mkdir -p "/home/ndumas/work/wikilink-parser/dist"
|
||||
go clean code.ndumas.com/ndumas/wikilink-parser
|
||||
rm -vrf "/home/ndumas/work/wikilink-parser/dist"/*
|
||||
rm -vf "/home/ndumas/work/wikilink-parser/reports"/*
|
||||
removed '/home/ndumas/work/wikilink-parser/reports/test.out'
|
||||
go get -d -t code.ndumas.com/ndumas/wikilink-parser/...
|
||||
go install golang.org/x/tools/cmd/stringer@latest
|
||||
go generate
|
||||
go test -race -v -tags "release" $(go list "code.ndumas.com/ndumas/wikilink-parser/..." | grep -v /vendor/) | tee "/home/ndumas/work/wikilink-parser/reports/test.out"
|
||||
=== RUN Test_Lexer
|
||||
=== RUN Test_Lexer/wikilink
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":10,"width":1,"item":"ItemIdent:\"wikilink\""}
|
||||
2023/07/01 18:25:42 lexCloseLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":12,"width":1,"item":"ItemCloseLink:\"]]\""}
|
||||
=== RUN Test_Lexer/wikilink|display_name
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":12,"width":0,"item":"ItemText:\"\""}
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":10,"width":1,"item":"ItemIdent:\"wikilink\""}
|
||||
2023/07/01 18:25:42 lexAlias
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":11,"width":1,"item":"ItemAlias:\"|\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":23,"width":1,"item":"ItemIdent:\"display name\""}
|
||||
2023/07/01 18:25:42 lexCloseLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":25,"width":1,"item":"ItemCloseLink:\"]]\""}
|
||||
=== RUN Test_Lexer/wikilink|display_name|second_pipe
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":10,"width":1,"item":"ItemIdent:\"wikilink\""}
|
||||
2023/07/01 18:25:42 lexAlias
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":11,"width":1,"item":"ItemAlias:\"|\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":23,"width":1,"item":"ItemIdent:\"display name\""}
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":25,"width":0,"item":"ItemText:\"\""}
|
||||
2023/07/01 18:25:42 lexAlias
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":24,"width":1,"item":"ItemAlias:\"|\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":35,"width":1,"item":"ItemIdent:\"second pipe\""}
|
||||
2023/07/01 18:25:42 lexCloseLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":37,"width":1,"item":"ItemCloseLink:\"]]\""}
|
||||
=== RUN Test_Lexer/wikilink_with_numeric_alias|420|second_pipe
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":10,"width":1,"item":"ItemIdent:\"wikilink\""}
|
||||
2023/07/01 18:25:42 lexAlias
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":11,"width":1,"item":"ItemAlias:\"|\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":14,"width":1,"item":"ItemIdent:\"420\""}
|
||||
2023/07/01 18:25:42 lexAlias
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":15,"width":1,"item":"ItemAlias:\"|\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":26,"width":1,"item":"ItemIdent:\"second pipe\""}
|
||||
2023/07/01 18:25:42 lexCloseLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":28,"width":1,"item":"ItemCloseLink:\"]]\""}
|
||||
=== RUN Test_Lexer/wikilink_with_spaces_in_filename
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":17,"width":1,"item":"ItemIdent:\"wikilink spaces\""}
|
||||
2023/07/01 18:25:42 lexCloseLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":19,"width":1,"item":"ItemCloseLink:\"]]\""}
|
||||
=== RUN Test_Lexer/#heading
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":10,"width":1,"item":"ItemIdent:\"#heading\""}
|
||||
lexer_test.go:100: expected Type ItemHeading, received ItemIdent
|
||||
lexer_test.go:105: expected Value "#", received "#heading"
|
||||
2023/07/01 18:25:42 lexCloseLink
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":12,"width":1,"item":"ItemCloseLink:\"]]\""}
|
||||
lexer_test.go:100: expected Type ItemIdent, received ItemCloseLink
|
||||
lexer_test.go:105: expected Value "heading", received "]]"
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":12,"width":0,"item":"ItemText:\"\""}
|
||||
lexer_test.go:100: expected Type ItemCloseLink, received ItemText
|
||||
lexer_test.go:105: expected Value "]]", received ""
|
||||
=== RUN Test_Lexer/wikilink#heading
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":37,"width":0,"item":"ItemText:\"\""}
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":28,"width":0,"item":"ItemText:\"\""}
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":19,"width":0,"item":"ItemText:\"\""}
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":12,"width":0,"item":"ItemText:\"\""}
|
||||
2023/07/01 18:25:42 lexText
|
||||
2023/07/01 18:25:42 lexOpenLink
|
||||
2023/07/01 18:25:42 lexText
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":2,"width":0,"item":"ItemOpenLink:\"[[\""}
|
||||
2023/07/01 18:25:42 lexIdent
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":10,"width":1,"item":"ItemIdent:\"wikilink\""}
|
||||
==================
|
||||
WARNING: DATA RACE
|
||||
Read at 0x00c0000822b0 by goroutine 21:
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexText()
|
||||
/home/ndumas/work/wikilink-parser/states.go:82 +0x69
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).run()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:149 +0x3a
|
||||
code.ndumas.com/ndumas/wikilink-parser.Lex.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:45 +0x39
|
||||
|
||||
Previous write at 0x00c0000822b0 by goroutine 20:
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexOpenLink()
|
||||
/home/ndumas/work/wikilink-parser/states.go:96 +0x86
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).NextItem()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:64 +0xd5
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:98 +0x18c
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
|
||||
Goroutine 21 (running) created at:
|
||||
code.ndumas.com/ndumas/wikilink-parser.Lex()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:45 +0x41a
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:95 +0x69
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
|
||||
Goroutine 20 (running) created at:
|
||||
testing.(*T).Run()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x75d
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:93 +0x1086
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
==================
|
||||
==================
|
||||
WARNING: DATA RACE
|
||||
Write at 0x00c0000822b8 by goroutine 21:
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).next()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:142 +0xe8
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexText()
|
||||
/home/ndumas/work/wikilink-parser/states.go:85 +0xc4
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).run()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:149 +0x3a
|
||||
code.ndumas.com/ndumas/wikilink-parser.Lex.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:45 +0x39
|
||||
|
||||
Previous write at 0x00c0000822b8 by goroutine 20:
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).next()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:142 +0xe8
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexIdent()
|
||||
/home/ndumas/work/wikilink-parser/states.go:31 +0x64
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).NextItem()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:64 +0xd5
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:98 +0x18c
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
|
||||
Goroutine 21 (running) created at:
|
||||
code.ndumas.com/ndumas/wikilink-parser.Lex()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:45 +0x41a
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:95 +0x69
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
|
||||
Goroutine 20 (running) created at:
|
||||
testing.(*T).Run()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x75d
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:93 +0x1086
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
==================
|
||||
==================
|
||||
WARNING: DATA RACE
|
||||
Read at 0x00c0000822a8 by goroutine 21:
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).emit()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:109 +0x64
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexText()
|
||||
/home/ndumas/work/wikilink-parser/states.go:88 +0xf4
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).run()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:149 +0x3a
|
||||
code.ndumas.com/ndumas/wikilink-parser.Lex.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:45 +0x39
|
||||
|
||||
Previous write at 0x00c0000822a8 by goroutine 20:
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).emit()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:119 +0x4cf
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexOpenLink()
|
||||
/home/ndumas/work/wikilink-parser/states.go:97 +0xa4
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).NextItem()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:64 +0xd5
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:98 +0x18c
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
|
||||
Goroutine 21 (running) created at:
|
||||
code.ndumas.com/ndumas/wikilink-parser.Lex()
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:45 +0x41a
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:95 +0x69
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
|
||||
Goroutine 20 (running) created at:
|
||||
testing.(*T).Run()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x75d
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer()
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:93 +0x1086
|
||||
testing.tRunner()
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x216
|
||||
testing.(*T).Run.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x47
|
||||
==================
|
||||
2023/07/01 18:25:42 lexHeading
|
||||
{"level":"debug","logger":"lexer.emit","msg":"emitting item","pos":20,"width":0,"item":"ItemText:\"wikilink#heading]]\""}
|
||||
testing.go:1319: race detected during execution of test
|
||||
--- FAIL: Test_Lexer (0.01s)
|
||||
--- PASS: Test_Lexer/wikilink (0.00s)
|
||||
--- PASS: Test_Lexer/wikilink|display_name (0.00s)
|
||||
--- PASS: Test_Lexer/wikilink|display_name|second_pipe (0.00s)
|
||||
--- PASS: Test_Lexer/wikilink_with_numeric_alias|420|second_pipe (0.00s)
|
||||
--- PASS: Test_Lexer/wikilink_with_spaces_in_filename (0.00s)
|
||||
--- FAIL: Test_Lexer/#heading (0.00s)
|
||||
--- FAIL: Test_Lexer/wikilink#heading (0.00s)
|
||||
panic: runtime error: slice bounds out of range [:21] with length 20 [recovered]
|
||||
panic: runtime error: slice bounds out of range [:21] with length 20
|
||||
|
||||
goroutine 34 [running]:
|
||||
testing.tRunner.func1.2({0x6e8160, 0xc0000e20a8})
|
||||
/usr/lib/golang/src/testing/testing.go:1396 +0x372
|
||||
testing.tRunner.func1()
|
||||
/usr/lib/golang/src/testing/testing.go:1399 +0x5f0
|
||||
panic({0x6e8160, 0xc0000e20a8})
|
||||
/usr/lib/golang/src/runtime/panic.go:890 +0x262
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).emit(0xc000082280, 0x5)
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:109 +0x506
|
||||
code.ndumas.com/ndumas/wikilink-parser.lexHeading(0xc000082280)
|
||||
/home/ndumas/work/wikilink-parser/states.go:58 +0xa5
|
||||
code.ndumas.com/ndumas/wikilink-parser.(*Lexer).NextItem(0xc000082280)
|
||||
/home/ndumas/work/wikilink-parser/lexer.go:64 +0xd6
|
||||
code.ndumas.com/ndumas/wikilink-parser_test.Test_Lexer.func1(0xc000190b60)
|
||||
/home/ndumas/work/wikilink-parser/lexer_test.go:98 +0x18d
|
||||
testing.tRunner(0xc000190b60, 0xc00019cb40)
|
||||
/usr/lib/golang/src/testing/testing.go:1446 +0x217
|
||||
created by testing.(*T).Run
|
||||
/usr/lib/golang/src/testing/testing.go:1493 +0x75e
|
||||
FAIL code.ndumas.com/ndumas/wikilink-parser 0.024s
|
||||
FAIL
|
Loading…
Reference in New Issue