From cbc7358b66ed3b7885045c43072f29fe6945f023 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Fri, 30 Jan 2015 20:35:35 +0100 Subject: [PATCH] add a test that shows a bug in h_seq_index_path --- src/t_misc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/t_misc.c b/src/t_misc.c index 92c2b326..31d82eaa 100644 --- a/src/t_misc.c +++ b/src/t_misc.c @@ -2,6 +2,8 @@ #include <string.h> #include "test_suite.h" #include "hammer.h" +#include "internal.h" +#include "glue.h" static void test_tt_user(void) { g_check_cmp_int32(TT_USER, >, TT_NONE); @@ -29,7 +31,28 @@ static void test_tt_registry(void) { g_check_cmp_int32(h_get_token_type_number("com.upstandinghackers.test.unkown_token_type"), ==, 0); } +static void test_seq_index_path(void) { + HArena *arena = h_new_arena(&system_allocator, 0); + + HParsedToken *seq = h_make_seqn(arena, 1); + HParsedToken *seq2 = h_make_seqn(arena, 2); + HParsedToken *tok1 = h_make_uint(arena, 41); + HParsedToken *tok2 = h_make_uint(arena, 42); + + seq->seq->elements[0] = seq2; + seq->seq->used = 1; + seq2->seq->elements[0] = tok1; + seq2->seq->elements[1] = tok2; + seq2->seq->used = 2; + + g_check_cmp_int(h_seq_index_path(seq, 0, -1)->token_type, ==, TT_SEQUENCE); + g_check_cmp_int(h_seq_index_path(seq, 0, 0, -1)->token_type, ==, TT_UINT); + g_check_cmp_int64(h_seq_index_path(seq, 0, 0, -1)->uint, ==, 41); + g_check_cmp_int64(h_seq_index_path(seq, 0, 1, -1)->uint, ==, 42); +} + void register_misc_tests(void) { g_test_add_func("/core/misc/tt_user", test_tt_user); g_test_add_func("/core/misc/tt_registry", test_tt_registry); + g_test_add_func("/core/misc/seq_index_path", test_seq_index_path); } -- GitLab