6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00
firebird-qa/tests/bugs/core_2006_test.py

489 lines
16 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-21 18:49:26 +01:00
"""
ID: issue-2443
ISSUE: 2443
TITLE: SUBSTRING with regular expression (SIMILAR TO) capability
DESCRIPTION:
JIRA: CORE-2006
FBTEST: bugs.core_2006
2022-01-21 18:49:26 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
set list on;
------------------------------------------------------------------------------
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
-- Test for matching with percent characters before and after pattern:
select
trim(str) str
,trim(ptn) ptn
,iif( trim(str) similar to '%'||trim(ptn)||'%', 1, 0 ) "str similar to %ptn%"
,substring( trim(str) similar '%\\"' || trim(ptn) || '\\"%' escape '\\' ) "subs(str similar to %ptn%)"
from(
select
'WDWDWDWD' str
,'((DW)|(WD)){4}' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select
'AAXYAAXYAAAAXYAAAXYAA' str
,'(AAXY|AAAX){2,}' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select
'YZZXYZZ0Z0YZZYZZYYZZZYZZ0Z0YZZ'
,'(0Z0(Y|Z)*){2}'
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select
'AARARARAARARAR'
,'RA(AR){3}'
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select
'eiavieieav' str
,'(ie){2,}' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select
'avieieavav' str
,'(av|ie){2,}' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select
'avieieieav' str
,'((av)|(ie)){2,}' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
);
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
----------------------
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
-- Test for exact matching to pattern:
select
trim(str) str
,trim(ptn) ptn
,iif( trim(str) similar to trim(ptn), 1, 0 ) "str similar to ptn"
,substring( trim(str) similar '\\"' || trim(ptn) || '\\"' escape '\\' ) "subs(str similar to ptn)"
from(
select ----------- core-2389
'x/t' str
,'%[/]t' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select ------------------- core-2756
'2015-04-13' str
,'[[:DIGIT:]]{4}[-][[:DIGIT:]]{2}[-][[:DIGIT:]]{2}' ptn
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select ------------------- core-2780
'WI-T3.0.0.31780 Firebird 3.0 Beta 2'
,'%[0-9]+.[0-9]+.[0-9]+((.?[0-9]+)*)[[:WHITESPACE:]]%'
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select ----------- core-3523
2021-10-21 19:29:23 +02:00
'm'
2021-04-26 20:07:00 +02:00
,'[p-k]'
from rdb$database
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
union all
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
------------------- core-3754
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
select '1', '(1|2){0,}' from rdb$database union all select
'1', '(1|2){0,1}' from rdb$database union all select
'1', '(1|2){1}' from rdb$database union all select
'123', '(1|12[3]?){1}' from rdb$database union all select
'123', '(1|12[3]?)+' from rdb$database union all select
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
------------- core-0769
2021-10-21 19:29:23 +02:00
'ab', 'ab|cd|efg' from rdb$database union all select
'efg', 'ab|cd|efg' from rdb$database union all select
2021-04-26 20:07:00 +02:00
'a', 'ab|cd|efg' from rdb$database union all select -- 0
2021-10-21 19:29:23 +02:00
'', 'a*' from rdb$database union all select
'a', 'a*' from rdb$database union all select
'aaa', 'a*' from rdb$database union all select
2021-04-26 20:07:00 +02:00
'', 'a+' from rdb$database union all select -- 0
'a', 'a+' from rdb$database union all select
'aaa', 'a+' from rdb$database union all select
'', 'a?' from rdb$database union all select
'a', 'a?' from rdb$database union all select
'aaa', 'a?' from rdb$database union all select -- 0
'', 'a{2,}' from rdb$database union all select -- 0
'a', 'a{2,}' from rdb$database union all select -- 0
'aa', 'a{2,}' from rdb$database union all select
'aaa', 'a{2,}' from rdb$database union all select
'', 'a{2,4}' from rdb$database union all select -- 0
'a', 'a{2,4}' from rdb$database union all select -- 0
'aa', 'a{2,4}' from rdb$database union all select
'aaa', 'a{2,4}' from rdb$database union all select
'aaaa', 'a{2,4}' from rdb$database union all select
'aaaaa', 'a{2,4}' from rdb$database union all select -- 0
'', '_' from rdb$database union all select -- 0
'a', '_' from rdb$database union all select
'1', '_' from rdb$database union all select
'a1', '_' from rdb$database union all select -- 0
'', '%' from rdb$database union all select
'az', 'a%z' from rdb$database union all select
'a123z', 'a%z' from rdb$database union all select
'azx', 'a%z' from rdb$database union all select -- 0
'ab', '(ab){2}' from rdb$database union all select -- 0
'aabb', '(ab){2}' from rdb$database union all select -- 0
'abab', '(ab){2}' from rdb$database union all select
'b', '[abc]' from rdb$database union all select
'd', '[abc]' from rdb$database union all select -- 0
'9', '[0-9]' from rdb$database union all select
'9', '[0-8]' from rdb$database union all select -- 0
'b', '[^abc]' from rdb$database union all select -- 0
'd', '[^abc]' from rdb$database union all select
'3', '[[:DIGIT:]^3]' from rdb$database union all select -- 0
'4', '[[:DIGIT:]^3]' from rdb$database union all select
'4', '[[:DIGIT:]]' from rdb$database union all select
'a', '[[:DIGIT:]]' from rdb$database union all select -- 0
'4', '[^[:DIGIT:]]' from rdb$database union all select -- 0
'a', '[^[:DIGIT:]]' from rdb$database
);
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
STR WDWDWDWD
PTN ((DW)|(WD)){4}
str similar to %ptn% 1
subs(str similar to %ptn%) WDWDWDWD
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR AAXYAAXYAAAAXYAAAXYAA
PTN (AAXY|AAAX){2,}
str similar to %ptn% 1
subs(str similar to %ptn%) AAXYAAXY
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR YZZXYZZ0Z0YZZYZZYYZZZYZZ0Z0YZZ
PTN (0Z0(Y|Z)*){2}
str similar to %ptn% 1
subs(str similar to %ptn%) 0Z0YZZYZZYYZZZYZZ0Z0YZZ
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR AARARARAARARAR
PTN RA(AR){3}
str similar to %ptn% 1
subs(str similar to %ptn%) RAARARAR
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR eiavieieav
PTN (ie){2,}
str similar to %ptn% 1
subs(str similar to %ptn%) ieie
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR avieieavav
PTN (av|ie){2,}
str similar to %ptn% 1
subs(str similar to %ptn%) avieieavav
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR avieieieav
PTN ((av)|(ie)){2,}
str similar to %ptn% 1
subs(str similar to %ptn%) avieieieav
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR x/t
PTN %[/]t
str similar to ptn 1
subs(str similar to ptn) x/t
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 2015-04-13
PTN [[:DIGIT:]]{4}[-][[:DIGIT:]]{2}[-][[:DIGIT:]]{2}
str similar to ptn 1
subs(str similar to ptn) 2015-04-13
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR WI-T3.0.0.31780 Firebird 3.0 Beta 2
PTN %[0-9]+.[0-9]+.[0-9]+((.?[0-9]+)*)[[:WHITESPACE:]]%
str similar to ptn 1
subs(str similar to ptn) WI-T3.0.0.31780 Firebird 3.0 Beta 2
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR m
PTN [p-k]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 1
PTN (1|2){0,}
str similar to ptn 1
subs(str similar to ptn) 1
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 1
PTN (1|2){0,1}
str similar to ptn 1
subs(str similar to ptn) 1
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 1
PTN (1|2){1}
str similar to ptn 1
subs(str similar to ptn) 1
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 123
PTN (1|12[3]?){1}
str similar to ptn 1
subs(str similar to ptn) 123
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 123
PTN (1|12[3]?)+
str similar to ptn 1
subs(str similar to ptn) 123
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR ab
PTN ab|cd|efg
str similar to ptn 1
subs(str similar to ptn) ab
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR efg
PTN ab|cd|efg
str similar to ptn 1
subs(str similar to ptn) efg
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN ab|cd|efg
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN a*
str similar to ptn 1
2021-10-21 19:29:23 +02:00
subs(str similar to ptn)
2021-04-26 20:07:00 +02:00
STR a
PTN a*
str similar to ptn 1
subs(str similar to ptn) a
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaa
PTN a*
str similar to ptn 1
subs(str similar to ptn) aaa
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN a+
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN a+
str similar to ptn 1
subs(str similar to ptn) a
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaa
PTN a+
str similar to ptn 1
subs(str similar to ptn) aaa
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN a?
str similar to ptn 1
2021-10-21 19:29:23 +02:00
subs(str similar to ptn)
2021-04-26 20:07:00 +02:00
STR a
PTN a?
str similar to ptn 1
subs(str similar to ptn) a
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaa
PTN a?
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN a{2,}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN a{2,}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aa
PTN a{2,}
str similar to ptn 1
subs(str similar to ptn) aa
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaa
PTN a{2,}
str similar to ptn 1
subs(str similar to ptn) aaa
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN a{2,4}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN a{2,4}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aa
PTN a{2,4}
str similar to ptn 1
subs(str similar to ptn) aa
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaa
PTN a{2,4}
str similar to ptn 1
subs(str similar to ptn) aaa
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaaa
PTN a{2,4}
str similar to ptn 1
subs(str similar to ptn) aaaa
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aaaaa
PTN a{2,4}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN _
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN _
str similar to ptn 1
subs(str similar to ptn) a
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 1
PTN _
str similar to ptn 1
subs(str similar to ptn) 1
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a1
PTN _
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
STR
2021-04-26 20:07:00 +02:00
PTN %
str similar to ptn 1
2021-10-21 19:29:23 +02:00
subs(str similar to ptn)
2021-04-26 20:07:00 +02:00
STR az
PTN a%z
str similar to ptn 1
subs(str similar to ptn) az
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a123z
PTN a%z
str similar to ptn 1
subs(str similar to ptn) a123z
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR azx
PTN a%z
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR ab
PTN (ab){2}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR aabb
PTN (ab){2}
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR abab
PTN (ab){2}
str similar to ptn 1
subs(str similar to ptn) abab
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR b
PTN [abc]
str similar to ptn 1
subs(str similar to ptn) b
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR d
PTN [abc]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 9
PTN [0-9]
str similar to ptn 1
subs(str similar to ptn) 9
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 9
PTN [0-8]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR b
PTN [^abc]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR d
PTN [^abc]
str similar to ptn 1
subs(str similar to ptn) d
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 3
PTN [[:DIGIT:]^3]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 4
PTN [[:DIGIT:]^3]
str similar to ptn 1
subs(str similar to ptn) 4
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 4
PTN [[:DIGIT:]]
str similar to ptn 1
subs(str similar to ptn) 4
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN [[:DIGIT:]]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR 4
PTN [^[:DIGIT:]]
str similar to ptn 0
subs(str similar to ptn) <null>
2021-10-21 19:29:23 +02:00
2021-04-26 20:07:00 +02:00
STR a
PTN [^[:DIGIT:]]
str similar to ptn 1
subs(str similar to ptn) a
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-21 18:49:26 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout
2021-04-26 20:07:00 +02:00