Merge remote-tracking branch 'upstream/master' into fix-wrong_bit_length

This commit is contained in:
Sven M. Hallberg 2015-09-26 18:09:58 +02:00
commit 89e675bd2a
5 changed files with 92 additions and 39 deletions

View file

@ -141,13 +141,24 @@ static void test_wrong_bit_length(void) {
static void test_lalr_charset_lhs(void) {
HParserBackend be = PB_LALR;
HParser *p = h_choice(h_ch('A'), h_uint8(), NULL);
HParser *p = h_many(h_choice(h_sequence(h_ch('A'), h_ch('B'), NULL),
h_in((uint8_t*)"AB",2), NULL));
// the above would fail to compile because of an unhandled case in trying
// to resolve a conflict where an item's left-hand-side was an HCF_CHARSET.
// the above would abort because of an unhandled case in trying to resolve
// a conflict where an item's left-hand-side was an HCF_CHARSET.
// however, the compile should fail - the conflict cannot be resolved.
g_check_parse_match(p, be, "A",1, "u0x41");
g_check_parse_match(p, be, "B",1, "u0x42");
if(h_compile(p, be, NULL) == 0) {
g_test_message("LALR compile didn't detect ambiguous grammar");
// it says it compiled it - well, then it should parse it!
// (this helps us see what it thinks it should be doing.)
g_check_parse_match(p, be, "AA",2, "(u0x41 u0x41)");
g_check_parse_match(p, be, "AB",2, "((u0x41 u0x42))");
g_test_fail();
return;
}
}
static void test_cfg_many_seq(void) {
@ -160,6 +171,28 @@ static void test_cfg_many_seq(void) {
// reshape on h_many.
}
static uint8_t test_charset_bits__buf[256];
static void *test_charset_bits__alloc(HAllocator *allocator, size_t size)
{
g_check_cmp_uint64(size, ==, 256/8);
assert(size <= 256);
return test_charset_bits__buf;
}
static void test_charset_bits(void) {
// charset would allocate 256 bytes instead of 256 bits (= 32 bytes)
HAllocator alloc = {
.alloc = test_charset_bits__alloc,
.realloc = NULL,
.free = NULL,
};
test_charset_bits__buf[32] = 0xAB;
HCharset cs = new_charset(&alloc);
for(size_t i=0; i<32; i++)
g_check_cmp_uint32(test_charset_bits__buf[i], ==, 0);
g_check_cmp_uint32(test_charset_bits__buf[32], ==, 0xAB);
}
void register_regression_tests(void) {
g_test_add_func("/core/regression/bug118", test_bug118);
g_test_add_func("/core/regression/seq_index_path", test_seq_index_path);
@ -168,4 +201,5 @@ void register_regression_tests(void) {
g_test_add_func("/core/regression/wrong_bit_length", test_wrong_bit_length);
g_test_add_func("/core/regression/lalr_charset_lhs", test_lalr_charset_lhs);
g_test_add_func("/core/regression/cfg_many_seq", test_cfg_many_seq);
g_test_add_func("/core/regression/charset_bits", test_charset_bits);
}