aboutsummaryrefslogtreecommitdiffstats
path: root/common/infostring/infostring_test.go
blob: 977090d3ff3511fb9261445d8868c771379fa687 (plain) (blame)
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
package infostring

import (
	"reflect"
	"testing"
)

type infoStringTest struct {
	name     string
	input    string
	expected InfoString
}

var infoStringTests = []infoStringTest{
	{
		name:  "foo",
		input: "\"\\FOO\\foo\\BAR\\bar\\BAZ\\baz\"",
		expected: InfoString{
			Info: []Info{
				Info{Key: "FOO", Value: "foo"},
				Info{Key: "BAR", Value: "bar"},
				Info{Key: "BAZ", Value: "baz"},
			},
		},
	},
	{
		name:  "\\foo\\with spaces",
		input: "\"\\foo\\with spaces\"",
		expected: InfoString{
			Info: []Info{
				Info{Key: "foo", Value: "with spaces"},
			},
		},
	},
}

func TestInfoString(t *testing.T) {
	for _, is := range infoStringTests {
		t.Run(is.name, func(t *testing.T) {
			infoString := Parse(is.input)

			if !reflect.DeepEqual(is.expected.Bytes(), infoString.Bytes()) {
				t.Errorf("parsed infostring output didn't match")
				t.Logf("output: %#v\n", infoString)
				t.Logf("expected: %#v\n", is.expected)
			}
		})
	}
}