Skip to content

Commit

Permalink
test: Add required tests for go/mysql/collations/charset (#15435)
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 authored Mar 18, 2024
1 parent f19b58e commit 61db2db
Show file tree
Hide file tree
Showing 3 changed files with 579 additions and 0 deletions.
108 changes: 108 additions & 0 deletions go/mysql/collations/charset/charset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package charset

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsMultibyteByName(t *testing.T) {
testCases := []struct {
csname string
want bool
}{
{"euckr", true},
{"gb2312", true},
{"sjis", true},
{"cp932", true},
{"eucjpms", true},
{"ujis", true},
{"utf16", false},
{"latin1", false},
{"binary", false},
}

for _, tc := range testCases {
t.Run(tc.csname, func(t *testing.T) {
assert.Equal(t, tc.want, IsMultibyteByName(tc.csname))
})
}
}

func TestIsUnicode(t *testing.T) {
testCases := []struct {
cs Charset
want bool
}{
{Charset_utf8mb3{}, true},
{Charset_utf8mb4{}, true},
{Charset_utf16{}, true},
{Charset_utf16le{}, true},
{Charset_ucs2{}, true},
{Charset_utf32{}, true},
{&testCharset1{}, false},
}

for _, tc := range testCases {
t.Run(tc.cs.Name(), func(t *testing.T) {
assert.Equal(t, tc.want, IsUnicode(tc.cs))
})
}
}

func TestIsUnicodeByName(t *testing.T) {
testCases := []struct {
csname string
want bool
}{
{"utf8", true},
{"utf8mb3", true},
{"utf8mb4", true},
{"utf16", true},
{"utf16le", true},
{"ucs2", true},
{"utf32", true},
{"binary", false},
}

for _, tc := range testCases {
t.Run(tc.csname, func(t *testing.T) {
assert.Equal(t, tc.want, IsUnicodeByName(tc.csname))
})
}
}

func TestIsBackslashSafe(t *testing.T) {
testCases := []struct {
cs Charset
want bool
}{
{Charset_sjis{}, false},
{Charset_cp932{}, false},
{Charset_gb18030{}, false},
{Charset_utf16le{}, true},
{&testCharset1{}, true},
}

for _, tc := range testCases {
t.Run(tc.cs.Name(), func(t *testing.T) {
assert.Equal(t, tc.want, IsBackslashSafe(tc.cs))
})
}
}
Loading

0 comments on commit 61db2db

Please sign in to comment.