-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
55 lines (50 loc) · 1.26 KB
/
parse_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
package envStore
import (
"bytes"
"testing"
internalTest "github.com/theTardigrade/golang-envStore/internal/test"
)
var testParseLineData = []struct {
line, key, value string
err error
}{
{"x=y", "X", "y", nil},
{"all men=mortal", "ALL MEN", "mortal", nil},
{"socrates=a man", "SOCRATES", "a man", nil},
{"Socrates=mortal", "SOCRATES", "mortal", nil},
{"3=three=tres", "3", "three=tres", nil},
{"2!=3", "2!", "3", nil},
{"shell=/bin/bash", "SHELL", "/bin/bash", nil},
{
"JS_code=((msg) => { console.log(msg); })('test');",
"JS_CODE",
"((msg) => { console.log(msg); })('test');",
nil,
},
{"Oranges=Apples", "ORANGES", "Apples", nil},
{"=LockedOut", "", "", NoKeyParseErr},
{"Nihilist=", "", "", NoValParseErr},
{
func() string {
buffer := bytes.NewBuffer([]byte("test="))
for i, l := 0, MaxLineLen-buffer.Len()+1; i < l; i++ {
buffer.WriteRune(0)
}
return buffer.String()
}(),
"",
"",
MaxLineLenParseErr,
},
}
func TestParseLine(t *testing.T) {
for _, d := range testParseLineData {
key, value, err := parseLine(d.line)
if err != nil {
internalTest.AssertEqual(t, "error", d.err, err)
continue
}
internalTest.AssertEqual(t, "key", d.key, key)
internalTest.AssertEqual(t, "value", d.value, value)
}
}