-
Notifications
You must be signed in to change notification settings - Fork 2
/
range_test.sh
executable file
·134 lines (102 loc) · 3.27 KB
/
range_test.sh
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
. ./range.sh
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
DEFAULT='\033[0m'
FAIL=$(echo -e "[${RED} fail ${DEFAULT}]")
PASS=$(echo -e "[${GREEN} pass ${DEFAULT}]")
function test_repeat() {
local test_name="test_repeat"
local expected="0000"
local got=$(repeat "0" "4")
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
function test_parse_start() {
local test_name="test_parse_start"
local expected="739 999 1000 7420"
local got=$(parse_start 739 7420)
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
function test_create_break_point() {
local test_name="test_create_break_point"
local expected="09"
local got=$(create_break_point 9)
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
function test_parse_end() {
local test_name="test_parse_end"
local expected="739 739 740 799 800 999"
local got=$(parse_end 739 999)
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
function test_parse_into_regex() {
local test_name="test_parse_into_regex"
local expected="739 7[4-9][0-9] [89][0-9]{2} [1-6][0-9]{3} 7[0-3][0-9]{2} 74[01][0-9] 7420"
local got=$(parse_into_regex "739 739 740 799 800 999 1000 6999 7000 7399 7400 7419 7420 7420")
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
function test_parse_into_pattern() {
local test_name="test_parse_into_pattern"
local expected="(739|7[4-9][0-9]|[89][0-9]{2}|[1-6][0-9]{3}|7[0-3][0-9]{2}|74[01][0-9]|7420)"
local got=$(parse_into_pattern "739 7[4-9][0-9] [89][0-9]{2} [1-6][0-9]{3} 7[0-3][0-9]{2} 74[01][0-9] 7420")
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
function test_combine() {
local test_name="test_combine"
local expected="(739|7[4-9][0-9]|[89][0-9]{2}|[1-6][0-9]{3}|7[0-3][0-9]{2}|74[01][0-9]|7420)"
local got=$(combine "739" "7420")
if [ ! "$expected" = "$got" ]; then
echo -e "$FAIL $test_name \nexpected: $expected\n got: $got" >&2
return 1
fi
echo -e "$PASS $test_name" >&2
}
case "$1" in
test_repeat)
test_repeat;;
test_parse_start)
test_parse_start;;
test_create_break_point)
test_create_break_point;;
test_parse_end)
test_parse_end;;
test_parse_into_regex)
test_parse_into_regex;;
test_parse_into_pattern)
test_parse_into_pattern;;
test_combine)
test_combine;;
*)
test_repeat
test_parse_start
test_create_break_point
test_parse_end
test_parse_into_regex
test_parse_into_pattern
test_combine
esac