From fb8aee6c5147b8751a3920f613934d90b79ef4c5 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Wed, 21 Jul 2021 23:00:00 -0500 Subject: Added parser for +- syntax for relative references to snapshots --- snap/parsing_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 snap/parsing_test.go (limited to 'snap/parsing_test.go') diff --git a/snap/parsing_test.go b/snap/parsing_test.go new file mode 100644 index 0000000..1a87723 --- /dev/null +++ b/snap/parsing_test.go @@ -0,0 +1,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) + } + } +} \ No newline at end of file -- cgit v1.2.3