-- source include/have_big5.inc

#
# Tests with the big5 character set
#
--disable_warnings
drop table if exists t1;
--enable_warnings

SET @test_character_set= 'big5';
SET @test_collation= 'big5_chinese_ci';
-- source include/ctype_common.inc

SET NAMES big5;
SET collation_connection='big5_chinese_ci';
-- source include/ctype_filesort.inc
-- source include/ctype_innodb_like.inc
-- source include/ctype_like_escape.inc
-- source include/ctype_like_range_f1f2.inc
-- source include/ctype_ascii_order.inc
SET collation_connection='big5_bin';
-- source include/ctype_filesort.inc
-- source include/ctype_innodb_like.inc
-- source include/ctype_like_escape.inc
-- source include/ctype_like_range_f1f2.inc

#
# Bugs#9357: TEXT columns break string with special word in BIG5 charset.
#
SET NAMES big5;
CREATE TABLE t1 (a text) character set big5;
INSERT INTO t1 VALUES ('ùØ');
SELECT * FROM t1;
DROP TABLE t1;

#
# BUG#12075 - FULLTEXT non-functional for big5 strings
#
CREATE TABLE t1 (a CHAR(50) CHARACTER SET big5 NOT NULL, FULLTEXT(a));
INSERT INTO t1 VALUES(0xA741ADCCA66EB6DC20A7DAADCCABDCA66E);
SELECT HEX(a) FROM t1 WHERE MATCH(a) AGAINST (0xA741ADCCA66EB6DC IN BOOLEAN MODE);
DROP TABLE t1;

#
# Bug#12476 Some big5 codes are still missing.
#
set names big5;
create table t1 (a char character set big5);
insert into t1 values (0xF9D6),(0xF9D7),(0xF9D8),(0xF9D9);
insert into t1 values (0xF9DA),(0xF9DB),(0xF9DC);
# Check round trip
select hex(a) a, hex(@u:=convert(a using utf8)) b,
hex(convert(@u using big5)) c from t1 order by a;
# Check that there is no "illegal mix of collations" error with Unicode.
alter table t1 convert to character set utf8;
select hex(a) from t1 where a = _big5 0xF9DC;
drop table t1;

#
# Bugs#15375: Unassigned multibyte codes are broken
# into parts when converting to Unicode.
# This query should return 0x003F0041. I.e. it should
# scan unassigned double-byte character 0xC840, convert
# it as QUESTION MARK 0x003F and then scan the next
# character, which is a single byte character 0x41.
#
select hex(convert(_big5 0xC84041 using ucs2));

--echo End of 4.1 tests

#
# Bug#26711 "binary content 0x00 sometimes becomes 0x5C 0x00 after dump/load"
#
set names big5;
create table t1 (a blob);
insert into t1 values (0xEE00);
select * into outfile 'test/t1.txt' from t1;
delete from t1;
let $MYSQLD_DATADIR= `select @@datadir`;
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
--eval select hex(load_file('$MYSQLD_DATADIR/test/t1.txt'));
load data infile 't1.txt' into table t1;
select hex(a) from t1;
--remove_file $MYSQLD_DATADIR/test/t1.txt
drop table t1;

--echo End of 5.0 tests


--echo #
--echo # Start of 5.5 tests
--echo #

--echo #
--echo # Testing WL#4583 Case conversion in Asian character sets 
--echo #
#
# Populate t1 with all hex digits
#
SET NAMES utf8;
SET collation_connection=big5_chinese_ci;
CREATE TABLE t1 (b VARCHAR(2));
INSERT INTO t1 VALUES ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7');
INSERT INTO t1 VALUES ('8'),('9'),('A'),('B'),('C'),('D'),('E'),('F');
#
# Populate tables head and tail with values '00'-'FF'
#
CREATE TEMPORARY TABLE head AS SELECT concat(b1.b, b2.b) AS head FROM t1 b1, t1 b2;
CREATE TEMPORARY TABLE tail AS SELECT concat(b1.b, b2.b) AS tail FROM t1 b1, t1 b2;
DROP TABLE t1;
#
# Populate table t1 with all values [80..FF][20..FF]
# Expected valid big5 codes: [A1..F9][40..7E,A1..FE] (89x157=13973)
#
CREATE TABLE t1 AS
SELECT concat(head, tail) AS code, ' ' AS a
FROM head, tail
WHERE (head BETWEEN '80' AND 'FF') AND (tail BETWEEN '20' AND 'FF')
ORDER BY head, tail;
DROP TEMPORARY TABLE head, tail;
SHOW CREATE TABLE t1;
SELECT COUNT(*) FROM t1;
UPDATE t1 SET a=unhex(code) ORDER BY code;
SELECT COUNT(*) FROM t1 WHERE a<>'';
#
# Display all characters that have upper or lower case mapping.
#
SELECT code, hex(upper(a)), hex(lower(a)),a, upper(a), lower(a) FROM t1 WHERE hex(a)<>hex(upper(a)) OR hex(a)<>hex(lower(a));
#
# Make sure all possible conversion happened
#
# Expect U+2160 to U+2169 ROMAN NUMERAL ONE to ROMAN NUMERAL TEN
#
SELECT * FROM t1
WHERE HEX(CAST(LOWER(a) AS CHAR CHARACTER SET utf8)) <>
      HEX(LOWER(CAST(a AS CHAR CHARACTER SET utf8))) ORDER BY code;
