-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
48 lines (41 loc) · 1.21 KB
/
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
testBRE() {
grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$' <<< '10.0.0.10'
assertTrue "$?"
gsed '/^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$/Q1' <<< '10.0.0.10'
assertFalse "$?"
}
testBREnawk() {
awk '/^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/{exit 1}' <<< '10.0.0.10'
assertFalse "$?"
gawk '/^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/{exit 1}' <<< '10.0.0.10'
assertFalse "$?"
}
testERE() {
grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' <<< '10.0.0.10'
assertTrue "$?"
grep -E -q '^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$' <<< '10.0.0.10'
assertTrue "$?"
gsed -E '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/Q1' <<< '10.0.0.10'
assertFalse "$?"
}
testEREshorter() {
grep -E -q '^([0-9]+(\.|$)){4}' <<< '10.0.0.10'
assertTrue "$?"
gsed -E '/^([0-9]+(\.|$)){4}/Q1' <<< '10.0.0.10'
assertFalse "$?"
}
testPCRE() {
perl -ne '/^\d+\.\d+\.\d+\.\d+$/ and exit 1' <<< '10.0.0.10'
assertFalse "$?"
}
testPCREshorter() {
perl -ne '/^(\d+(\.|$)){4}/ and exit 1' <<< '10.0.0.10'
assertFalse "$?"
perl -ne '/(\d+(\.|\b)){4}/ and exit 1' <<< '10.0.0.10'
assertFalse "$?"
}
testPCRERuby() {
ruby -ne '/^(\d+[\.$]){4}/ and exit 1' <<< '10.0.0.10'
assertFalse "$?"
}
. shunit2