(t *testing.T)
| 392 | } |
| 393 | |
| 394 | func TestConvertToStringWithCheck(t *testing.T) { |
| 395 | nhUTF8 := "你好" |
| 396 | nhUTF8MB4 := "你好👋" |
| 397 | nhUTF8Invalid := "你好" + string([]byte{0x81}) |
| 398 | tests := []struct { |
| 399 | input string |
| 400 | outputChs string |
| 401 | newFlags func(flags Flags) Flags |
| 402 | output string |
| 403 | }{ |
| 404 | {nhUTF8, "utf8mb4", func(f Flags) Flags { return f.WithSkipUTF8Check(false) }, nhUTF8}, |
| 405 | {nhUTF8MB4, "utf8mb4", func(f Flags) Flags { return f.WithSkipUTF8Check(false) }, nhUTF8MB4}, |
| 406 | {nhUTF8, "utf8mb4", func(f Flags) Flags { return f.WithSkipUTF8Check(true) }, nhUTF8}, |
| 407 | {nhUTF8MB4, "utf8mb4", func(f Flags) Flags { return f.WithSkipUTF8Check(true) }, nhUTF8MB4}, |
| 408 | {nhUTF8Invalid, "utf8mb4", func(f Flags) Flags { return f.WithSkipUTF8Check(true) }, nhUTF8Invalid}, |
| 409 | {nhUTF8Invalid, "utf8mb4", func(f Flags) Flags { return f.WithSkipUTF8Check(false) }, ""}, |
| 410 | {nhUTF8Invalid, "ascii", func(f Flags) Flags { return f.WithSkipSACIICheck(false) }, ""}, |
| 411 | {nhUTF8Invalid, "ascii", func(f Flags) Flags { return f.WithSkipSACIICheck(true) }, nhUTF8Invalid}, |
| 412 | {nhUTF8MB4, "utf8", func(f Flags) Flags { return f.WithSkipUTF8MB4Check(false) }, ""}, |
| 413 | {nhUTF8MB4, "utf8", func(f Flags) Flags { return f.WithSkipUTF8MB4Check(true) }, nhUTF8MB4}, |
| 414 | } |
| 415 | for _, tt := range tests { |
| 416 | ft := NewFieldType(mysql.TypeVarchar) |
| 417 | ft.SetFlen(255) |
| 418 | ft.SetCharset(tt.outputChs) |
| 419 | inputDatum := NewStringDatum(tt.input) |
| 420 | ctx := DefaultStmtNoWarningContext |
| 421 | ctx = ctx.WithFlags(tt.newFlags(DefaultStmtFlags)) |
| 422 | outputDatum, err := inputDatum.ConvertTo(ctx, ft) |
| 423 | if len(tt.output) == 0 { |
| 424 | require.True(t, charset.ErrInvalidCharacterString.Equal(err), tt) |
| 425 | } else { |
| 426 | require.NoError(t, err, tt) |
| 427 | require.Equal(t, tt.output, outputDatum.GetString(), tt) |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | func TestConvertToBinaryString(t *testing.T) { |
| 433 | nhUTF8 := "你好" |
nothing calls this directly
no test coverage detected