diff options
| author | ewy <ewy0@protonmail.com> | 2026-04-22 19:27:25 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-04-22 19:27:25 +0200 |
| commit | 098cae128b18418b0e6be87af5bf29ce2aae39a1 (patch) | |
| tree | dce7a55ac44296d5803a3d74e0076672bbcd7b33 /cache/cache_test.go | |
| parent | f13b2bcf9a3a5ea6afeaa60c7a2e801e8e79a2c1 (diff) | |
update script experiment
Diffstat (limited to 'cache/cache_test.go')
| -rw-r--r-- | cache/cache_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cache/cache_test.go b/cache/cache_test.go index 499c0f5..38c100a 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -1,11 +1,37 @@ +//go:build test + package cache import ( "github.com/stretchr/testify/assert" + . "pik/testx" "strings" "testing" + "testing/fstest" ) +func TestLoadFile(t *testing.T) { + input := ` + +# comment +/asdf/hjkl # label + +# other comment +//comment + +` + f := fstest.MapFS{ + "contexts": &fstest.MapFile{ + Data: []byte(input), + }, + } + res, err := LoadFile(f, "contexts") + assert.NoError(t, err) + assert.Len(t, res.Entries, 1) + assert.Equal(t, res.Entries[0].Path, "/asdf/hjkl") + assert.Equal(t, res.Entries[0].Label, "label") +} + func TestFromReader_Blank(t *testing.T) { input := ` ` @@ -113,3 +139,29 @@ func TestMerge(t *testing.T) { assert.Len(t, result.Entries, 3) assert.Contains(t, result.Entries, a, b, c) } + +func TestCache_String(t *testing.T) { + c := Cache{Entries: []Entry{{Path: "/asdf/hjkl", Label: "hjkl"}}} + output := c.String() + for _, e := range c.Entries { + assert.Contains(t, output, e.Path) + assert.Contains(t, output, e.Label) + } +} + +func TestNew(t *testing.T) { + st := TState(TSource("/test/location", "target1", "target2"), TSource("/other/place/asdf/hjkl", "1target", "2target")) + c := New(st) + assert.NotNil(t, c) + assert.Len(t, c.Entries, 2) + assert.Equal(t, "/test/location", c.Entries[0].Path) + assert.Equal(t, "/other/place/asdf/hjkl", c.Entries[1].Path) +} + +func TestLoadFile_NotExist(t *testing.T) { + f := fstest.MapFS{} + c, err := LoadFile(f, "anything is fine") + assert.Nil(t, c.Entries) + assert.Error(t, err) + +} |
