-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclt-test.sh
executable file
·127 lines (101 loc) · 2.35 KB
/
clt-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
# ---- Colors ----
COLOR_FAILURE='\033[0;31m'
COLOR_SUCCESS='\033[0;32m'
COLOR_NC='\033[0m' # No Color
function error {
echo "${COLOR_FAILURE}$1${COLOR_NC}"
exit 1
}
function success {
echo "${COLOR_SUCCESS}$1${COLOR_NC}"
}
# ---- Files ----
json=Playground/People.json
plist=Playground/People.plist
xml=Playground/People.xml
function format {
echo "${1##*.}"
}
# ---- Test functions ----
function testGet {
fileFormat=`format $3`
expected=$2
result=`scout $1 -i $3`
if [ "$result" != "$expected" ]; then
error "Error $fileFormat get. '$1' = $result != $expected"
fi
}
function testGetAll {
expected=$2
echo "Testing get at '$1'..."
testGet "$1" "$2" $json
testGet "$1" "$2" $plist
testGet "$1" "$2" $xml
success "All test formats passed"
echo ""
}
function testSet {
fileFormat=`format $3`
modified=`scout set "$1=$2" -i $3 -v`
valueAtPath=`echo "$modified" | scout $1`
if [ "$valueAtPath" != "$2" ]; then
error "Error $fileFormat set. '$1': expected $2 and got $valueAtPath"
fi
}
function testSetAll {
expected=$2
echo "Testing set at '$1'..."
testSet "$1" "$2" $json
testSet "$1" "$2" $plist
testSet "$1" "$2" $xml
success "All test formats passed"
echo ""
}
# ---- Tests ----
# Get
echo "-- Testing Get --"
testGetAll people.Tom.height 175
testGetAll people.Tom.hobbies[-1] guitar
testGetAll people.Tom.hobbies[0] cooking
testGetAll people.Suzanne.movies[0].title "Tomorrow is so far"
testGetAll people.Robert.running_records[1][0] 9
# -- Test dictionary --
TomJson='{
"age" : 68,
"hobbies" : [
"cooking",
"guitar"
],
"height" : 175
}'
testGet people.Tom "$TomJson" $json
TomPlist='<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>age</key>
<integer>68</integer>
<key>height</key>
<integer>175</integer>
<key>hobbies</key>
<array>
<string>cooking</string>
<string>guitar</string>
</array>
</dict>
</plist>'
testGet people.Tom "$TomPlist" $plist
TomXml='<Tom>
<height>175</height>
<age>68</age>
<hobbies>
<hobby>cooking</hobby>
<hobby>guitar</hobby>
</hobbies>
</Tom>'
testGet people.Tom "$TomXml" $xml
# Set
echo "-- Testing Set --"
testSetAll people.Robert.age 60
testSetAll people.Suzanne.movies[1].title "Never gonna die"
testSetAll people.Robert.running_records[0][2] 15