return errors from parse() #1
6
Makefile
6
Makefile
@ -2,10 +2,8 @@ CC=gcc
|
||||
all: test
|
||||
shortcodes.c: shortcodes.rl
|
||||
ragel -G2 -L shortcodes.rl -o shortcodes.c
|
||||
%.o: %.c
|
||||
$(CC) -fPIC -c -o $@ $^ -g
|
||||
tests.so: shortcodes.o tests.o
|
||||
$(CC) -shared -g -o $@ $^ -lbg -lcgreen
|
||||
tests.so: shortcodes.c tests.c
|
||||
$(CC) -fPIC -shared -g -o $@ $^ -lbg -lcgreen
|
||||
clean:
|
||||
rm -f shortcodes.c *.o *.so tests
|
||||
test: tests.so
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef SHORTCODES_H
|
||||
#define SHORTCODES_H
|
||||
#pragma once
|
||||
|
||||
// A chunk is a reference to a piece of string
|
||||
// from "start" relative to its start
|
||||
@ -46,9 +45,8 @@ Example:
|
||||
|
||||
{{% foo %}} {{% /bar %}}
|
||||
*/
|
||||
#define ERR_MISMATCHED_CLOSING_TAG 1;
|
||||
#define ERR_MISMATCHED_CLOSING_TAG 1
|
||||
#define ERR_MISMATCHED_BRACKET 2
|
||||
|
||||
|
||||
sc_result parse(char *);
|
||||
|
||||
#endif
|
||||
|
@ -58,6 +58,9 @@
|
||||
// Since it's mismatched, remove the name
|
||||
sc_list[c_sc].name.start = 0;
|
||||
sc_list[c_sc].name.len=0;
|
||||
result.errors[result.errcount].position = p-start-2;
|
||||
result.errors[result.errcount].code = ERR_MISMATCHED_BRACKET;
|
||||
result.errcount++;
|
||||
};
|
||||
|
||||
shortcode = ((start_p content end_p) | (start_b content end_b))
|
||||
|
4
tests.c
4
tests.c
@ -45,6 +45,10 @@ Ensure(parse, mismatched_brackets)
|
||||
result = parse(input);
|
||||
// No shortcodes
|
||||
assert_that(result.sc[0].name.len, is_equal_to(0));
|
||||
assert_that(result.errcount, is_equal_to(1));
|
||||
assert_that(result.errors[0].code, is_equal_to(ERR_MISMATCHED_BRACKET));
|
||||
str_copyb(&s, input + result.errors[0].position, 3);
|
||||
assert_that(s.s, is_equal_to_string(">}}"));
|
||||
}
|
||||
|
||||
Ensure(parse, mismatched_brackets_inside_data_are_ok)
|
||||
|
Loading…
Reference in New Issue
Block a user