-
Notifications
You must be signed in to change notification settings - Fork 35
/
unit-test-match.sql
105 lines (84 loc) · 2.13 KB
/
unit-test-match.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
-- Unit tests for the dbo.RegexMatch() function
See unit-tests.md for a list of expected behaviors
*/
-- UNIT TEST: Match one entry
; with test as
(
select dbo.RegexMatch('testme space','\w+') as TestResult
)
select StatusMessage = case when TestResult = 'testme' then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = 'testme'
from test
go
-- UNIT TEST: Match no entries
; with test as
(
select dbo.RegexMatch('testme space','ddd') as TestResult
)
select StatusMessage = case when TestResult is null then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = null
from test
go
-- UNIT TEST: Match multiple entries
; with test as
(
select dbo.RegexMatch('testme space','\w') as TestResult
)
select StatusMessage = case when TestResult = 't' then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = 't' --the first character
from test
go
-- UNIT TEST: Null string input
; with test as
(
select dbo.RegexMatch(null,'\w') as TestResult
)
select StatusMessage = case when TestResult is null then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = null
from test
go
-- UNIT TEST: Null pattern input
; with test as
(
select dbo.RegexMatch('testme space',null) as TestResult
)
select StatusMessage = case when TestResult is null then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = null
from test
go
-- UNIT TEST: Both inputs are null
; with test as
(
select dbo.RegexMatch(null,null) as TestResult
)
select StatusMessage = case when TestResult is null then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = null
from test
go
-- UNIT TEST: Illegal regular expression
; with test as
(
select dbo.RegexMatch('testme space','$^') as TestResult
)
select StatusMessage = case when TestResult is null then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = null
from test
go
-- UNIT TEST: Wrong input types (numbers, guids, etc)
; with test as
(
select dbo.RegexMatch(1334873,'\d{3}') as TestResult
)
select StatusMessage = case when TestResult = '133' then 'Success' else 'Failure' end
,TestResult
,ExpectedTestResult = 133
from test
go