-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_regexp
executable file
·134 lines (111 loc) · 4.47 KB
/
test_regexp
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
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${SOURCE_DIR}"
if [ "x$1" == "x" ]; then
BIN="./regexp_dotno"
else
BIN="$1"
fi
function err() { echo "$@" 1>&2; }
# Input has to be cut to be valid will return a cut (valid) version
function assert_equal_comp {
IN="$1";
EXPOUT="$2";
GOTOUT="$(echo "$IN" | $BIN)";
if [ "${EXPOUT}" != "${GOTOUT}" ]; then
EXPLEN="$(echo -n "${EXPOUT}" | wc -c)"
GOTLEN="$(echo -n "${GOTOUT}" | wc -c)"
echo "[ERROR] Input '${IN}', expected '${EXPOUT}' (${EXPLEN}), got '${GOTOUT}' (${GOTLEN})";
fi
}
# Input is a valid domain will return the same as input
function assert_equal {
assert_equal_comp "$1" "$1";
}
# Input that can not be cut to a valid domain returns nothing
function assert_empty {
IN="$1";
GOTOUT="$(echo "$IN" | $BIN)";
if [ "%" != "%${GOTOUT}" ]; then
GOTLEN="$(echo -n "${GOTOUT}" | wc -c)"
echo "[ERROR] Input '${IN}', expected '', got '${GOTOUT} (${GOTLEN})'";
fi
}
# Check that maxlen is 63
assert_equal "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-exactly-62.no"
assert_equal "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-exactly-63.no"
assert_equal "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-exactly-63.oslo.no"
assert_equal_comp "wmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-64-cut-to-63.no" "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-64-cut-to-63.no"
assert_equal_comp "wmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-64-cut-to-63.oslo.no" "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-64-cut-to-63.oslo.no"
assert_equal_comp "wwwwwwwwwwwwwwwwmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-80-cut-to-63.no" "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-80-cut-to-63.no"
assert_equal_comp "wwwwwwwwwwwwwwwwmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-80-cut-to-63.oslo.no" "maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-80-cut-to-63.oslo.no"
# Check that - is not permitted, either at start or end
assert_equal_comp "---foo.oslo.no" "foo.oslo.no"
assert_equal_comp "foo-.oslo.no" "oslo.no"
assert_equal_comp "-foo-.oslo.no" "oslo.no"
assert_empty "-o.no"
assert_empty "o-.no"
assert_empty "-o-.no"
# Check that domains can't be one char
assert_empty "l.no"
assert_empty "-.no"
assert_empty "1.no"
# Check some legal hyphens
assert_equal "0--o.no"
assert_equal "0----------------o.no"
assert_equal "0-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o.no"
# Check that subdomains of category domains can be 1 char (oslo is category domain)
assert_equal "m.oslo.no"
assert_equal "mm.oslo.no"
assert_equal "mmm.oslo.no"
assert_equal_comp "det.er.m.oslo.no" "m.oslo.no"
assert_equal_comp "m.m.m.oslo.no" "m.oslo.no"
# Check some weird category domains
assert_equal "www.gs.of.no"
assert_equal "foobar.sande.more-og-romsdal.no"
assert_equal "www.xn--hery-ira.xn--mre-og-romsdal-qqb.no"
assert_equal "våler.østfold.no"
assert_equal "sør-trøndelag.no"
assert_equal "ákŋoluokta.no"
# Test some numbers
assert_equal "1ákŋo2.no"
assert_equal "112.no"
assert_equal "99999999.no"
# Test some strings that will return multiple domains
assert_equal_comp "det.er.no.sol.no" "er.no
sol.no"
assert_equal_comp " det.er.no.sol.no" "er.no
sol.no"
assert_equal_comp "det.er.no.sol.no" "er.no
sol.no"
assert_equal_comp "det.er.no.oslo.no" "er.no
oslo.no"
assert_equal_comp "det.er.no.m.oslo.no" "er.no
m.oslo.no"
assert_equal_comp "oslo.no,sol.no" "oslo.no
sol.no"
assert_equal_comp "det.er.no.m.m.oslo.no.m.e.no" "er.no
m.oslo.no" # oslo is category domain
# Test some domains with noise around them
assert_equal_comp "02inan.norsknettskole.no:80" "norsknettskole.no"
assert_equal_comp "02klho.norsknettskole.no/pages" "norsknettskole.no"
assert_equal_comp "02klho.norsknettskole.no/pages" "norsknettskole.no"
assert_equal "no.no"
assert_equal "øl.no"
assert_equal "lo.no"
assert_equal "lol.no"
assert_equal "o-a.no"
assert_equal "foobarfoooo.oslo.no"
assert_equal "02600.no"
assert_equal_comp "02bjli.norsknettskole.no" "norsknettskole.no"
assert_equal "0330.no"
assert_equal "123førstehjelp.no"
assert_equal_comp "02bat.norwegianbroker.no" "norwegianbroker.no"
assert_equal_comp "123ror.no123ferdig.no" "no123ferdig.no"
assert_equal_comp "123ror.rrno123ferdig.no" "rrno123ferdig.no"
assert_equal "1sol.no"
assert_equal "sol1.no"
assert_equal_comp "123ror.no123ferdig.no" "no123ferdig.no"
assert_equal "123áàäčçđéèêŋń-ñóòôöšŧüžæøå123.no"
assert_empty "1c.nov.ru"
echo "[INFO] All tests complete"