github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/internal/util/strings_test.go (about) 1 /** 2 * Copyright 2023 CloudWeGo Authors. 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 util 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestSplitTagOptions(t *testing.T) { 25 type args struct { 26 tag string 27 } 28 tests := []struct { 29 name string 30 args args 31 wantRet []string 32 wantErr bool 33 }{ 34 { 35 name: "single", 36 args: args{ 37 tag: `json:"k1,omitempty"`, 38 }, 39 wantRet: []string{"json", "k1"}, 40 wantErr: false, 41 }, 42 { 43 name: "multi", 44 args: args{ 45 tag: `json:"k1,omitempty" thrift:"k2,xxx"`, 46 }, 47 wantRet: []string{"json", "k1", "thrift", "k2"}, 48 wantErr: false, 49 }, 50 { 51 name: "quoted", 52 args: args{ 53 tag: `json:\"k1,omitempty\"`, 54 }, 55 wantRet: []string{"json", "k1"}, 56 wantErr: false, 57 }, 58 59 } 60 for _, tt := range tests { 61 t.Run(tt.name, func(t *testing.T) { 62 gotRet, err := SplitTagOptions(tt.args.tag) 63 if (err != nil) != tt.wantErr { 64 t.Errorf("SplitTagOptions() error = %v, wantErr %v", err, tt.wantErr) 65 return 66 } 67 if !reflect.DeepEqual(gotRet, tt.wantRet) { 68 t.Errorf("SplitTagOptions() = %v, want %v", gotRet, tt.wantRet) 69 } 70 }) 71 } 72 }