github.com/ipld/go-ipld-prime@v0.21.0/node/basicnode/int_test.go (about) 1 package basicnode_test 2 3 import ( 4 "testing" 5 6 qt "github.com/frankban/quicktest" 7 "github.com/ipld/go-ipld-prime/must" 8 "github.com/ipld/go-ipld-prime/node/basicnode" 9 ) 10 11 func TestBasicInt(t *testing.T) { 12 m := basicnode.NewInt(3) 13 b := m.Prototype().NewBuilder() 14 b.AssignInt(4) 15 n := b.Build() 16 u := basicnode.NewUint(5) 17 qt.Check(t, must.Int(m), qt.Equals, int64(3)) 18 qt.Check(t, must.Int(n), qt.Equals, int64(4)) 19 qt.Check(t, must.Int(u), qt.Equals, int64(5)) 20 } 21 22 func TestIntErrors(t *testing.T) { 23 x := basicnode.NewInt(3) 24 25 _, err := x.LookupByIndex(0) 26 errExpect := `func called on wrong kind: "LookupByIndex" called on a int node \(kind: int\), but only makes sense on list` 27 qt.Check(t, err, qt.ErrorMatches, errExpect) 28 29 _, err = x.LookupByString("n") 30 errExpect = `func called on wrong kind: "LookupByString" called on a int node \(kind: int\), but only makes sense on map` 31 qt.Check(t, err, qt.ErrorMatches, errExpect) 32 33 _, err = x.LookupByNode(x) 34 errExpect = `func called on wrong kind: "LookupByNode" called on a int node \(kind: int\), but only makes sense on map` 35 qt.Check(t, err, qt.ErrorMatches, errExpect) 36 }