gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

mammoth2-test.go.tmpl (3106B)


      1 // +build !codec.notmammoth
      2 
      3 // Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved.
      4 // Use of this source code is governed by a MIT license found in the LICENSE file.
      5 
      6 // Code generated from mammoth2-test.go.tmpl - DO NOT EDIT.
      7 
      8 package codec
      9 
     10 // Increase codecoverage by covering all the codecgen paths, in fast-path and gen-helper.go....
     11 //
     12 // Note: even though this is built based on fast-path and gen-helper, we will run these tests
     13 // in all modes, including notfastpath, etc.
     14 //
     15 // Add test file for creating a mammoth generated file as _mammoth_generated.go
     16 //  - generate a second mammoth files in a different file: mammoth2_generated_test.go
     17 //    mammoth-test.go.tmpl will do this
     18 //  - run codecgen on it, into mammoth2_codecgen_generated_test.go (no build tags)
     19 //  - as part of TestMammoth, run it also
     20 //  - this will cover all the codecgen, gen-helper, etc in one full run
     21 //  - check in mammoth* files into github also
     22 //
     23 // Now, add some types:
     24 //  - some that implement BinaryMarshal, TextMarshal, JSONMarshal, and one that implements none of it
     25 //  - create a wrapper type that includes TestMammoth2, with it in slices, and maps, and the custom types
     26 //  - this wrapper object is what we work encode/decode (so that the codecgen methods are called)
     27 
     28 
     29 // import "encoding/binary"
     30 
     31 import "fmt"
     32 
     33 type TestMammoth2 struct {
     34 
     35 {{range .Values }}{{if .Primitive }}{{/*
     36 */}}{{ .MethodNamePfx "F" true }} {{ .Primitive }}
     37 {{ .MethodNamePfx "Fptr" true }} *{{ .Primitive }}
     38 {{end}}{{end}}
     39 
     40 {{range .Values }}{{if not .Primitive }}{{if not .MapKey }}{{/*
     41 */}}{{ .MethodNamePfx "F" false }} []{{ .Elem }}
     42 {{ .MethodNamePfx "Fptr" false }} *[]{{ .Elem }}
     43 {{end}}{{end}}{{end}}
     44 
     45 {{range .Values }}{{if not .Primitive }}{{if .MapKey }}{{/*
     46 */}}{{ .MethodNamePfx "F" false }} map[{{ .MapKey }}]{{ .Elem }}
     47 {{ .MethodNamePfx "Fptr" false }} *map[{{ .MapKey }}]{{ .Elem }}
     48 {{end}}{{end}}{{end}}
     49 
     50 }
     51 
     52 // -----------
     53 
     54 type testMammoth2Binary uint64
     55 func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) {
     56 data = make([]byte, 8)
     57 bigenstd.PutUint64(data, uint64(x))
     58 return
     59 }
     60 func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) {
     61 *x = testMammoth2Binary(bigenstd.Uint64(data))
     62 return
     63 }
     64 
     65 type testMammoth2Text uint64
     66 func (x testMammoth2Text) MarshalText() (data []byte, err error) {
     67 data = []byte(fmt.Sprintf("%b", uint64(x)))
     68 return
     69 }
     70 func (x *testMammoth2Text) UnmarshalText(data []byte) (err error) {
     71 _, err = fmt.Sscanf(string(data), "%b", (*uint64)(x))
     72 return
     73 }
     74 
     75 type testMammoth2Json uint64
     76 func (x testMammoth2Json) MarshalJSON() (data []byte, err error) {
     77 data = []byte(fmt.Sprintf("%v", uint64(x)))
     78 return
     79 }
     80 func (x *testMammoth2Json) UnmarshalJSON(data []byte) (err error) {
     81 _, err = fmt.Sscanf(string(data), "%v", (*uint64)(x))
     82 return
     83 }
     84 
     85 type testMammoth2Basic [4]uint64
     86 
     87 type TestMammoth2Wrapper struct {
     88 	V TestMammoth2
     89 	T testMammoth2Text
     90 	B testMammoth2Binary
     91 	J testMammoth2Json
     92 	C testMammoth2Basic
     93 	M map[testMammoth2Basic]TestMammoth2
     94 	L []TestMammoth2
     95 	A [4]int64
     96 	
     97   	Tcomplex128 complex128
     98 	Tcomplex64 complex64
     99 	Tbytes []uint8
    100 	Tpbytes *[]uint8
    101 }