-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitter_test.go
60 lines (55 loc) · 1.62 KB
/
splitter_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
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2022 jonow //
// //
// Use of this source code is governed by an MIT-style license that can be //
// found in the LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
package lsv
import (
"reflect"
"testing"
)
// Tests that SplitParams returns the expected error or value for each test.
func TestSplitParams(t *testing.T) {
newParameters := func(tt readTest) Parameters {
p := DefaultParameters()
if tt.Comment != 0 {
p.Comment = tt.Comment
}
if tt.Raw != 0 {
p.Raw = tt.Raw
}
if tt.Escape != 0 {
p.Escape = tt.Escape
}
if tt.NoTrim {
p.TrimLeadingSpace = false
}
return p
}
for _, tt := range readTests {
t.Run(tt.Name, func(t *testing.T) {
p := newParameters(tt)
out, err := SplitParams(tt.Input, p)
if tt.Error != nil {
if !reflect.DeepEqual(err, tt.Error) {
t.Fatalf("SplitParams() error mismatch:"+
"\nexpected: %v (%#v)\nreceived: %v (%#v)",
tt.Error, tt.Error, err, err)
}
if out != nil {
t.Fatalf("SplitParams() unexpected output:"+
"\nexpected: nil\nreceived: %q", out)
}
} else {
if err != nil {
t.Fatalf("Unexpected SplitParams() error: %+v", err)
}
if !reflect.DeepEqual(out, tt.Output) {
t.Fatalf("SplitParams() unexpected output:"+
"\nexpected: %q\nreceived: %q", tt.Output, out)
}
}
})
}
}