aboutsummaryrefslogtreecommitdiff
path: root/src/internal/pkgbits/pkgbits_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/pkgbits/pkgbits_test.go')
-rw-r--r--src/internal/pkgbits/pkgbits_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/internal/pkgbits/pkgbits_test.go b/src/internal/pkgbits/pkgbits_test.go
new file mode 100644
index 0000000000..a5f93c7e8e
--- /dev/null
+++ b/src/internal/pkgbits/pkgbits_test.go
@@ -0,0 +1,67 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package pkgbits_test
+
+import (
+ "internal/pkgbits"
+ "strings"
+ "testing"
+)
+
+func TestRoundTrip(t *testing.T) {
+ pw := pkgbits.NewPkgEncoder(-1)
+ w := pw.NewEncoder(pkgbits.RelocMeta, pkgbits.SyncPublic)
+ w.Flush()
+
+ var b strings.Builder
+ _ = pw.DumpTo(&b)
+ input := b.String()
+
+ pr := pkgbits.NewPkgDecoder("package_id", input)
+ r := pr.NewDecoder(pkgbits.RelocMeta, pkgbits.PublicRootIdx, pkgbits.SyncPublic)
+
+ if r.Version() != w.Version() {
+ t.Errorf("Expected reader version %q to be the writer version %q", r.Version(), w.Version())
+ }
+}
+
+// Type checker to enforce that know V* have the constant values they must have.
+var _ [0]bool = [pkgbits.V0]bool{}
+var _ [1]bool = [pkgbits.V1]bool{}
+
+func TestVersions(t *testing.T) {
+ type vfpair struct {
+ v pkgbits.Version
+ f pkgbits.Field
+ }
+
+ // has field tests
+ for _, c := range []vfpair{
+ {pkgbits.V1, pkgbits.Flags},
+ {pkgbits.V2, pkgbits.Flags},
+ {pkgbits.V0, pkgbits.HasInit},
+ {pkgbits.V1, pkgbits.HasInit},
+ {pkgbits.V0, pkgbits.DerivedFuncInstance},
+ {pkgbits.V1, pkgbits.DerivedFuncInstance},
+ {pkgbits.V2, pkgbits.AliasTypeParamNames},
+ } {
+ if !c.v.Has(c.f) {
+ t.Errorf("Expected version %v to have field %v", c.v, c.f)
+ }
+ }
+
+ // does not have field tests
+ for _, c := range []vfpair{
+ {pkgbits.V0, pkgbits.Flags},
+ {pkgbits.V2, pkgbits.HasInit},
+ {pkgbits.V2, pkgbits.DerivedFuncInstance},
+ {pkgbits.V0, pkgbits.AliasTypeParamNames},
+ {pkgbits.V1, pkgbits.AliasTypeParamNames},
+ } {
+ if c.v.Has(c.f) {
+ t.Errorf("Expected version %v to not have field %v", c.v, c.f)
+ }
+ }
+}