github.com/cloudwego/frugal@v0.1.15/internal/binary/encoder/translator_test.go (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package encoder 18 19 import ( 20 `reflect` 21 `testing` 22 23 `github.com/stretchr/testify/require` 24 ) 25 26 type TranslatorTestStruct struct { 27 A bool `frugal:"0,default,bool"` 28 B int8 `frugal:"1,default,i8"` 29 C float64 `frugal:"2,default,double"` 30 D int16 `frugal:"3,default,i16"` 31 E int32 `frugal:"4,default,i32"` 32 F int64 `frugal:"5,default,i64"` 33 G string `frugal:"6,default,string"` 34 H []byte `frugal:"7,default,binary"` 35 I []int32 `frugal:"8,default,list<i32>"` 36 J map[string]string `frugal:"9,default,map<string:string>"` 37 K map[string]*TranslatorTestStruct `frugal:"65,default,map<string:TranslatorTestStruct>"` 38 L *bool `frugal:"11,optional,bool"` 39 M *int8 `frugal:"12,optional,i8"` 40 N *float64 `frugal:"13,optional,double"` 41 O *int16 `frugal:"14,optional,i16"` 42 P *int32 `frugal:"15,optional,i32"` 43 Q *int64 `frugal:"16,optional,i64"` 44 } 45 46 func TestTranslator_Translate(t *testing.T) { 47 var v TranslatorTestStruct 48 p, err := CreateCompiler().Compile(reflect.TypeOf(v)) 49 require.NoError(t, err) 50 tr := Translate(p) 51 println(tr.Disassemble()) 52 }