-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_test.go
88 lines (71 loc) · 1.98 KB
/
split_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
package timecat
import (
"testing"
)
func TestSplitWithEmptyFile(t *testing.T) {
var testFile = ``
oldReadFile := mockReadFile(func(f string) (string, error) {
return testFile, nil
})
defer func() { readFile = oldReadFile }()
// when split is run with a completely empty file
// the resulting array of files to write should be empty
result := Split("testfile", "testdir")
if len(result) != 0 {
t.Fatal("there was more or less than one heading")
}
}
func TestSplitWithNoHeadings(t *testing.T) {
var testFile = `asuh
ok
asdf
asdf
`
oldReadFile := mockReadFile(func(f string) (string, error) {
return testFile, nil
})
defer func() { readFile = oldReadFile }()
// when split is run with a file that doens't have a single heading
// the resulting array of files to write should be empty
result := Split("testfile", "testdir")
if len(result) > 0 {
t.Fatal("there were headings when there should be none")
}
}
func TestSplitWithOneHeading(t *testing.T) {
var testFile = `asuh
ok
asdf
asdf
` + plainTextHeading + ` testfile1.md
testtext1
testtext2
testtext3
`
oldReadFile := mockReadFile(func(f string) (string, error) {
return testFile, nil
})
defer func() { readFile = oldReadFile }()
oldNowISODate := mockNowISODate("test-prefix")
defer func() { nowISODate = oldNowISODate }()
result := Split("testfile.md", "testdir")
// when split has some text before a single heading
// the resulting array has a single result
if len(result) != 1 {
t.Fatal("there was more or less than one heading")
}
contentWant :=
`testtext1
testtext2
testtext3
`
// and that results contents does not contain any of the previous text
if result[0].Content != contentWant {
t.Fatalf("content was not correct: want: %s, got: %s", contentWant, result[0].Content)
}
nameWant := "test-prefix-testfile1.md"
// and that results name matches what we see from the heading itself
if result[0].Name != nameWant {
t.Fatalf("name was not correct: want: %s, got: %s", nameWant, result[0].Name)
}
}