github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/issue_test/issue119_test.go (about) 1 2 /* 3 * Copyright 2022 ByteDance Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package issue_test 19 20 import ( 21 `testing` 22 23 `encoding/json` 24 . `github.com/bytedance/sonic` 25 `github.com/stretchr/testify/require` 26 ) 27 28 func TestIssue_UnmarshalBase64(t *testing.T) { 29 var obj, stdobj []byte 30 tests := []string { 31 `"xy\r\nzu"`, 32 `"xy\/\/"`, 33 `"\/\/=="`, 34 `"\/\/\u003d\u003d"`, 35 `"\u0030\u0030\u0030\u003d"`, 36 } 37 for _, data := range(tests) { 38 stderr := json.Unmarshal([]byte(data), &stdobj) 39 err := Unmarshal([]byte(data), &obj) 40 require.NoError(t, stderr, data) 41 require.NoError(t, err, data) 42 require.Equal(t, stdobj, obj, data) 43 } 44 } 45 46 func TestIssue_UnmarshalBase64Error(t *testing.T) { 47 var obj, stdobj []byte 48 tests := []string { 49 `"xy\r\nzu0==="`, 50 `"xy\/\/`, 51 `"\/\/==`, 52 `"\/\/\u003d0\u003d"`, 53 `"\u0030\u0030\u0030\u003d`, 54 } 55 for _, data := range(tests) { 56 stderr := json.Unmarshal([]byte(data), &stdobj) 57 err := Unmarshal([]byte(data), &obj) 58 require.Equal(t, stderr != nil, err != nil) 59 } 60 var _, _ = obj, stdobj 61 }