github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/issue_test/issue242_test.go (about) 1 // +build !go1.22 2 3 /* 4 * Copyright 2021 ByteDance Inc. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package issue_test 20 21 import ( 22 `unicode/utf8` 23 `encoding/json` 24 `testing` 25 26 `github.com/stretchr/testify/require` 27 `github.com/bytedance/sonic` 28 ) 29 30 func TestIssue242_MarshalControlChars(t *testing.T) { 31 for i := 0; i < utf8.RuneSelf; i++ { 32 input := string([]byte{byte(i)}) 33 out1, err1 := sonic.ConfigStd.Marshal(input) 34 out2, err2 := json.Marshal(input) 35 require.NoError(t, err1) 36 require.NoError(t, err2) 37 require.Equal(t, out1, out2) 38 } 39 }