aboutsummaryrefslogtreecommitdiff
path: root/snap/parsing_test.go
blob: 1a87723d27f4c330ba67d254f66353c1ef8e2081 (plain)
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
package snap

import "testing"

func TestRelativeParsing(t * testing.T) {
	cases := []struct {
		snapish string
		snapshot string
		offset int
	} {
		{"snapshot", "snapshot", 0},
		{"testing--", "testing", -2},
		{"%SNAPSHOT%^+++", "%SNAPSHOT%^", 3},
		{"--prefixed", "--prefixed", 0},
		{"+++", "", 3},
		{"---", "", -3},
		{"+5", "", 5},
		{"-3", "", -3},
		{"+", "", 1},
		{"-", "", -1},
		{`"-"`, "-", 0},
	}

	for _, c := range cases {
		got := ToRelative(c.snapish)

		if got.offset != c.offset || got.snapshot != c.snapshot {
			t.Errorf("ToRelative(%s) == %+v, wanted %+v", c.snapish, got, c)
		}
	}
}