File: path_test.go

package info (click to toggle)
snowflake 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 968 kB
  • sloc: makefile: 5
file content (54 lines) | stat: -rw-r--r-- 1,299 bytes parent folder | download
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
package amp

import (
	"testing"
)

func TestDecodePath(t *testing.T) {
	for _, test := range []struct {
		path           string
		expectedData   string
		expectedErrStr string
	}{
		{"", "", "missing format indicator"},
		{"0", "", "missing data"},
		{"0foobar", "", "missing data"},
		{"/0/YWJj", "", "unknown format indicator '/'"},

		{"0/", "", ""},
		{"0foobar/", "", ""},
		{"0/YWJj", "abc", ""},
		{"0///YWJj", "abc", ""},
		{"0foobar/YWJj", "abc", ""},
		{"0/foobar/YWJj", "abc", ""},
	} {
		data, err := DecodePath(test.path)
		if test.expectedErrStr != "" {
			if err == nil || err.Error() != test.expectedErrStr {
				t.Errorf("%+q expected error %+q, got %+q",
					test.path, test.expectedErrStr, err)
			}
		} else if err != nil {
			t.Errorf("%+q expected no error, got %+q", test.path, err)
		} else if string(data) != test.expectedData {
			t.Errorf("%+q expected data %+q, got %+q",
				test.path, test.expectedData, data)
		}
	}
}

func TestPathRoundTrip(t *testing.T) {
	for _, data := range []string{
		"",
		"\x00",
		"/",
		"hello world",
	} {
		decoded, err := DecodePath(EncodePath([]byte(data)))
		if err != nil {
			t.Errorf("%+q roundtripped with error %v", data, err)
		} else if string(decoded) != data {
			t.Errorf("%+q roundtripped to %+q", data, decoded)
		}
	}
}