wiki/util_test.go

49 lines
1.7 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]]."
links, err := ParseLinks(example)
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")
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")
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")
}
}
func TestTagLinks(t *testing.T) {
example := `
* #[[TODO]] Test1
* #[[TODO]] Test2
* #[[TODO]] Test3
* #[[TODO]] Test4
`
links, err := ParseLinks(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")
}
}