github.com/cloudwego/frugal@v0.1.15/internal/binary/encoder/compiler_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 CompilerTest 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 CompilerTestSubStruct `frugal:"7,default,CompilerTestSubStruct"` 35 I *CompilerTestSubStruct `frugal:"8,default,CompilerTestSubStruct"` 36 J map[string]int `frugal:"9,default,map<string:int>"` 37 K []string `frugal:"10,default,set<string>"` 38 L []string `frugal:"11,default,list<string>"` 39 M []byte `frugal:"12,default,binary"` 40 N []int8 `frugal:"13,default,set<i8>"` 41 O []int8 `frugal:"14,default,list<i8>"` 42 } 43 44 type CompilerTestSubStruct struct { 45 X int `frugal:"0,default,i64"` 46 Y *CompilerTestSubStruct `frugal:"1,default,CompilerTestSubStruct"` 47 } 48 49 func TestCompiler_Compile(t *testing.T) { 50 p, err := CreateCompiler().Compile(reflect.TypeOf(CompilerTest{})) 51 require.NoError(t, err) 52 println(p.Disassemble()) 53 }