-
Notifications
You must be signed in to change notification settings - Fork 10
/
note_internal_test.go
105 lines (92 loc) · 2.21 KB
/
note_internal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* 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 2 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/>.
*
* Copyright (C) Joakim Kennedy, 2018
*/
package clinote
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNoteParsing(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
content []byte
}{
{"simple", []byte(testContent)},
{"compact", []byte(compactContent)},
{"with_white_space", []byte(contentWithWhiteSpace)},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
n := new(Note)
r := bytes.NewReader(test.content)
err := parseNote(r, n, DefaultNoteOption)
assert.NoError(err, "Should not return an error")
assert.Equal(noteTitle, n.Title, "Wrong title parsed")
assert.Equal(noteContent, n.MD, "Wrong content parsed")
assert.Equal(notebookName, n.Notebook.Name, "Wrong notebook parsed")
})
}
}
func TestNoteWriting(t *testing.T) {
assert := assert.New(t)
n := &Note{
Title: noteTitle,
MD: noteContent,
Notebook: &Notebook{
Name: notebookName,
GUID: notebookGUID,
},
}
w := new(bytes.Buffer)
err := WriteNote(w, n, DefaultNoteOption)
assert.NoError(err, "Should not fail")
assert.Equal(testContent, string(w.Bytes()), "Wrong content written")
}
const (
noteTitle = "Note title"
noteContent = "Body\nof\nthe\nnote"
notebookGUID = "Notebook GUID"
notebookName = "Notebook name"
)
const testContent = `---
title: Note title
notebook: Notebook name
---
Body
of
the
note
`
const compactContent = `---
title:Note title
notebook: Notebook name
---
Body
of
the
note
`
const contentWithWhiteSpace = `---
title: Note title
notebook: Notebook name
---
Body
of
the
note
`