-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
93 lines (85 loc) · 1.51 KB
/
parser_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
package chomp_test
import (
"testing"
"github.com/purpleclay/chomp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCrlf(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
rem string
ext string
}{
{
name: "LF",
input: "\nHello",
rem: "Hello",
ext: "\n",
},
{
name: "CRLF",
input: "\r\nこんにちは",
rem: "こんにちは",
ext: "\r\n",
},
{
name: "LFOnly",
input: "\n",
rem: "",
ext: "\n",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
rem, ext, err := chomp.Crlf()(tt.input)
require.NoError(t, err)
assert.Equal(t, tt.rem, rem)
assert.Equal(t, tt.ext, ext)
})
}
}
func TestEol(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
rem string
ext string
}{
{
name: "LF",
input: `Hello, World!
It's a great day`,
rem: "It's a great day",
ext: "Hello, World!",
},
{
name: "NoLF",
input: "こんにちは、おはよう",
rem: "",
ext: "こんにちは、おはよう",
},
{
name: "EmptyLineBeforeLF",
input: `
こんにちは、おはよう`,
rem: "こんにちは、おはよう",
ext: "",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
rem, ext, err := chomp.Eol()(tt.input)
require.NoError(t, err)
assert.Equal(t, tt.rem, rem)
assert.Equal(t, tt.ext, ext)
})
}
}