#
# Expect U+0430 to U+0433 CYRILLIC SMALL LETTER A, BE, VE, GHE
# Expect U+043D to U+0442 CYRILLIC SMALL LETTER EN, O, PE, ER, ES, TE
#
SELECT * FROM t1
WHERE HEX(CAST(UPPER(a) AS CHAR CHARACTER SET utf8)) <>
      HEX(UPPER(CAST(a AS CHAR CHARACTER SET utf8))) ORDER BY code;
DROP TABLE t1;

--echo #
--echo # End of 5.5 tests
--echo #


--echo #
--echo # Start of 5.6 tests
--echo #

--echo #
--echo # WL#3664 WEIGHT_STRING
--echo #

set names big5;
--source include/weight_string.inc
--source include/weight_string_l1.inc
--source include/weight_string_A1A1.inc

set collation_connection=big5_bin;
--source include/weight_string.inc
--source include/weight_string_l1.inc
--source include/weight_string_A1A1.inc

--echo #
--echo # End of 5.6 tests
--echo #

--echo #
--echo # Start of 10.0 tests
--echo #

let $ctype_unescape_combinations=selected;
--source include/ctype_unescape.inc

--character_set big5
SET NAMES big5;
--source include/ctype_E05C.inc


#
# Checking unassigned character 0xC840 in an ENUM
#

SET NAMES big5;
CREATE TABLE t1 (a ENUM('È@') CHARACTER SET big5);
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES ('È@');
INSERT INTO t1 VALUES (_big5 0xC840);
INSERT INTO t1 VALUES (0xC840);
SELECT HEX(a),a FROM t1;
DROP TABLE t1;

SET NAMES binary;
CREATE TABLE t1 (a ENUM('È@') CHARACTER SET big5);
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES ('È@');
INSERT INTO t1 VALUES (_big5 0xC840);
INSERT INTO t1 VALUES (0xC840);
SELECT HEX(a),a FROM t1;
DROP TABLE t1;


#
# Checking unassigned character in CHAR, VARCHAR, TEXT
#

SET NAMES big5;
CREATE TABLE t1 (
  c1 CHAR(10)    CHARACTER SET big5,
  c2 VARCHAR(10) CHARACTER SET big5,
  c3 TEXT        CHARACTER SET big5
);
INSERT INTO t1 VALUES ('È@','È@','È@');
INSERT INTO t1 VALUES (_big5 0xC840,_big5 0xC840,_big5 0xC840);
INSERT INTO t1 VALUES (0xC840,0xC840,0xC840);
SELECT HEX(c1),HEX(c2),HEX(c3) FROM t1;
DROP TABLE t1;

SET NAMES binary;
CREATE TABLE t1 (
  c1 CHAR(10)    CHARACTER SET big5,
  c2 VARCHAR(10) CHARACTER SET big5,
  c3 TEXT        CHARACTER SET big5
);
INSERT INTO t1 VALUES ('È@','È@','È@');
INSERT INTO t1 VALUES (_big5 0xC840,_big5 0xC840,_big5 0xC840);
INSERT INTO t1 VALUES (0xC840,0xC840,0xC840);
SELECT HEX(c1),HEX(c2),HEX(c3) FROM t1;
DROP TABLE t1;


#
# Checking binary->big5 conversion of an unassigned character 0xC840 in optimizer
#
SET NAMES binary;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET big5, KEY(a));
INSERT INTO t1 VALUES (0xC840),(0xC841),(0xC842);
SELECT HEX(a) FROM t1 WHERE a='È@';
SELECT HEX(a) FROM t1 IGNORE KEY(a) WHERE a='È@';
DROP TABLE t1;

--echo #
--echo # End of 10.0 tests
--echo #
