wiki/util_test.go

71 lines
2.6 KiB
Go
Raw Normal View History

2021-08-07 17:13:10 +00:00
/*
* Wiki - A wiki with editor
* Copyright (c) 2021 Peter Stuifzand
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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")
}
}