From 1cf292d3e51550e4d78ad94ed54c029c085c9625 Mon Sep 17 00:00:00 2001 From: Kyler Date: Sat, 1 Nov 2025 00:04:37 -0600 Subject: [PATCH] Implemented test_array_struct_inline_value test helper function --- SLS_C/include/sls/lexer.h | 6 +++--- SLS_C/tests/lexer_tests.c | 26 ++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/SLS_C/include/sls/lexer.h b/SLS_C/include/sls/lexer.h index 2f8fa71..80992aa 100644 --- a/SLS_C/include/sls/lexer.h +++ b/SLS_C/include/sls/lexer.h @@ -131,8 +131,8 @@ typedef struct { } TypeTuple; typedef struct { - TokenString values; - Identifier name; + void **values; + const char *name; } StructInline; typedef struct ArrayLiteral { @@ -146,7 +146,7 @@ typedef struct ArrayLiteral { Boolean *boolean_literals; // type == ARRAY_BOOLEAN TokenString *token_strings; // type == ARRAY_TOKEN_STRING TypeTuple *type_tuples; // type == ARRAY_TYPE_TUPLE - StructInline *type_tuples; // type == ARRAY_STRUCT_INLINE + StructInline struct_inline; // type == ARRAY_STRUCT_INLINE }; size_t *shape; size_t dimensions; diff --git a/SLS_C/tests/lexer_tests.c b/SLS_C/tests/lexer_tests.c index 3f60177..f11f625 100644 --- a/SLS_C/tests/lexer_tests.c +++ b/SLS_C/tests/lexer_tests.c @@ -492,13 +492,31 @@ static Boolean test_array_boolean_value(LexerTest *test, LexerResult result, siz return FALSE; } -static Boolean test_array_struct_inline_value(LexerTest *test, LexerResult result, size_t i, void *values, size_t *shape, size_t dimensions) { - error_test(test, result, (SlsError) { .message = "Test case not implemented!", .code = 984, }); - // TODO - return TRUE; +static Boolean test_array_struct_inline_value(LexerTest *test, LexerResult result, size_t i, size_t struct_name_length, const char *struct_name, Boolean (*struct_handler)(LexerTest *, LexerResult, size_t, size_t, void *, void *), void **values, size_t *shape, size_t dimensions) { + static const ArrayType array_type = ARRAY_STRUCT_INLINE; + LexerTokenResult *head = get_token(result.result, i); + if (test_array_type(test, result, i, array_type, shape, dimensions)) { + return TRUE; + } if (strncmp(head->result.array_literal.struct_inline.name, struct_name, struct_name_length)) { + logic_fail_test(test, result, token_value_string_should_be(i + 1, ARRAY_STRUCT_INLINE, struct_name_length, struct_name, head->result.array_literal.struct_inline.name)); + return TRUE; + } + size_t length = 1; + for (int j = 0; j < dimensions; j++) length *= shape[j]; + for (int j = 0; j < length; j++) { + if (struct_handler(test, result, i, j, head->result.array_literal.struct_inline.values[j], values[j])) { + return TRUE; + } + } + return FALSE; } static Boolean test_token_string_value(LexerTest *test, LexerResult result, size_t i, void *value) { + static const TokenType token_type = TOKEN_TOKEN_STRING; + LexerTokenResult *head = get_token(result.result, i); + if (test_token_type(test, result, i, token_type)) { + return TRUE; + } error_test(test, result, (SlsError) { .message = "Test case not implemented!", .code = 984, }); // TODO return TRUE;