wiki/util_test.go

53 lines
1.9 KiB
Go
Raw Normal View History

2020-05-16 20:15:36 +00:00
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseLinks(t *testing.T) {
example := "There are three types of notes and these should be kept seperate, because they have different goals. [[Fleeting notes]], [[Permanent notes]], [[Project notes]]."
2020-06-30 22:55:33 +00:00
links, err := ParseLinks("id", example)
2020-05-16 20:15:36 +00:00
if assert.NoError(t, err, "should parse example") {
assert.Len(t, links, 3, "should contain 3 links")
assert.Equal(t, links[0].Line, "There are three types of notes and these should be kept seperate, because they have different goals. [[Fleeting notes]], [[Permanent notes]], [[Project notes]].")
assert.Equal(t, links[0].Name, "Fleeting notes")
assert.Equal(t, links[0].PageName, "Fleeting_notes")
2020-06-30 22:55:33 +00:00
assert.Equal(t, links[0].ID, "id")
2020-05-16 20:15:36 +00:00
assert.Equal(t, links[1].Line, "There are three types of notes and these should be kept seperate, because they have different goals. [[Fleeting notes]], [[Permanent notes]], [[Project notes]].")
assert.Equal(t, links[1].Name, "Permanent notes")
assert.Equal(t, links[1].PageName, "Permanent_notes")
2020-06-30 22:55:33 +00:00
assert.Equal(t, links[1].ID, "id")
2020-05-16 20:15:36 +00:00
assert.Equal(t, links[2].Line, "There are three types of notes and these should be kept seperate, because they have different goals. [[Fleeting notes]], [[Permanent notes]], [[Project notes]].")
assert.Equal(t, links[2].Name, "Project notes")
assert.Equal(t, links[2].PageName, "Project_notes")
2020-06-30 22:55:33 +00:00
assert.Equal(t, links[2].ID, "id")
2020-05-16 20:15:36 +00:00
}
}
func TestTagLinks(t *testing.T) {
example := `
* #[[TODO]] Test1
* #[[TODO]] Test2
* #[[TODO]] Test3
* #[[TODO]] Test4
`
2020-06-30 22:55:33 +00:00
links, err := ParseLinks("id", example)
if assert.NoError(t, err, "should parse example") {
assert.Len(t, links, 4, "should contain 3 links")
assert.Equal(t, links[0].Line, "* #[[TODO]] Test1")
assert.Equal(t, links[0].Name, "TODO")
assert.Equal(t, links[0].PageName, "TODO")
2020-06-30 22:58:07 +00:00
assert.Equal(t, links[0].ID, "id")
}
}