diff --git a/Makefile b/Makefile index a0ab9d9..070a97c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,13 @@ +CC=tcc +all: tests run: shortcodes ./shortcodes shortcodes.c: shortcodes.rl ragel -G2 shortcodes.rl -o shortcodes.c shortcodes: shortcodes.c - tcc shortcodes.c -lbg -g -o shortcodes + $(CC) shortcodes.c -lbg -g -o shortcodes +tests: shortcodes.c shortcodes.h tests.c + $(CC) tests.c shortcodes.c -lbg -lcgreen -g -o tests + ./tests +clean: + rm -f shortcodes shortcodes.c diff --git a/shortcodes.h b/shortcodes.h index 5cfab9b..e3e4a5e 100644 --- a/shortcodes.h +++ b/shortcodes.h @@ -1 +1,4 @@ -char *parse(char *); +#ifndef SHORTCODES_H +#define SHORTCODES_H +int parse(char *); +#endif diff --git a/shortcodes.rl b/shortcodes.rl index e0030fd..cb81242 100644 --- a/shortcodes.rl +++ b/shortcodes.rl @@ -159,13 +159,9 @@ int parse(char *input) { return 0; } -int main(int argc, char **argv) { - parse( -"bbb{{% sarasa sar1 sar2 \"sar3\" %}}ccc -{{< c1 arg2 >}}foobar{{% /c1%}}aaa{{% sarasa name=\"pepe\" %}}"); - // if (output == 0) { - // printf("parse error\n"); - // return 1; - // } - return 0; -} +// int main(int argc, char **argv) { +// parse( +// "bbb{{% sarasa sar1 sar2 \"sar3\" %}}ccc" +// "{{< c1 arg2 >}}foobar{{% /c1%}}aaa{{% sarasa name=\"pepe\" %}}"); +// return 0; +// }; diff --git a/tests.c b/tests.c index 7fb9b5e..6d84b0f 100755 --- a/tests.c +++ b/tests.c @@ -1,22 +1,19 @@ -#!/usr/bin/tcc -run -lcgreen shortcodes.c bstrlib/bstrlib.c #include #include "shortcodes.h" -#include "bstrlib/bstrlib.h" Describe(parse); BeforeEach(parse) {} AfterEach(parse) {} -Ensure(parse, is_identity) { - char *input = "hello"; - bstring output = parse(input); - printf("%s / %s", output->data, input); - assert_that(output->data, is_equal_to_string("hello!")); +Ensure(parse, empty_string) { + char *input = ""; + int output = parse(input); + assert_that(output, is_equal_to(0)); } int main(int argc, char **argv) { TestSuite *suite = create_test_suite(); - add_test_with_context(suite, parse, is_identity); + add_test_with_context(suite, parse, empty_string); return run_test_suite(suite, create_text_reporter()); }