From 45a297a8e526094e8fce6e2c5c0fd89b381d1765 Mon Sep 17 00:00:00 2001 From: ewy Date: Tue, 14 Apr 2026 16:37:17 +0200 Subject: i have to commit at some point! --- cache/cache_test.go | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 cache/cache_test.go (limited to 'cache/cache_test.go') diff --git a/cache/cache_test.go b/cache/cache_test.go new file mode 100644 index 0000000..fa81974 --- /dev/null +++ b/cache/cache_test.go @@ -0,0 +1,79 @@ +package cache + +import ( + "github.com/stretchr/testify/assert" + "strings" + "testing" +) + +func TestFromReader_Blank(t *testing.T) { + input := ` +` + sr := strings.NewReader(input) + c, err := FromReader(sr) + assert.Nil(t, err) + assert.Len(t, c.Entries, 0) +} + +func TestFromReader_OneEntry(t *testing.T) { + input := `/abc/def # deffers` + sr := strings.NewReader(input) + c, err := FromReader(sr) + assert.Nil(t, err) + assert.Len(t, c.Entries, 1) + assert.Equal(t, c.Entries[0], Entry{ + Path: "/abc/def", + Label: "deffers", + }) +} + +func TestFromReader_ManyEntries(t *testing.T) { + input := `/abc/def # deffers +/123/aa # i love aa +/path/src # da source +` + sr := strings.NewReader(input) + c, err := FromReader(sr) + assert.Nil(t, err) + assert.Len(t, c.Entries, 3) + assert.Equal(t, c.Entries[0], Entry{ + Path: "/abc/def", + Label: "deffers", + }) + assert.Equal(t, c.Entries[1], Entry{ + Path: "/123/aa", + Label: "i love aa", + }) + assert.Equal(t, c.Entries[2], Entry{ + Path: "/path/src", + Label: "da source", + }) +} + +func TestFromReader_Comments(t *testing.T) { + input := ` +// comment +/abc/def # deffers +# comment +/123/aa # i love aa +// # comment +/path/src # da source +# // comment +` + sr := strings.NewReader(input) + c, err := FromReader(sr) + assert.Nil(t, err) + assert.Len(t, c.Entries, 3) + assert.Equal(t, c.Entries[0], Entry{ + Path: "/abc/def", + Label: "deffers", + }) + assert.Equal(t, c.Entries[1], Entry{ + Path: "/123/aa", + Label: "i love aa", + }) + assert.Equal(t, c.Entries[2], Entry{ + Path: "/path/src", + Label: "da source", + }) +} -- cgit v1.3