wiki/util_test.go
Peter Stuifzand 7f521bcde5
All checks were successful
continuous-integration/drone/push Build is passing
Add copyright comments
2021-08-07 19:13:10 +02:00

71 lines
2.6 KiB
Go

/*
* 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/>.
*/
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("id", 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[0].ID, "id")
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[1].ID, "id")
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")
assert.Equal(t, links[2].ID, "id")
}
}
func TestTagLinks(t *testing.T) {
example := `
* #[[TODO]] Test1
* #[[TODO]] Test2
* #[[TODO]] Test3
* #[[TODO]] Test4
`
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")
assert.Equal(t, links[0].ID, "id")
}
}