blob: 1cd668f7e3deba631442a63fe51d9f4d7369baea (
plain)
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
|
#!/bin/sh
PARSECONF="./dist/parseconf"
SIMPLECONF="./test/simple.conf"
test_simple_loading () {
cat ${SIMPLECONF} | ${PARSECONF} > /dev/null
}
test_simple_parsing () {
config="
key value
"
retval=$(printf "$config" | ${PARSECONF} key)
[ "$retval" = "key:value" ]
}
test_bad_formatting () {
config="
key value
"
retval=$(printf "$config" | ${PARSECONF} key)
[ "$retval" = "key:value" ]
}
test_unecessary_semicolons () {
config="
key value;
"
retval=$(printf "$config" | ${PARSECONF} key)
[ "$retval" = "key:value" ]
}
test_extra_unecessary_semicolons () {
config="
key value;;;;;
"
retval=$(printf "$config" | ${PARSECONF} key)
[ "$retval" = "key:value" ]
}
test_mutlikey_parsing() {
config="
key1 value1
key2 value2
key3 value3
key4 value4
"
retval=$(printf "$config" | ${PARSECONF} key2)
[ "$retval" = "key2:value2" ]
}
test_comments_parsing() {
config="
#key1 value1
#key2 value2
# this is a comment
#key4 value4
dict {
#nothing here
}
"
retval=$(printf "$config" | ${PARSECONF} )
[ "x$retval" = "x" ]
}
test_list_parsing() {
config="
list [
a
b
c
d
e
]
"
retval=$(printf "$config" | ${PARSECONF} list)
[ "$retval" = "list:a b c d e " ]
}
test_dict_parsing() {
config="
dict {
a 1
b 2
c 3
d 4
e 5
}
"
retval=$(printf "$config" | ${PARSECONF} dict.a)
[ "$retval" = "dict.a:1" ]
}
test_file_input () {
retval=$(${PARSECONF} -f ${SIMPLECONF} key2)
[ "$retval" = "key2:value2" ]
}
test_include () {
config="
include test/simple.conf
"
retval=$(printf "$config" | ${PARSECONF} key2)
[ "$retval" = "key2:value2" ]
}
test_glob_matching () {
config="
dict {
a 1
b 2
c 3
d 4
}
"
retval=$(printf "$config" | ${PARSECONF} "dict.*" | wc -l)
[ "$retval" = "4" ]
}
test_glob_max_count () {
config="
dict {
a 1
b 2
c 3
d 4
}
"
retval=$(printf "$config" | ${PARSECONF} -c 1 "dict.*")
[ "$retval" = "dict.a:1" ]
}
|