summaryrefslogtreecommitdiffstats
path: root/tests/parse_control.sh
blob: caf0a297b7c9e00be7231477c7bcfa29fbf46f61 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# parse_control() tests
#
# Copyright (C) 2019  Patrick McDermott
#
# This file is part of the ProteanOS Development Kit.
#
# The ProteanOS Development Kit is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# The ProteanOS Development Kit is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the ProteanOS Development Kit.  If not, see
# <http://www.gnu.org/licenses/>.

LF='
'
CONTROL="$(cat <<-'EOF'
	Package: foo
	Version: 1.0
	Description: Frobnicator of Objects
	 This is a frobnicator of objects.  Conveniently, it also bit-bangs all
	 registers.

	Package: bar
	Version: 2.0
	Description: Bit-bang All Registers
	 This is a frobnicator of objects.  Conveniently, it also bit-bangs all
	 registers.
	EOF
	)"

field=0
para=0

field_1()
{
	local name="${1}"
	local value="${2}"
	shift 2

	is 'package field name' "${name}" 'Package'
	is 'package field value' "${value}" 'foo'

	return 0
}

field_2()
{
	local name="${1}"
	local value="${2}"
	shift 2

	is 'version field name' "${name}" 'Version'
	is 'version field value' "${value}" '1.0'

	return 0
}

field_3()
{
	local name="${1}"
	local value="${2}"
	shift 2

	is 'description field name' "${name}" 'Description'
	is_diff 'description field value' "${value}" "$(cat <<-'EOF'
	Frobnicator of Objects
	This is a frobnicator of objects.  Conveniently, it also bit-bangs all
	registers.
	EOF
	)"

	return 0
}

field_4()
{
	local name="${1}"
	local value="${2}"
	shift 2

	is 'package field name' "${name}" 'Package'
	is 'package field value' "${value}" 'bar'

	return 0
}

field_5()
{
	local name="${1}"
	local value="${2}"
	shift 2

	is 'version field name' "${name}" 'Version'
	is 'version field value' "${value}" '2.0'

	return 0
}

field_6()
{
	local name="${1}"
	local value="${2}"
	shift 2

	is 'description field name' "${name}" 'Description'
	is_diff 'description field value' "${value}" "$(cat <<-'EOF'
	Bit-bang All Registers
	This is a frobnicator of objects.  Conveniently, it also bit-bangs all
	registers.
	EOF
	)"

	return 0
}

field_7()
{
	bailout_ 'too many fields'
}

field_cb()
{
	field=$((${field} + 1))
	"field_${field}" "${@}"
}

para_1()
{
	is 'number of parsed fields' "${field}" 3
}

para_2()
{
	is 'number of parsed fields' "${field}" 6
}

para_3()
{
	bailout_ 'too many paragraphs'
}

para_cb()
{
	para=$((${para} + 1))
	"para_${para}" "${@}"
}

main()
{
	plan_ 15

	parse_control - field_cb para_cb 'Package' <<-EOF
		${CONTROL}
		EOF

	is 'number of parsed paragraphs' "${para}" 2

	return 0
}