aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/index/index_test.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-08-05 12:03:32 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-08-05 12:03:32 -0400
commit62aeb1a0fb0a239f6193b7cb872787578480082c (patch)
tree889b9e3c3f27cbac2be335e30076a51fb548334a /pkg/index/index_test.go
parentf14c466d5d5d1f1a68153162349a74a154bcb535 (diff)
Add header parsing and improved link parsing
Diffstat (limited to 'pkg/index/index_test.go')
-rw-r--r--pkg/index/index_test.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/pkg/index/index_test.go b/pkg/index/index_test.go
index 4242ce1..d3ca72c 100644
--- a/pkg/index/index_test.go
+++ b/pkg/index/index_test.go
@@ -264,6 +264,7 @@ func TestIndex_ParseOne(t *testing.T) {
In this sentence there is a valid [hyperlink](https://jpappel.xyz).
But in this sentence, the [link]() should not get parsed.
The same is true for the [link]( ) in this sentence.
+ There must be a nonwhitespace characters for a link to be a [valid link]( destination )
`)
return path
@@ -271,7 +272,51 @@ func TestIndex_ParseOne(t *testing.T) {
index.ParseOpts{ParseLinks: true},
&index.Document{
Title: "Link test",
- Links: []string{"https://jpappel.xyz"},
+ Links: []string{"https://jpappel.xyz", "destination"},
+ },
+ nil,
+ },
+ {
+ "headings",
+ func(t *testing.T) string {
+ f, path := newTestFile(t, "headings")
+ defer f.Close()
+
+ f.WriteString("---\n")
+ f.WriteString("title: Heading test\n")
+ f.WriteString("---\n")
+ f.WriteString("# A Heading\n")
+ f.WriteString("##Another Heading\n")
+ f.WriteString("### [Linked Heading](but no link parse)\n")
+ return path
+ },
+ index.ParseOpts{ParseHeadings: true},
+ &index.Document{
+ Title: "Heading test",
+ Headings: "# A Heading\n##Another Heading\n### [Linked Heading]\n",
+ },
+ nil,
+ },
+ {
+ "linked_headings",
+ func(t *testing.T) string {
+ f, path := newTestFile(t, "linked_headings")
+ defer f.Close()
+
+ f.WriteString("---\n")
+ f.WriteString("title: Linked Heading Test\n")
+ f.WriteString("---\n")
+
+ f.WriteString("#[Top Level Heading](and its link)\n")
+ f.WriteString("## [Second Level heading]( sometext )\n")
+
+ return path
+ },
+ index.ParseOpts{ParseLinks: true, ParseHeadings: true},
+ &index.Document{
+ Title: "Linked Heading Test",
+ Headings: "#[Top Level Heading]\n## [Second Level heading]\n",
+ Links: []string{"and its link", "sometext"},
},
nil,
},