summaryrefslogtreecommitdiffstats
path: root/tests/parse_control.sh
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-25 17:51:42 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-25 17:56:54 (EDT)
commit56b3636acd3106b46ec0ebfe5a08434a2fd423c1 (patch)
treee3a2483b9b20230a15ef7f93dadfa2c1ac89753d /tests/parse_control.sh
parent3031ace14b82d02324b366665ae779485c04d516 (diff)
tests/parse_control.sh: New test file
Diffstat (limited to 'tests/parse_control.sh')
-rwxr-xr-xtests/parse_control.sh166
1 files changed, 166 insertions, 0 deletions
diff --git a/tests/parse_control.sh b/tests/parse_control.sh
new file mode 100755
index 0000000..caf0a29
--- /dev/null
+++ b/tests/parse_control.sh
@@ -0,0 +1,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
+}