/* * 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 . */ 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") } }