diff options
| author | davidovski <david@davidovski.xyz> | 2022-02-13 17:52:07 +0000 | 
|---|---|---|
| committer | davidovski <david@davidovski.xyz> | 2022-02-13 17:52:07 +0000 | 
| commit | 8ce674db7ea92f6b3e551280b462c4f52ac74116 (patch) | |
| tree | b9783423018abeedb66fd96916788c4157acbeb9 /test | |
| parent | 355a513ee8ca5ce04a323c0a3fa6f20779dcc4fd (diff) | |
added test suite for parseconf
Diffstat (limited to 'test')
| -rw-r--r-- | test/external.conf | 4 | ||||
| -rwxr-xr-x | test/parseconf.sh | 121 | ||||
| -rw-r--r-- | test/simple.conf | 18 | ||||
| -rw-r--r-- | test/test.conf | 2 | 
4 files changed, 145 insertions, 0 deletions
| diff --git a/test/external.conf b/test/external.conf new file mode 100644 index 0000000..05f61d8 --- /dev/null +++ b/test/external.conf @@ -0,0 +1,4 @@ +external1 value +external2 value +external3 value +external4 value diff --git a/test/parseconf.sh b/test/parseconf.sh new file mode 100755 index 0000000..3095e18 --- /dev/null +++ b/test/parseconf.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +PARSECONF="./src/parseconf" + +SIMPLECONF="./test/simple.conf" + +test_simple_loading () { +    cat ${SIMPLECONF} | ${PARSECONF} > /dev/null +} + +test_simple_parsing () { +    config=" +key value +    " +    retval=$(${PARSECONF} key <<< "$config") +    [ "$retval" = "key:value" ] +} + +test_bad_formatting () { +    config=" +      key       value     +    " +    retval=$(${PARSECONF} key <<< "$config") +    [ "$retval" = "key:value" ] +} + +test_unecessary_semicolons () { +    config=" +key value; +    " +    retval=$(${PARSECONF} key <<< "$config") +    [ "$retval" = "key:value" ] +} + +test_extra_unecessary_semicolons () { +    config=" +key value;;;;; +    " +    retval=$(${PARSECONF} key <<< "$config") +    [ "$retval" = "key:value" ] +} + +test_mutlikey_parsing() { +    config=" +key1 value1 +key2 value2 +key3 value3 +key4 value4 +    " +    retval=$(${PARSECONF} key2 <<< "$config") +    [ "$retval" = "key2:value2" ] +} + + +test_list_parsing() { +    config=" +list [ +    a +    b +    c +    d +    e +] +    " +    retval=$(${PARSECONF} list <<< "$config") +    [ "$retval" = "list:a b c d e " ] +} + +test_dict_parsing() { +    config=" +dict { +    a 1 +    b 2 +    c 3 +    d 4 +    e 5 +} +    " +    retval=$(${PARSECONF} dict.a <<< "$config") +    [ "$retval" = "dict.a:1" ] +} + +test_file_input () { +    retval=$(${PARSECONF} -f ${SIMPLECONF} key2) +    [ "$retval" = "key2:value2" ] +} + +test_include () { +    config=" +include test/simple.conf +    " +    retval=$(${PARSECONF} key2 <<< "$config") +    [ "$retval" = "key2:value2" ] +} + +test_glob_matching () { +    config=" +dict { +    a 1 +    b 2 +    c 3 +    d 4 +} +    " +    retval=$(${PARSECONF} "dict.*" <<< "$config" | wc -l) +    [ "$retval" = "4" ] +} + +test_glob_max_count () { +    config=" +dict { +    a 1 +    b 2 +    c 3 +    d 4 +} +    " +    retval=$(${PARSECONF} -c 1 "dict.*" <<< "$config") +    [ "$retval" = "dict.d:4" ] +} + diff --git a/test/simple.conf b/test/simple.conf new file mode 100644 index 0000000..605f3f5 --- /dev/null +++ b/test/simple.conf @@ -0,0 +1,18 @@ +key1 value1 +key2 value2 +key3 value3 +key4 value4 + +dict { +    a 1 +    b 2 +    c 3 +    d 4 +} + +list [ +    alpha +    beta +    gamma +    delta +] diff --git a/test/test.conf b/test/test.conf new file mode 100644 index 0000000..139597f --- /dev/null +++ b/test/test.conf @@ -0,0 +1,2 @@ + + | 
