shortcode/tests.c

64 lines
1.7 KiB
C
Raw Normal View History

2023-07-10 15:51:21 +00:00
#include <cgreen/cgreen.h>
2023-07-12 19:22:54 +00:00
#include <bglibs/str.h>
2023-07-10 15:51:21 +00:00
#include "shortcodes.h"
Describe(parse);
BeforeEach(parse) {}
AfterEach(parse) {}
2023-07-12 19:22:54 +00:00
shortcode *result;
str s;
chunk_s(char *buffer, chunk c){
str_copyb(&s, buffer + c.start, c.len);
}
Ensure(parse, empty_string)
{
2023-07-12 19:09:17 +00:00
char *input = "";
2023-07-12 19:22:54 +00:00
result = parse(input);
// This means no shortcodes in it
assert_that(result[0].name.len, is_equal_to(0));
2023-07-10 15:51:21 +00:00
}
2023-07-12 19:22:54 +00:00
Ensure(parse, simple_shortcode)
{
2023-07-12 20:10:55 +00:00
char *input = "foobar {{% shortcode %}}blah";
2023-07-12 19:22:54 +00:00
result = parse(input);
2023-07-12 19:49:46 +00:00
// Only 1 shortcode
assert_that(result[1].name.len, is_equal_to(0));
// It's a simple one called shortcode, no args
2023-07-12 20:10:55 +00:00
chunk_s(input, result[0].name);
2023-07-12 19:49:46 +00:00
assert_that(s.s, is_equal_to_string("shortcode"));
assert_that(result[0].matching, is_equal_to(0));
assert_that(result[0].argcount, is_equal_to(0));
2023-07-12 20:10:55 +00:00
chunk_s(input, result[0].whole);
assert_that(s.s, is_equal_to_string("{{% shortcode %}}"));
2023-07-12 19:49:46 +00:00
}
Ensure(parse, matching_shortcode)
{
char *input = "{{% shortcode %}}foo bar{{% /shortcode %}}";
result = parse(input);
chunk_s(input, result[0].name);
// Only 1 shortcode
2023-07-12 20:10:55 +00:00
assert_that(result[1].name.len, is_equal_to(0));
2023-07-12 19:49:46 +00:00
// It's a matching one called shortcode, no args
2023-07-12 19:22:54 +00:00
assert_that(s.s, is_equal_to_string("shortcode"));
2023-07-12 19:49:46 +00:00
assert_that(result[0].matching, is_equal_to(1));
2023-07-12 19:22:54 +00:00
assert_that(result[0].argcount, is_equal_to(0));
}
2023-07-10 15:51:21 +00:00
2023-07-12 19:22:54 +00:00
int main(int argc, char **argv)
{
str_init(&s);
2023-07-10 15:51:21 +00:00
TestSuite *suite = create_test_suite();
2023-07-12 19:09:17 +00:00
add_test_with_context(suite, parse, empty_string);
2023-07-12 19:22:54 +00:00
add_test_with_context(suite, parse, simple_shortcode);
2023-07-12 19:49:46 +00:00
add_test_with_context(suite, parse, matching_shortcode);
2023-07-10 15:51:21 +00:00
return run_test_suite(suite, create_text_reporter());
}