#coding:utf-8 """ ID: gtcs.regexp-substring-similar-to TITLE: SUBSTRING - miscelaneous tests of SIMILAR TO DESCRIPTION: Test creates table and fills it with unicode data to be checked (field 'str'), pattern and performs output of SUBSTRING( SIMILAR ). Also, some additional examples presents for other checks. Original test see in: https://github.com/FirebirdSQL/fbtcs/blob/master/GTCS/tests/FB_SQL_REGEX_1.script FBTEST: functional.gtcs.regexp_substring_similar_to """ import pytest from firebird.qa import * db = db_factory() test_script = """ recreate table tests ( id integer generated by default as identity, str varchar(20), pattern varchar(20), expected varchar(20) ); create sequence g; set heading off; insert into tests(id, str, pattern, expected) values ( gen_id(g,1), '(12) 3456-7890', '\\(__\\) \\"%\\-%\\"', '3456-7890'); insert into tests(id, str, pattern, expected) values ( gen_id(g,1), '(12) 3456-7890', '\\(__\\) \\"%x%\\"', null); insert into tests(id, str, pattern, expected) values ( gen_id(g,1), 'abc123abc456', '\\"%\\"abc%6', 'abc123'); insert into tests(id, str, pattern, expected) values ( gen_id(g,1), 'abc123abc456', '\\"%\\"abc%7', null); commit; select id, substring(str similar pattern escape '\\'), expected from tests; select gen_id(g,1), substring('(12) 3456-7890' similar '\\(__\\) \\"%\\-%\\"' escape '\\') from rdb$database; -- 3.0.6: invalid pattern select gen_id(g,1), substring('abc123abc456' similar '\\"%\\"abc%6' escape '\\') from rdb$database; select gen_id(g,1), substring('abc123abc456' similar '\\"%\\"abc%7' escape '\\') from rdb$database; select gen_id(g,1), substring('asds 12.34 asd' similar '% \\"[\\+\\-]?[0-9]*([0-9].|.[0-9])?[0-9]*\\" %' escape '\\') from rdb$database; select gen_id(g,1), substring('asd 5 s 1234 a 12 sd' similar '% \\"[\\+\\-]?[0-9]*\\" %' escape '\\') from rdb$database; select gen_id(g,1), substring('a 1 b' similar '%#"[0-9]*#" %' escape '#') from rdb$database; select gen_id(g,1), substring('çaaaЫxЫЫcccç' similar '%aaa#"%#"ccc%' escape '#') from rdb$database; select gen_id(g,1), substring(cast('aaaЫxЫЫccc' as varchar(15) character set win1251) similar '%aaa#"%#"ccc%' escape '#') from rdb$database; select gen_id(g,1), cast(substring(cast(_utf8 'aaaЫxЫЫccc' as varchar(10) character set win1251) similar '%aaa#"%#"ccc%' escape '#') as varchar(10) character set utf8) from rdb$database; """ act = isql_act('db', test_script, substitutions=[('[ \t]+', ' ')]) expected_stdout = """ 1 3456-7890 3456-7890 2 3 abc123 abc123 4 5 3456-7890 6 abc123 7 8 12.34 9 5 10 11 ЫxЫЫ 12 ЫxЫЫ 13 ЫxЫЫ """ @pytest.mark.version('>=4.0') def test_1(act: Action): act.expected_stdout = expected_stdout act.execute() assert act.clean_stdout == act.clean_expected_stdout