diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-02-24 23:15:28 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-02-24 23:15:28 +0100 |
commit | fb27e8ed5030e6b5aa8df33cc4d347eacaef76ba (patch) | |
tree | 35f634c605ae01c195408ffb4334da43b89f4c07 /tests/blogc-make | |
parent | 144f49bdee2dd7d29748d2c3d2e3c0e5cfbfa34d (diff) | |
download | blogc-fb27e8ed5030e6b5aa8df33cc4d347eacaef76ba.tar.gz blogc-fb27e8ed5030e6b5aa8df33cc4d347eacaef76ba.tar.bz2 blogc-fb27e8ed5030e6b5aa8df33cc4d347eacaef76ba.zip |
make: parse runserver arguments from cli, instead of env
this is some over-optimized parser, to celebrate #cloudbleed :D
Diffstat (limited to 'tests/blogc-make')
-rw-r--r-- | tests/blogc-make/check_rules.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/blogc-make/check_rules.c b/tests/blogc-make/check_rules.c new file mode 100644 index 0000000..0ef8be7 --- /dev/null +++ b/tests/blogc-make/check_rules.c @@ -0,0 +1,104 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2015-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include <stdlib.h> +#include <string.h> + +#include "../../src/blogc-make/rules.h" +#include "../../src/common/utils.h" + + +static void +test_rule_parse_args(void **state) +{ + bc_trie_t *t = bm_rule_parse_args("bola:foo=" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 1); + assert_string_equal(bc_trie_lookup(t, "foo"), ""); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=bar" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 1); + assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=,baz=lol" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 2); + assert_string_equal(bc_trie_lookup(t, "foo"), ""); + assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=bar,baz=" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 2); + assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); + assert_string_equal(bc_trie_lookup(t, "baz"), ""); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=bar,baz=lol" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 2); + assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); + assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=,baz=lol,asd=qwe" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 3); + assert_string_equal(bc_trie_lookup(t, "foo"), ""); + assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); + assert_string_equal(bc_trie_lookup(t, "asd"), "qwe"); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=bar,baz=,asd=qwe" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 3); + assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); + assert_string_equal(bc_trie_lookup(t, "baz"), ""); + assert_string_equal(bc_trie_lookup(t, "asd"), "qwe"); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 3); + assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); + assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); + assert_string_equal(bc_trie_lookup(t, "asd"), ""); + bc_trie_free(t); + t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=qwe" + 4); + assert_non_null(t); + assert_int_equal(bc_trie_size(t), 3); + assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); + assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); + assert_string_equal(bc_trie_lookup(t, "asd"), "qwe"); + bc_trie_free(t); +} + + +static void +test_rule_parse_args_error(void **state) +{ + assert_null(bm_rule_parse_args(NULL)); + assert_null(bm_rule_parse_args("bola" + 4)); + assert_null(bm_rule_parse_args("bola:" + 4)); + assert_null(bm_rule_parse_args("bola:asd" + 4)); + assert_null(bm_rule_parse_args("bola:asd=foo,lol" + 4)); + assert_null(bm_rule_parse_args("bola:asd=foo,qwe=bar,lol" + 4)); + assert_null(bm_rule_parse_args("bolaasd" + 4)); +} + + +int +main(void) +{ + const UnitTest tests[] = { + unit_test(test_rule_parse_args), + unit_test(test_rule_parse_args_error), + }; + return run_tests(tests); +} |