github.com/chrislusf/greenpack@v3.7.1-0.20170911073826-ad5bd10b7c47+incompatible/msgp/clue_test.go (about) 1 package msgp 2 3 import ( 4 "testing" 5 ) 6 7 // embedding of version & type info at the 8 // end of the field name, as in "myField_zid01_i64" 9 // For back-compatibility with existing 10 // msgpack2 implementations, this is still 11 // a legit variable name. 12 func TestClue(t *testing.T) { 13 14 // convert from (name, type, zid) -> fieldName 15 name := "my_Field" 16 clue := "i64" 17 var zid int64 = 9 18 fieldName := Clue2Field(name, clue, zid) 19 if fieldName != "my_Field_zid09_i64" { 20 t.Fatalf("unexpected fieldName") 21 } 22 f := Clue2Field(name, clue, 199) 23 if f != "my_Field_zid199_i64" { 24 t.Fatalf("unexpected fieldName") 25 } 26 27 // and the inverse: parse fieldName -> (name, type, zid) 28 name2, clue2, zid2, err := Field2Clue(fieldName) 29 if err != nil { 30 t.Fatal(err) 31 } 32 if name2 != name { 33 t.Fatal("unexpected name2") 34 } 35 if clue2 != clue { 36 t.Fatal("unexpected clue2") 37 } 38 if zid2 != zid { 39 t.Fatal("unexpected zid2") 40 } 41 }