From dd84b9d64fb98746a230cd24233ff50a562c39c9 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 28 Apr 2023 01:36:44 +0800 Subject: --- cli/internal/lockfile/yarn_lockfile_test.go | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cli/internal/lockfile/yarn_lockfile_test.go (limited to 'cli/internal/lockfile/yarn_lockfile_test.go') diff --git a/cli/internal/lockfile/yarn_lockfile_test.go b/cli/internal/lockfile/yarn_lockfile_test.go new file mode 100644 index 0000000..ef4fcb0 --- /dev/null +++ b/cli/internal/lockfile/yarn_lockfile_test.go @@ -0,0 +1,51 @@ +package lockfile + +import ( + "bytes" + "testing" + + "gotest.tools/v3/assert" +) + +func TestRoundtrip(t *testing.T) { + content, err := getFixture(t, "yarn.lock") + if err != nil { + t.Error(err) + } + + lockfile, err := DecodeYarnLockfile(content) + if err != nil { + t.Error(err) + } + + var b bytes.Buffer + if err := lockfile.Encode(&b); err != nil { + t.Error(err) + } + + assert.DeepEqual(t, string(content), b.String()) +} + +func TestKeySplitting(t *testing.T) { + content, err := getFixture(t, "yarn.lock") + if err != nil { + t.Error(err) + } + + lockfile, err := DecodeYarnLockfile(content) + if err != nil { + t.Error(err) + } + + // @babel/types has multiple entries, these should all appear in the lockfile struct + keys := []string{ + "@babel/types@^7.18.10", + "@babel/types@^7.18.6", + "@babel/types@^7.19.0", + } + + for _, key := range keys { + _, ok := lockfile.inner[key] + assert.Assert(t, ok, "Unable to find entry for %s in parsed lockfile", key) + } +} -- cgit v1.2.3-70-g09d2