diff --git a/Readme.md b/Readme.md index 19311ea..e024b98 100644 --- a/Readme.md +++ b/Readme.md @@ -1,11 +1,6 @@ -# Metadesk Library: RAD Debugger's Standalone Fork +# Metadesk Library -This is a fork that aims to make the latest version of metadesk available from the [RAD Debugger](https://github.com/EpicGamesExt/raddebugger) accessible as a library. - -**Note: This repo is under heavy WIP. Currently getting the code from RAD's (Epic Games) Debugger over to a standalone state while at the same time studying it.** -**Update:** This will contain just the minimal lib. Extra additions or the ability to generate variants are available at: [metadesk_libgen](https://github.com/Ed94/metadesk_libgen) - -docs will be updated referencing content procued by Ryan Fleury and content based on studying or resolving this library for this repo. +WIP: This hosts the raddbg's verion of mdesk module lifeted for use as a library. Intent is to get it working with tests & examples as the original was able to, then reduce the surface area of the base & os mdoules that it originally was dependent on to a minimal size. Before dependencies removal the modules will be hosted on a separate repo as a frozen state of their "libification". ## Documentation diff --git a/source/base/arena.h b/source/base/arena.h index c7d6166..8aec97d 100644 --- a/source/base/arena.h +++ b/source/base/arena.h @@ -106,11 +106,11 @@ void temp_arena_end(MD_TempArena temp); //- rjf: push helper macros -#ifndef md_push_array_ +#ifndef md_push_array #define md_push_array__no_zero_aligned(a, T, c, align) (T *)md_arena_push((a), sizeof(T) * (c), (align)) #define md_push_array__aligned(a, T, c, align) (T *)md_memory_zero(md_push_array__no_zero_aligned(a, T, c, align), sizeof(T) * (c)) #define md_push_array__no_zero(a, T, c) md_push_array__no_zero_aligned(a, T, c, md_max(8, md_align_of(T))) -#define md_push_array_(a, T, c) md_push_array__aligned (a, T, c, md_max(8, md_align_of(T))) +#define md_push_array(a, T, c) md_push_array__aligned (a, T, c, md_max(8, md_align_of(T))) #endif // Inlines diff --git a/source/base/command_line.h b/source/base/command_line.h index d687c5b..2441fd4 100644 --- a/source/base/command_line.h +++ b/source/base/command_line.h @@ -85,7 +85,7 @@ md_force_inline MD_CmdLine md_cmd_line_from_string_list__arena(MD_Arena* are inline MD_CmdLineOpt* md_cmd_line_opt_from_string(MD_CmdLine *cmd_line, MD_String8 name) { return md_cmd_line_opt_from_slot(md_cmd_line_slot_from_string(cmd_line, name), name); } inline MD_B32 md_cmd_line_has_flag (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0); } -inline MD_B32 md_cmd_line_has_argument (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0 && var->value_strings.md_node_count > 0); } +inline MD_B32 md_cmd_line_has_argument (MD_CmdLine *cmd_line, MD_String8 name) { MD_CmdLineOpt *var = md_cmd_line_opt_from_string(cmd_line, name); return(var != 0 && var->value_strings.node_count > 0); } inline MD_String8List md_cmd_line_strings(MD_CmdLine *cmd_line, MD_String8 name) { diff --git a/source/base/logger.c b/source/base/logger.c index 3a204a7..fd221f0 100644 --- a/source/base/logger.c +++ b/source/base/logger.c @@ -56,7 +56,7 @@ void md_log_scope_begin(void) { if (md_log_active != 0) { MD_U64 pos = md_arena_pos(md_log_active->arena); - MD_LogScope* scope = md_push_array_(md_log_active->arena, MD_LogScope, 1); + MD_LogScope* scope = md_push_array(md_log_active->arena, MD_LogScope, 1); scope->pos = pos; md_sll_stack_push(md_log_active->top_scope, scope); } diff --git a/source/base/logger.h b/source/base/logger.h index 2152919..6884916 100644 --- a/source/base/logger.h +++ b/source/base/logger.h @@ -58,7 +58,7 @@ md_log_alloc(MD_AllocatorInfo ainfo, MD_U64 md_arena_block_size) { md_arena_block_size = MD_LOG_DEFAULT_ARENA_BLOCK_SIZE; } MD_Arena* arena = md_arena_alloc(.backing = ainfo, .block_size = md_arena_block_size); - MD_Log* log = md_push_array_(arena, MD_Log, 1); + MD_Log* log = md_push_array(arena, MD_Log, 1); log->arena = arena; return log; } diff --git a/source/base/memory.h b/source/base/memory.h index f419b5e..8982eda 100644 --- a/source/base/memory.h +++ b/source/base/memory.h @@ -37,7 +37,7 @@ #endif #ifndef md_thousand -#define thousand(n) ((n) * 1000) +#define md_thousand(n) ((n) * 1000) #endif #ifndef md_million #define md_million(n) ((n) * 1000000) @@ -801,9 +801,9 @@ md_sll__queue_pop_nz(void* nil, void** f, void* f_next, void** l) #ifndef md_zero_struct # if MD_LANG_CPP -# define md_zero_struct {} +# define md_zero_struct() {} # else -# define md_zero_struct {0} +# define md_zero_struct() {0} # endif #endif diff --git a/source/base/strings.c b/source/base/strings.c index 3ff62dd..910c692 100644 --- a/source/base/strings.c +++ b/source/base/strings.c @@ -672,7 +672,7 @@ md_str8_path_list_resolve_dots_in_place(MD_String8List* path, MD_PathStyle style eliminate_stack_top: { - path->md_node_count -= 1; + path->node_count -= 1; path->total_size -= stack->node->string.size; md_sll_stack_pop(stack); @@ -1377,7 +1377,7 @@ md_fuzzy_match_find__ainfo(MD_AllocatorInfo ainfo, MD_String8 needle, MD_String8 } if (find_pos < haystack.size) { MD_Rng1U64 range = md_r1u64(find_pos, find_pos+needle_n->string.size); - MD_FuzzyMatchRangeNode* n = md_push_array_(scratch.arena, MD_FuzzyMatchRangeNode, 1); + MD_FuzzyMatchRangeNode* n = md_push_array(scratch.arena, MD_FuzzyMatchRangeNode, 1); n->range = range; md_sll_queue_push(result.first, result.last, n); result.count += 1; diff --git a/source/base/strings.h b/source/base/strings.h index dff7208..9881ffa 100644 --- a/source/base/strings.h +++ b/source/base/strings.h @@ -616,7 +616,7 @@ void md_str8_list_concat_in_place (MD_String8List* list, MD inline MD_String8Node* md_str8_list_push_node(MD_String8List* list, MD_String8Node* node) { md_sll_queue_push(list->first, list->last, node); - list->md_node_count += 1; + list->node_count += 1; list->total_size += node->string.size; return(node); } @@ -624,7 +624,7 @@ md_str8_list_push_node(MD_String8List* list, MD_String8Node* node) { inline MD_String8Node* md_str8_list_push_node_set_string(MD_String8List* list, MD_String8Node* node, MD_String8 string) { md_sll_queue_push(list->first, list->last, node); - list->md_node_count += 1; + list->node_count += 1; list->total_size += string.size; node->string = string; return(node); @@ -633,7 +633,7 @@ md_str8_list_push_node_set_string(MD_String8List* list, MD_String8Node* node, MD inline MD_String8Node* md_str8_list_push_node_front(MD_String8List* list, MD_String8Node* node) { md_sll_queue_push_front(list->first, list->last, node); - list->md_node_count += 1; + list->node_count += 1; list->total_size += node->string.size; return(node); } @@ -641,7 +641,7 @@ md_str8_list_push_node_front(MD_String8List* list, MD_String8Node* node) { inline MD_String8Node* md_str8_list_push_node_front_set_string(MD_String8List* list, MD_String8Node* node, MD_String8 string) { md_sll_queue_push_front(list->first, list->last, node); - list->md_node_count += 1; + list->node_count += 1; list->total_size += string.size; node->string = string; return(node); @@ -791,7 +791,7 @@ md_str8_list_from_flags__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list, MD_ inline MD_String8Array md_str8_array_from_list__ainfo(MD_AllocatorInfo ainfo, MD_String8List* list) { MD_String8Array array; - array.count = list->md_node_count; + array.count = list->node_count; array.v = md_alloc_array_no_zero(ainfo, MD_String8, array.count); MD_U64 idx = 0; for(MD_String8Node *n = list->first; n != 0; n = n->next, idx += 1) { @@ -1124,7 +1124,7 @@ MD_API MD_FuzzyMatchRangeList md_fuzzy_match_range_list_copy__ainfo(MD_Allocator #define md_fuzzy_match_range_list_copy(allocator, src) _Generic(allocator, MD_Arena*: md_fuzzy_match_range_list_copy__arena, MD_AllocatorInfo: md_fuzzy_match_range_list_copy__ainfo) md_generic_call(allocator, src) md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_find__arena (MD_Arena *arena, MD_String8 needle, MD_String8 haystack) { return md_fuzzy_match_find__ainfo (md_arena_allocator(arena), needle, haystack); } -md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_range_list_copy__arena(MD_Arena* arena, MD_FuzzyMatchRangeList* src) s{ return md_fuzzy_match_range_list_copy__ainfo(md_arena_allocator(arena), src); } +md_force_inline MD_FuzzyMatchRangeList md_fuzzy_match_range_list_copy__arena(MD_Arena* arena, MD_FuzzyMatchRangeList* src) { return md_fuzzy_match_range_list_copy__ainfo(md_arena_allocator(arena), src); } //////////////////////////////// //~ NOTE(allen): Serialization Helpers @@ -1221,7 +1221,7 @@ md_str8_serial_begin__ainfo(MD_AllocatorInfo ainfo, MD_String8List* srl) { MD_String8Node* node = md_alloc_array(ainfo, MD_String8Node, 1); node->string.str = md_alloc_array_no_zero(ainfo, MD_U8, 0); srl->first = srl->last = node; - srl->md_node_count = 1; + srl->node_count = 1; srl->total_size = 0; } diff --git a/source/mdesk/mdesk.c b/source/mdesk/mdesk.c index 31d2630..2c35fc4 100644 --- a/source/mdesk/mdesk.c +++ b/source/mdesk/mdesk.c @@ -6,6 +6,128 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) +MD_String8 +md_str8_stylize(MD_Arena* arena, MD_String8 string, MD_IdentifierStyle word_style, MD_String8 separator) +{ + MD_String8 result = md_zero_struct(); + MD_String8List words = md_zero_struct(); + + MD_B32 break_on_uppercase = 0; + { + break_on_uppercase = 1; + for (MD_U64 i = 0; i < string.size; i += 1) + { + if ( ! md_char_is_alpha(string.str[i]) && ! md_char_is_digit(string.str[i])) { + break_on_uppercase = 0; + break; + } + } + } + + MD_B32 making_word = 0; + MD_String8 word = md_zero_struct(); + for (MD_U64 i = 0; i < string.size;) + { + if (making_word) + { + + if ( (break_on_uppercase && md_char_is_upper(string.str[i])) || string.str[i] == '_' || md_char_is_space(string.str[i]) || i == string.size - 1) + { + if (i == string.size - 1) { + word.size += 1; + } + making_word = 0; + md_str8_list_push(arena, &words, word); + } + else + { + word.size += 1; + i += 1; + } + } + else + { + if(md_char_is_alpha(string.str[i])) + { + making_word = 1; + word.str = string.str + i; + word.size = 1; + } + i += 1; + } + } + + result.size = words.total_size; + if (words.node_count > 1) { + result.size += separator.size*(words.node_count-1); + } + result.str = md_push_array(arena, MD_U8*, result.size); + { + MD_U64 write_pos = 0; + for(MD_String8Node *node = words.first; node; node = node->next) + { + + // NOTE(rjf): Write word string to result. + { + MD_MemoryCopy(result.str + write_pos, node->string.str, node->string.size); + + // NOTE(rjf): Transform string based on word style. + switch(word_style) + { + case MD_IdentifierStyle_UpperCamelCase: + { + result.str[write_pos] = MD_CharToUpper(result.str[write_pos]); + for(MD_u64 i = write_pos+1; i < write_pos + node->string.size; i += 1) + { + result.str[i] = MD_CharToLower(result.str[i]); + } + }break; + + case MD_IdentifierStyle_LowerCamelCase: + { + MD_b32 is_first = (node == words.first); + result.str[write_pos] = (is_first ? + MD_CharToLower(result.str[write_pos]) : + MD_CharToUpper(result.str[write_pos])); + for(MD_u64 i = write_pos+1; i < write_pos + node->string.size; i += 1) + { + result.str[i] = MD_CharToLower(result.str[i]); + } + }break; + + case MD_IdentifierStyle_UpperCase: + { + for(MD_u64 i = write_pos; i < write_pos + node->string.size; i += 1) + { + result.str[i] = MD_CharToUpper(result.str[i]); + } + }break; + + case MD_IdentifierStyle_LowerCase: + { + for(MD_u64 i = write_pos; i < write_pos + node->string.size; i += 1) + { + result.str[i] = MD_CharToLower(result.str[i]); + } + }break; + + default: break; + } + + write_pos += node->string.size; + } + + if(node->next) + { + MD_MemoryCopy(result.str + write_pos, separator.str, separator.size); + write_pos += separator.size; + } + } + } + + return result; +} + //////////////////////////////// // MD_Context @@ -648,7 +770,7 @@ void md_parse__work_push(MD_ParseWorkKind work_kind, MD_Node* work_parent, MD_Pa { MD_ParseWorkNode* work_node = work_free; if (work_node == 0) { - work_node = md_push_array_(scratch->arena, MD_ParseWorkNode, 1); + work_node = md_push_array(scratch->arena, MD_ParseWorkNode, 1); } else { md_sll_stack_pop(work_free); diff --git a/source/mdesk/mdesk.h b/source/mdesk/mdesk.h index 5e17951..1120aca 100644 --- a/source/mdesk/mdesk.h +++ b/source/mdesk/mdesk.h @@ -6,6 +6,18 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) +// String Identifier Style +typedef enum MD_IdentifierStyle MD_IdentifierStyle; +enum MD_IdentifierStyle +{ + MD_IdentifierStyle_UpperCamelCase, + MD_IdentifierStyle_LowerCamelCase, + MD_IdentifierStyle_UpperCase, + MD_IdentifierStyle_LowerCase, +}; + +MD_API MD_String8 md_str8_stylize(MD_Arena* arena, MD_String8 string, MD_IdentifierStyle style, MD_String8 separator); + //////////////////////////////// //~ rjf: Messages @@ -325,9 +337,9 @@ MD_API MD_TokenArray md_token_array_from_chunk_list__ainfo (MD_AllocatorInfo ai #define md_token_chunk_list_push(allocator, list, cap, token) _Generic(allocator, MD_Arena*: md_token_chunk_list_push__arena, MD_AllocatorInfo: md_token_chunk_list_push__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, list, cap, token) #define md_token_array_from_chunk_list(allocator, chunks) _Generic(allocator, MD_Arena*: md_token_array_from_chunk_list__arena, MD_AllocatorInfo: md_token_array_from_chunk_list__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, chunks) -md_force_inline MD_String8List md_string_list_from_token_flags__arena(MD_Arena* arena, MD_TokenFlags flags) { return md_string_list_from_token_flags__ainfo(md_arena_allocator(arena), flags); } -md_force_inline void md_token_chunk_list_push__arena (MD_Arena* arena, MD_TokenChunkList* list, MD_U64 cap, MD_Token token) { md_token_chunk_list_push__ainfo(md_arena_allocator(arena), list, cap, token); } -md_force_inline MD_TokenArray md_token_array_from_chunk_list__arena (MD_Arena* arena, MD_TokenChunkList* chunks) { return md_token_array_from_chunk_list__ainfo(md_arena_allocator(arena), chunks); } +md_force_inline MD_String8List md_string_list_from_token_flags__arena(MD_Arena* arena, MD_TokenFlags flags) { return md_string_list_from_token_flags__ainfo(md_arena_allocator(arena), flags); } +md_force_inline void md_token_chunk_list_push__arena (MD_Arena* arena, MD_TokenChunkList* list, MD_U64 cap, MD_Token token) { md_token_chunk_list_push__ainfo(md_arena_allocator(arena), list, cap, token); } +md_force_inline MD_TokenArray md_token_array_from_chunk_list__arena (MD_Arena* arena, MD_TokenChunkList* chunks) { return md_token_array_from_chunk_list__ainfo(md_arena_allocator(arena), chunks); } inline MD_Token md_token_make(MD_Rng1U64 range, MD_TokenFlags flags) { @@ -593,7 +605,7 @@ MD_API MD_ParseResult md_parse_from_text__arena(MD_Arena* arena, MD_Strin MD_API MD_ParseResult md_parse_from_text__ainfo(MD_AllocatorInfo ainfo, MD_String8 filename, MD_String8 text); #define md_parse_from_text(allocator, filename, text) _Generic(allocator, MD_Arena*: md_parse_from_text__arena, MD_AllocatorInfo: md_parse_from_text__ainfo, default: md_assert_generic_sel_fail) md_generic_call(allocator, filename, text) -#define tree_from_string(allocator, string) (md_parse_from_text((allocator), md_str8_zero(), (string)).root) +#define md_tree_from_string(allocator, string) (md_parse_from_text((allocator), md_str8_zero(), (string)).root) md_force_inline MD_ParseResult md_parse_from_text__arena(MD_Arena* arena, MD_String8 filename, MD_String8 text) { return md_parse_from_text__ainfo(md_arena_allocator(arena), filename, text); } diff --git a/source/os/linux/os_linux.c b/source/os/linux/os_linux.c index 5fc6d64..2c2101a 100644 --- a/source/os/linux/os_linux.c +++ b/source/os/linux/os_linux.c @@ -50,7 +50,7 @@ md_os_lnx_thread_entry_point(void *ptr) { MD_OS_LNX_Entity* entity = (MD_OS_LNX_Entity *)ptr; MD_OS_ThreadFunctionType* func = entity->thread.func; - void* thread_ptr = entity->thread.ptr; + void* thread_ptr = entity->thread.ptr; MD_TCTX md_tctx_; md_tctx_init_and_equip(&md_tctx_); @@ -80,8 +80,8 @@ md_os_set_thread_name(MD_String8 name) { MD_TempArena scratch = md_scratch_begin(0, 0); { - MD_String8 name_copy = md_push_str8_copy(scratch.arena, name); - pthread_t current_thread = pthread_self(); + MD_String8 name_copy = md_push_str8_copy(scratch.arena, name); + pthread_t current_thread = pthread_self(); pthread_setname_np(current_thread, (char *)name_copy.str); } scratch_end(scratch); @@ -102,14 +102,14 @@ md_os_file_open(MD_OS_AccessFlags flags, MD_String8 path) { MD_TempArena scratch = md_scratch_begin(0, 0); { - MD_String8 path_copy = md_push_str8_copy(scratch.arena, path); - int lnx_flags = 0; + MD_String8 path_copy = md_push_str8_copy(scratch.arena, path); + int lnx_flags = 0; if (flags & (MD_OS_AccessFlag_Read | MD_OS_AccessFlag_Write)) { lnx_flags = O_RDWR; } - else if (flags & MD_OS_AccessFlag_Write) { lnx_flags = O_WRONLY; } - else if (flags & MD_OS_AccessFlag_Read) { lnx_flags = O_RDONLY; } - if (flags & MD_OS_AccessFlag_Append) { lnx_flags |= O_APPEND; } + else if (flags & MD_OS_AccessFlag_Write) { lnx_flags = O_WRONLY; } + else if (flags & MD_OS_AccessFlag_Read) { lnx_flags = O_RDONLY; } + if (flags & MD_OS_AccessFlag_Append) { lnx_flags |= O_APPEND; } - int fd = open((char *)path_copy.str, lnx_flags); + int fd = open((char *)path_copy.str, lnx_flags); MD_OS_Handle handle = {0}; if (fd != -1) { handle.u64[0] = fd; @@ -156,8 +156,8 @@ md_os_file_read(MD_OS_Handle file, MD_Rng1U64 rng, void* out_data) MD_U64 md_os_file_write(MD_OS_Handle file, MD_Rng1U64 rng, void *data) { - if(md_os_handle_match(file, md_os_handle_zero())) { return 0; } - + if (md_os_handle_match(file, md_os_handle_zero())) { return 0; } + int fd = (int)file.u64[0]; if (rng.md_min != 0) { lseek(fd, rng.md_min, SEEK_SET); @@ -183,20 +183,20 @@ md_os_file_write(MD_OS_Handle file, MD_Rng1U64 rng, void *data) MD_B32 md_os_file_set_times(MD_OS_Handle file, MD_DateTime date_time) { - if(md_os_handle_match(file, md_os_handle_zero())) { return 0; } + if (md_os_handle_match(file, md_os_handle_zero())) { return 0; } int fd = (int)file.u64[0]; timespec time = md_os_lnx_timespec_from_date_time(date_time); timespec times[2] = {time, time}; int futimens_result = futimens(fd, times); - MD_B32 good = (futimens_result != -1); + MD_B32 good = (futimens_result != -1); return good; } MD_FileProperties md_os_properties_from_file(MD_OS_Handle file) { - if(md_os_handle_match(file, md_os_handle_zero())) { return (MD_FileProperties){0}; } + if (md_os_handle_match(file, md_os_handle_zero())) { return (MD_FileProperties){0}; } int fd = (int)file.u64[0]; struct stat fd_stat = {0}; @@ -216,7 +216,7 @@ md_os_id_from_file(MD_OS_Handle file) struct stat fd_stat = {0}; int fstat_result = fstat(fd, &fd_stat); MD_OS_FileID id = {0}; - if(fstat_result != -1) { + if (fstat_result != -1) { id.v[0] = fd_stat.st_dev; id.v[1] = fd_stat.st_ino; } @@ -304,8 +304,8 @@ md_internal MD_FileProperties md_os_properties_from_file_path(MD_String8 path) { MD_FileProperties props = {0}; - MD_TempArena scratch = md_scratch_begin(0, 0); - MD_String8 path_copy = md_push_str8_copy(scratch.arena, path); + MD_TempArena scratch = md_scratch_begin(0, 0); + MD_String8 path_copy = md_push_str8_copy(scratch.arena, path); struct stat f_stat = {0}; int stat_result = stat((char *)path_copy.str, &f_stat); if (stat_result != -1) { @@ -445,7 +445,7 @@ md_os_shared_memory_alloc(MD_U64 size, MD_String8 name) { MD_TempArena scratch = md_scratch_begin(0, 0); MD_String8 name_copy = md_push_str8_copy(scratch.arena, name); - int id = shm_open((char *)name_copy.str, O_RDWR, 0); + int id = shm_open((char *)name_copy.str, O_RDWR, 0); ftruncate(id, size); scratch_end(scratch); MD_OS_Handle result = {(MD_U64)id}; @@ -457,7 +457,7 @@ md_os_shared_memory_open(MD_String8 name) { MD_TempArena scratch = md_scratch_begin(0, 0); MD_String8 name_copy = md_push_str8_copy(scratch.arena, name); - int id = shm_open((char *)name_copy.str, O_RDWR, 0); + int id = shm_open((char *)name_copy.str, O_RDWR, 0); scratch_end(scratch); MD_OS_Handle result = {(MD_U64)id}; return result; @@ -491,7 +491,7 @@ MD_U64 md_os_now_microseconds(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); - MD_U64 result = t.tv_sec * md_million(1) + (t.tv_nsec / thousand(1)); + MD_U64 result = t.tv_sec * md_million(1) + (t.tv_nsec / md_thousand(1)); return result; } @@ -544,7 +544,7 @@ md_os_local_time_from_universal(MD_DateTime* date_time) void md_os_sleep_milliseconds(MD_U32 msec) { - usleep(msec * thousand(1)); + usleep(msec * md_thousand(1)); } //////////////////////////////// @@ -598,7 +598,7 @@ md_os_thread_join(MD_OS_Handle handle, MD_U64 endt_us) { if (md_os_handle_match(handle, md_os_handle_zero())) { return 0; } MD_OS_LNX_Entity* entity = (MD_OS_LNX_Entity*)handle.u64[0]; - int join_result = pthread_join(entity->thread.handle, 0); + int join_result = pthread_join(entity->thread.handle, 0); MD_B32 result = (join_result == 0); md_os_lnx_entity_release(entity); return result; @@ -753,10 +753,10 @@ md_os_condition_variable_wait(MD_OS_Handle cv, MD_OS_Handle mutex, MD_U64 endt_u struct timespec endt_timespec; endt_timespec.tv_sec = endt_us / md_million(1); - endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); + endt_timespec.tv_nsec = md_thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); int wait_result = pthread_cond_timedwait(&cv_entity->cv.cond_handle, &mutex_entity->mutex_handle, &endt_timespec); - MD_B32 result = (wait_result != ETIMEDOUT); + MD_B32 result = (wait_result != ETIMEDOUT); return result; } @@ -767,15 +767,15 @@ md_os_condition_variable_wait_rw_r(MD_OS_Handle cv, MD_OS_Handle mutex_rw, MD_U6 // this together, but this would probably just be a lot better if we just // implemented the primitives ourselves with e.g. futexes // - if(md_os_handle_match(cv, md_os_handle_zero())) { return 0; } - if(md_os_handle_match(mutex_rw, md_os_handle_zero())) { return 0; } + if (md_os_handle_match(cv, md_os_handle_zero())) { return 0; } + if (md_os_handle_match(mutex_rw, md_os_handle_zero())) { return 0; } MD_OS_LNX_Entity* cv_entity = (MD_OS_LNX_Entity*)cv.u64[0]; MD_OS_LNX_Entity* rw_mutex_entity = (MD_OS_LNX_Entity*)mutex_rw.u64[0]; struct timespec endt_timespec; endt_timespec.tv_sec = endt_us / md_million(1); - endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); + endt_timespec.tv_nsec = md_thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); MD_B32 result = 0; for(;;) @@ -814,7 +814,7 @@ md_os_condition_variable_wait_rw_w(MD_OS_Handle cv, MD_OS_Handle mutex_rw, MD_U6 struct timespec endt_timespec; endt_timespec.tv_sec = endt_us / md_million(1); - endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); + endt_timespec.tv_nsec = md_thousand(1) * (endt_us - (endt_us / md_million(1)) * md_million(1)); MD_B32 result = 0; for(;;) @@ -896,8 +896,8 @@ md_os_semaphore_drop(MD_OS_Handle semaphore) MD_OS_Handle md_os_library_open(MD_String8 path) { MD_TempArena scratch = md_scratch_begin(0, 0); - char* path_cstr = (char *)md_push_str8_copy(scratch.arena, path).str; - void* so = dlopen(path_cstr, RTLD_LAZY); + char* path_cstr = (char *)md_push_str8_copy(scratch.arena, path).str; + void* so = dlopen(path_cstr, RTLD_LAZY); MD_OS_Handle lib = { (MD_U64)so }; scratch_end(scratch); return lib; @@ -906,8 +906,8 @@ md_os_library_open(MD_String8 path) { MD_VoidProc* md_os_library_load_proc(MD_OS_Handle lib, MD_String8 name) { MD_TempArena scratch = md_scratch_begin(0, 0); - void* so = (void*)lib.u64; - char* name_cstr = (char*)md_push_str8_copy(scratch.arena, name).str; + void* so = (void*)lib.u64; + char* name_cstr = (char*)md_push_str8_copy(scratch.arena, name).str; MD_VoidProc* proc = (MD_VoidProc*)dlsym(so, name_cstr); scratch_end(scratch); return proc; @@ -927,7 +927,7 @@ md_os_safe_call(MD_OS_ThreadFunctionType* func, MD_OS_ThreadFunctionType* fail_h { // rjf: push handler to chain MD_OS_LNX_SafeCallChain chain = {0}; - SLLStackPush(md_os_lnx_safe_call_chain, &chain); + sll_stack_push(md_os_lnx_safe_call_chain, &chain); chain.fail_handler = fail_handler; chain.ptr = ptr; @@ -1000,7 +1000,7 @@ main(int argc, char **argv) md_tctx_init_and_equip(&md_tctx); //- rjf: set up dynamically allocated state - md_os_lnx_state.arena = md_arena_alloc(); + md_os_lnx_state.arena = md_arena_alloc(); md_os_lnx_state.entity_arena = md_arena_alloc(); pthread_mutex_init(&md_os_lnx_state.entity_mutex, 0); @@ -1012,7 +1012,7 @@ main(int argc, char **argv) // rjf: get machine name MD_B32 got_final_result = 0; MD_U8* buffer = 0; - int size = 0; + int size = 0; for (MD_S64 cap = 4096, r = 0; r < 4; cap *= 2, r += 1) { scratch_end(scratch); @@ -1030,7 +1030,7 @@ main(int argc, char **argv) { info->machine_name.size = size; info->machine_name.str = md_push_array__no_zero(md_os_lnx_state.arena, MD_U8, info->machine_name.size + 1); - MemoryCopy(info->machine_name.str, buffer, info->machine_name.size); + memory_copy(info->machine_name.str, buffer, info->machine_name.size); info->machine_name.str[info->machine_name.size] = 0; } @@ -1065,7 +1065,7 @@ main(int argc, char **argv) { MD_String8 full_name = md_str8(buffer, size); MD_String8 name_chopped = md_str8_chop_last_slash(full_name); - info->binary_path = md_push_str8_copy(md_os_lnx_state.arena, name_chopped); + info->binary_path = md_push_str8_copy(md_os_lnx_state.arena, name_chopped); } } diff --git a/source/os/linux/os_linux.h b/source/os/linux/os_linux.h index 8adbe0c..f5729e4 100644 --- a/source/os/linux/os_linux.h +++ b/source/os/linux/os_linux.h @@ -24,7 +24,7 @@ struct MD_OS_LNX_FileIter { DIR* dir; struct dirent* dp; - MD_String8 path; + MD_String8 path; }; md_assert(sizeof(Member(MD_OS_FileIter, memory)) >= sizeof(MD_OS_LNX_FileIter), md_os_lnx_file_iter_size_check); @@ -85,7 +85,7 @@ struct MD_OS_LNX_State MD_Arena* arena; MD_OS_SystemInfo system_info; MD_OS_ProcessInfo process_info; - pthread_mutex_t entity_mutex; + pthread_mutex_t entity_mutex; MD_Arena* entity_arena; MD_OS_LNX_Entity* entity_free; }; @@ -95,17 +95,17 @@ struct MD_OS_LNX_State //~ rjf: Helpers MD_DateTime md_os_lnx_date_time_from_tm (tm in, MD_U32 msec); -tm md_os_lnx_tm_from_date_time (MD_DateTime dt); -timespec md_os_lnx_timespec_from_date_time (MD_DateTime dt); +tm md_os_lnx_tm_from_date_time (MD_DateTime dt); +timespec md_os_lnx_timespec_from_date_time (MD_DateTime dt); MD_DenseTime md_os_lnx_dense_time_from_timespec (timespec in); MD_FileProperties md_os_lnx_file_properties_from_stat(struct stat* s); -void md_os_lnx_safe_call_sig_handler (int x); +void md_os_lnx_safe_call_sig_handler (int x); inline MD_DateTime md_os_lnx_date_time_from_tm(tm in, MD_U32 msec) { MD_DateTime dt = {0}; dt.sec = in.tm_sec; - dt.md_min = in.tm_min; + dt.min = in.tm_min; dt.hour = in.tm_hour; dt.day = in.tm_mday-1; @@ -173,7 +173,7 @@ md_os_lnx_safe_call_sig_handler(int x) { //~ rjf: Entities MD_API MD_OS_LNX_Entity* md_os_lnx_entity_alloc (MD_OS_LNX_EntityKind kind); -MD_API void md_os_lnx_entity_release(MD_OS_LNX_Entity* entity); +MD_API void md_os_lnx_entity_release(MD_OS_LNX_Entity* entity); //////////////////////////////// //~ rjf: Thread Entry Point @@ -185,7 +185,7 @@ MD_API void* md_os_lnx_thread_entry_point(void* ptr); inline MD_String8 md_os_get_current_path__ainfo(MD_AllocatorInfo ainfo) { - char* cwdir = getcwd(0, 0); + char* cwdir = getcwd(0, 0); MD_String8 string = md_str8_copy(ainfo, md_str8_cstring(cwdir)); return string; } @@ -195,15 +195,15 @@ md_os_get_current_path__ainfo(MD_AllocatorInfo ainfo) { //- rjf: basic -inline void* md_os_reserve ( MD_U64 size) { void* result = mmap(0, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); return result; } -inline MD_B32 md_os_commit (void *ptr, MD_U64 size) { mprotect(ptr, size, PROT_READ | PROT_WRITE); return 1; } -inline void md_os_decommit(void *ptr, MD_U64 size) { madvise(ptr, size, MADV_DONTNEED); mprotect(ptr, size, PROT_NONE); } -inline void md_os_release (void *ptr, MD_U64 size) { munmap(ptr, size); } +inline void* md_os_reserve ( MD_U64 size) { void* result = mmap(0, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); return result; } +inline MD_B32 md_os_commit (void *ptr, MD_U64 size) { mprotect(ptr, size, PROT_READ | PROT_WRITE); return 1; } +inline void md_os_decommit(void *ptr, MD_U64 size) { madvise(ptr, size, MADV_DONTNEED); mprotect(ptr, size, PROT_NONE); } +inline void md_os_release (void *ptr, MD_U64 size) { munmap(ptr, size); } //- rjf: large pages -inline void* md_os_reserve_large( MD_U64 size) { void* result = mmap(0, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); return result; } -inline MD_B32 md_os_commit_large (void *ptr, MD_U64 size) { mprotect(ptr, size, PROT_READ | PROT_WRITE); return 1; } +inline void* md_os_reserve_large( MD_U64 size) { void* result = mmap(0, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); return result; } +inline MD_B32 md_os_commit_large (void *ptr, MD_U64 size) { mprotect(ptr, size, PROT_READ | PROT_WRITE); return 1; } //////////////////////////////// //~ rjf: @md_os_hooks Thread Info (Implemented Per-OS) diff --git a/source/os/win32/os_win32.c b/source/os/win32/os_win32.c index ecf4521..3337d1c 100644 --- a/source/os/win32/os_win32.c +++ b/source/os/win32/os_win32.c @@ -1,3 +1,6 @@ +#ifdef INTELLISENSE_DIRECTIVES +# include "os_win32.h" +#endif // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) @@ -786,7 +789,7 @@ md_os_process_launch(MD_OS_ProcessLaunchParams* params) MD_String8List all_opts = params->env; if (params->inherit_env != 0) { - if (all_opts.md_node_count != 0) + if (all_opts.node_count != 0) { md_memory_zero_struct(&all_opts); for (MD_String8Node *n = params->env.first; n != 0; n = n->next) { @@ -1486,7 +1489,7 @@ w32_entry_point_caller(int argc, WCHAR** wargv) //- rjf: extract arguments MD_Arena* args_arena = md_arena_alloc(.backing = md_varena_alloc(.reserve_size = MD_MB(1), .commit_size = MD_KB(32))); - char** argv = md_push_array_(args_arena, char*, argc); + char** argv = md_push_array(args_arena, char*, argc); for (int i = 0; i < argc; i += 1) { MD_String16 arg16 = md_str16_cstring((MD_U16 *)wargv[i]); diff --git a/source/os/win32/os_win32.h b/source/os/win32/os_win32.h index 890ba26..942bc9b 100644 --- a/source/os/win32/os_win32.h +++ b/source/os/win32/os_win32.h @@ -17,9 +17,9 @@ struct MD_OS_W32_FileIter { HANDLE handle; WIN32_FIND_DATAW find_data; - MD_B32 is_volume_iter; - MD_String8Array drive_strings; - MD_U64 drive_strings_iter_idx; + MD_B32 is_volume_iter; + MD_String8Array drive_strings; + MD_U64 drive_strings_iter_idx; }; md_static_assert(sizeof(md_member(MD_OS_FileIter, memory)) >= sizeof(MD_OS_W32_FileIter), file_iter_memory_size); @@ -40,9 +40,9 @@ typedef struct MD_OS_W32_EntityThread MD_OS_W32_EntityThread; struct MD_OS_W32_EntityThread { MD_OS_ThreadFunctionType* func; - void* ptr; - HANDLE handle; - DWORD tid; + void* ptr; + HANDLE handle; + DWORD tid; }; typedef struct MD_OS_W32_Entity MD_OS_W32_Entity; @@ -53,9 +53,9 @@ struct MD_OS_W32_Entity union { MD_OS_W32_EntityThread thread; - CRITICAL_SECTION mutex; - SRWLOCK rw_mutex; - CONDITION_VARIABLE cv; + CRITICAL_SECTION mutex; + SRWLOCK rw_mutex; + CONDITION_VARIABLE cv; }; }; @@ -73,9 +73,9 @@ struct MD_OS_W32_State MD_U64 microsecond_resolution; // rjf: entity storage - CRITICAL_SECTION entity_mutex; - MD_Arena* entity_arena; - MD_OS_W32_Entity* entity_free; + CRITICAL_SECTION entity_mutex; + MD_Arena* entity_arena; + MD_OS_W32_Entity* entity_free; }; //////////////////////////////// @@ -87,10 +87,10 @@ MD_API extern MD_OS_W32_State md_os_w32_state; //////////////////////////////// //~ rjf: Time Conversion Helpers - void md_os_w32_date_time_from_system_time(MD_DateTime* out, SYSTEMTIME* in); - void md_os_w32_system_time_from_date_time(SYSTEMTIME* out, MD_DateTime* in); - void md_os_w32_dense_time_from_file_time (MD_DenseTime* out, FILETIME* in); -MD_API MD_U32 md_os_w32_sleep_ms_from_endt_us(MD_U64 endt_us); + void md_os_w32_date_time_from_system_time(MD_DateTime* out, SYSTEMTIME* in); + void md_os_w32_system_time_from_date_time(SYSTEMTIME* out, MD_DateTime* in); + void md_os_w32_dense_time_from_file_time (MD_DenseTime* out, FILETIME* in); +MD_API MD_U32 md_os_w32_sleep_ms_from_endt_us(MD_U64 endt_us); inline void md_os_w32_date_time_from_system_time(MD_DateTime* out, SYSTEMTIME* in) @@ -101,7 +101,7 @@ md_os_w32_date_time_from_system_time(MD_DateTime* out, SYSTEMTIME* in) out->day = in->wDay; out->hour = in->wHour; - out->md_min = in->wMinute; + out->min = in->wMinute; out->sec = in->wSecond; out->msec = in->wMilliseconds; } @@ -114,7 +114,7 @@ md_os_w32_system_time_from_date_time(SYSTEMTIME* out, MD_DateTime* in) out->wDay = in->day; out->wHour = in->hour; - out->wMinute = in->md_min; + out->wMinute = in->min; out->wSecond = in->sec; out->wMilliseconds = in->msec; } @@ -169,7 +169,7 @@ md_os_get_current_path__ainfo(MD_AllocatorInfo ainfo) { MD_TempArena scratch = md_scratch_begin(ainfo); { DWORD length = GetCurrentDirectoryW(0, 0); - MD_U16* memory = md_push_array__no_zero(scratch.arena, MD_U16, length + 1); + MD_U16* memory = md_push_array__no_zero(scratch.arena, MD_U16, length + 1); length = GetCurrentDirectoryW(length + 1, (WCHAR*)memory); name = md_str8_from(ainfo, md_str16(memory, length)); } @@ -182,9 +182,9 @@ md_os_get_current_path__ainfo(MD_AllocatorInfo ainfo) { //- rjf: basic -inline void* md_os_reserve ( MD_U64 size) { void* result = VirtualAlloc( 0, size, MEM_RESERVE, PAGE_READWRITE); return result; } -inline MD_B32 md_os_commit (void* ptr, MD_U64 size) { MD_B32 result = (VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE) != 0); return result; } -inline void md_os_decommit(void* ptr, MD_U64 size) { VirtualFree (ptr, size, MEM_DECOMMIT); } +inline void* md_os_reserve ( MD_U64 size) { void* result = VirtualAlloc( 0, size, MEM_RESERVE, PAGE_READWRITE); return result; } +inline MD_B32 md_os_commit (void* ptr, MD_U64 size) { MD_B32 result = (VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE) != 0); return result; } +inline void md_os_decommit(void* ptr, MD_U64 size) { VirtualFree (ptr, size, MEM_DECOMMIT); } inline void md_os_release(void* ptr, MD_U64 size) { diff --git a/tests/sanity_tests.c b/tests/sanity_tests.c index 7cb91ce..5bc9a34 100644 --- a/tests/sanity_tests.c +++ b/tests/sanity_tests.c @@ -79,8 +79,7 @@ match_parsed_with_node(MD_Arena* arena, MD_String8 string, MD_Node* tree) static MD_B32 token_match(MD_String8 text, MD_Token token, MD_String8 string, MD_TokenFlags flags) { - return md_str8_match(string, md_str8_substr(text, token.range), 0) &&& token.flags == flags; - // return MD_S8Match(string, token.string, 0) && token.kind == kind; + return md_str8_match(string, md_str8_substr(text, token.range), 0) && token.flags == flags; } int main(void) @@ -171,7 +170,7 @@ int main(void) md_node_push_child(sub, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("3"))); md_node_push_child(tree, sub); } - MD_PushChild(tree, make_test_node(MD_NodeKind_Main, md_str8_lit("c"))); + MD_PushChild(tree, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("c"))); test_result(matched_parsed_with_node(string, tree)); } @@ -180,7 +179,7 @@ int main(void) MD_Node* tree = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("foo")); MD_Node* params = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("")); MD_Node* size = make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("size")); - md_node_push_child(size, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier md_str8_lit("u64"))); + md_node_push_child(size, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("u64"))); md_node_push_child(params, size); md_node_push_child(tree, params); md_node_push_child(tree, make_test_node(MD_NodeKind_Main, MD_NodeFlag_Identifier, md_str8_lit("->"))); @@ -200,32 +199,41 @@ int main(void) test("Set Border Flags") { { - MD_TokenizeResult lexed = md_token_array_from_chunk_list() - MD_ParseResult parse = md_parse MD_ParseOneNode(arena, md_str8_lit("(0, 100)"), 0); + MD_String8 str = md_str8_lit("(0, 100)"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens); test_result(parse.root->flags & MD_NodeFlag_HasParenLeft && parse.root->flags & MD_NodeFlag_HasParenRight); } { - MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("(0, 100]"), 0); + MD_String8 str = md_str8_lit("(0, 100]"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens); test_result(parse.root->flags & MD_NodeFlag_HasParenLeft && parse.root->flags & MD_NodeFlag_HasBracketRight); } { - MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("[0, 100)"), 0); + MD_String8 str = md_str8_lit("[0, 100)"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, fmd_str8_zero(), str, lexed.tokens); test_result(parse.root->flags & MD_NodeFlag_HasBracketLeft && parse.root->flags & MD_NodeFlag_HasParenRight); } { - MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("[0, 100]"), 0); + MD_String8 str = md_str8_lit("[0, 100]"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens); test_result(parse.root->flags & MD_NodeFlag_HasBracketLeft && parse.root->flags & MD_NodeFlag_HasBracketRight); } { - MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("{0, 100}"), 0); + MD_String8 str = md_str8_lit("{0, 100}"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens); test_result(parse.root->flags & MD_NodeFlag_HasBraceLeft && parse.root->flags & MD_NodeFlag_HasBraceRight); } @@ -234,92 +242,90 @@ int main(void) test("Node Separator Flags") { { - MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("(a, b)"), 0); - test_result(parse.root->first_child->flags & MD_NodeFlag_IsBeforeComma); - test_result(parse.root->first_child->next->flags & MD_NodeFlag_IsAfterComma); + MD_String8 str = md_str8_lit("(a, b)"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens); + test_result(parse.root->first->flags & MD_NodeFlag_IsBeforeComma); + test_result(parse.root->first->next->flags & MD_NodeFlag_IsAfterComma); } { - MD_ParseResult parse = MD_ParseOneNode(arena, md_str8_lit("(a; b)"), 0); - test_result(parse.root->first_child->flags & MD_NodeFlag_IsBeforeSemicolon); - test_result(parse.root->first_child->next->flags & MD_NodeFlag_IsAfterSemicolon); + MD_String8 str = md_str8_lit("(a; b)"); + MD_TokenizeResult lexed = md_tokenize_from_text(arena, str); + MD_ParseResult parse = md_parse_from_text_tokens(arena, md_str8_zero(), str, lexed.tokens); + test_result(parse.root->first->flags & MD_NodeFlag_IsBeforeSemicolon); + test_result(parse.root->first->next->flags & MD_NodeFlag_IsAfterSemicolon); } } test("Node Text Flags") { - TestResult(MD_ParseOneNode(arena, md_str8_lit("123"), 0).node->flags &MD_NodeFlag_Numeric); - TestResult(MD_ParseOneNode(arena, md_str8_lit("123_456_789"), 0).node->flags &MD_NodeFlag_Numeric); - TestResult(MD_ParseOneNode(arena, md_str8_lit("abc"), 0).node->flags &MD_NodeFlag_Identifier); + test_result(md_tree_from_string(arena, md_str8_lit("123_456_789"))->flags & MD_NodeFlag_Numeric); + test_result(md_tree_from_string(arena, md_str8_lit("abc") )->flags & MD_NodeFlag_Identifier); { - MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"foo\""), 0); - TestResult(parse.root->flags & MD_NodeFlag_StringLiteral && - parse.root->flags & MD_NodeFlag_StringDoubleQuote); + MD_Node* root = md_tree_from_string(arena, md_str8_lit("\"foo\"")); + test_result(root->flags & MD_NodeFlag_StringLiteral && + root->flags & MD_NodeFlag_StringDoubleQuote); } { - MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'foo'"), 0); - TestResult(parse.root->flags & NodeFlag_StringLiteral && - parse.root->flags & NodeFlag_StringSingleQuote); + MD_Node* root = md_tree_from_string(arena, md_str8_lit("'foo'")); + test_result(root->flags & MD_NodeFlag_StringLiteral && + root->flags & MD_NodeFlag_StringSingleQuote); } { - MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`foo`"), 0); - TestResult(parse.root->flags & NodeFlag_StringLiteral && - parse.root->flags & NodeFlag_StringTick); + MD_Node* root = md_tree_from_string(arena, md_str8_lit("`foo`"), 0); + test_result(root->flags & MD_NodeFlag_StringLiteral && + root->flags & MD_NodeFlag_StringTick); } { - MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\"foo\"\"\""), 0); - TestResult(parse.root->flags & NodeFlag_StringLiteral && - parse.root->flags & NodeFlag_StringDoubleQuote && - parse.root->flags & NodeFlag_StringTriplet); + MD_Node* root = md_tree_from_string(arena, md_str8_lit("\"\"\"foo\"\"\""), 0); + test_result(parse.root->flags & MD_NodeFlag_StringLiteral && + parse.root->flags & MD_NodeFlag_StringDoubleQuote && + parse.root->flags & MD_NodeFlag_StringTriplet); } { - MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'''foo'''"), 0); - TestResult(parse.root->flags & NodeFlag_StringLiteral && - parse.root->flags & NodeFlag_StringSingleQuote && - parse.root->flags & NodeFlag_StringTriplet); + MD_Node* root = md_tree_from_string(arena, md_str8_lit("'''foo'''"), 0); + test_result(parse.root->flags & MD_NodeFlag_StringLiteral && + parse.root->flags & MD_NodeFlag_StringSingleQuote && + parse.root->flags & MD_NodeFlag_StringTriplet); } { - MD_ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("```foo```"), 0); - TestResult(parse.root->flags & NodeFlag_StringLiteral && - parse.root->flags & NodeFlag_StringTick && - parse.root->flags & NodeFlag_StringTriplet); + MD_Node* root = md_tree_from_string(arena, md_str8_lit("```foo```"), 0); + test_result(parse.root->flags & MD_NodeFlag_StringLiteral && + parse.root->flags & MD_NodeFlag_StringTick && + parse.root->flags & MD_NodeFlag_StringTriplet); } } test("Style Strings") { { - MD_String8 str = md_str8_style(arena, MD_S8Lit("THIS_IS_A_TEST"), - MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); - TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0)); + MD_String8 str = md_str8_style(arena, MD_S8Lit("THIS_IS_A_TEST"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); + test_result(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0)); } { - MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("this_is_a_test"), - MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); - TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0)); + MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("this_is_a_test"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); + test_result(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0)); } { - MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("ThisIsATest"), - MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); - TestResult(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0)); + MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("ThisIsATest"), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit(" ")); + test_result(MD_S8Match(str, MD_S8Lit("This Is A Test"), 0)); } { - MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("Here is another test."), - MD_IdentifierStyle_UpperCamelCase, MD_S8Lit("")); - TestResult(MD_S8Match(str, MD_S8Lit("HereIsAnotherTest."), 0)); + MD_String8 str = MD_S8Stylize(arena, MD_S8Lit("Here is another test."), MD_IdentifierStyle_UpperCamelCase, MD_S8Lit("")); + test_result(MD_S8Match(str, MD_S8Lit("HereIsAnotherTest."), 0)); } } test("Enum Strings") { - TestResult(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0)); - TestResult(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0)); + test_result(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0)); + test_result(MD_S8Match(MD_StringFromNodeKind(MD_NodeKind_Main), MD_S8Lit("Main"), 0)); MD_String8List list = MD_StringListFromNodeFlags(arena, MD_NodeFlag_StringLiteral | MD_NodeFlag_HasParenLeft | MD_NodeFlag_IsBeforeSemicolon); MD_B32 match = 1; for(MD_String8Node *node = list.first; node; node = node->next) - md_str8_lit if(!md_str8_match(node->string, md_str8_lit("StringLiteral"), 0) && !md_str8_match(node->string, md_str8_lit("HasParenLeft"), 0) && !md_str8_match(node->string, md_str8_lit("IsBeforeSemicolon"), 0)) @@ -328,7 +334,7 @@ int main(void) break; } } - TestResult(match); + test_result(match); } test("Node Comments") @@ -338,17 +344,17 @@ int main(void) { { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("/*foobar*/ (a b c)"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->prev_comment, MD_S8Lit("foobar"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("// foobar\n(a b c)"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->prev_comment, MD_S8Lit(" foobar"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("// foobar\n\n(a b c)"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->prev_comment, MD_S8Lit(""), 0)); } } @@ -357,22 +363,22 @@ int main(void) { { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c) /*foobar*/"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->next_comment, MD_S8Lit("foobar"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c) // foobar"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->next_comment, MD_S8Lit(" foobar"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c)\n// foobar"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("(a b c)\n\n// foobar"), 0); - TestResult(parse.node->kind == NodeKind_Main && + test_result(parse.node->kind == NodeKind_Main && MD_S8Match(parse.node->next_comment, MD_S8Lit(""), 0)); } } @@ -415,12 +421,12 @@ int main(void) columns_match = 0; } } - TestResult(columns_match); + test_result(columns_match); } { ParseResult parse = MD_ParseWholeFile(arena, MD_S8Lit("__does_not_exist.mdesk")); - TestResult(parse.node->kind == NodeKind_File && parse.errors.first != 0); + test_result(parse.node->kind == NodeKind_File && parse.errors.first != 0); } } @@ -453,7 +459,7 @@ int main(void) for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1) { MD_MapSlot *slot = MD_MapLookup(&map, keys[i]); - TestResult(slot && slot->val == (void *)i); + test_result(slot && slot->val == (void *)i); } for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1) { @@ -462,7 +468,7 @@ int main(void) for (MD_u64 i = 0; i < MD_ArrayCount(keys); i += 1) { MD_MapSlot *slot = MD_MapLookup(&map, keys[i]); - TestResult(slot && slot->val == (void *)(i + 10)); + test_result(slot && slot->val == (void *)(i + 10)); } } } @@ -485,60 +491,60 @@ int main(void) nodes[i] = result.node; } - TestResult(MD_S8Match(nodes[0]->string, MD_S8Lit("foo-bar"), 0)); - TestResult(MD_S8Match(nodes[1]->string, MD_S8Lit("foo-bar"), 0)); - TestResult(MD_S8Match(nodes[2]->string, MD_S8Lit("foo-bar"), 0)); - TestResult(MD_S8Match(nodes[3]->string, MD_S8Lit("foo-bar"), 0)); - TestResult(MD_S8Match(nodes[4]->string, MD_S8Lit("foo-bar"), 0)); - TestResult(MD_S8Match(nodes[5]->string, MD_S8Lit("foo-bar"), 0)); + test_result(MD_S8Match(nodes[0]->string, MD_S8Lit("foo-bar"), 0)); + test_result(MD_S8Match(nodes[1]->string, MD_S8Lit("foo-bar"), 0)); + test_result(MD_S8Match(nodes[2]->string, MD_S8Lit("foo-bar"), 0)); + test_result(MD_S8Match(nodes[3]->string, MD_S8Lit("foo-bar"), 0)); + test_result(MD_S8Match(nodes[4]->string, MD_S8Lit("foo-bar"), 0)); + test_result(MD_S8Match(nodes[5]->string, MD_S8Lit("foo-bar"), 0)); - TestResult(MD_S8Match(nodes[0]->raw_string, samples[0], 0)); - TestResult(MD_S8Match(nodes[1]->raw_string, samples[1], 0)); - TestResult(MD_S8Match(nodes[2]->raw_string, samples[2], 0)); - TestResult(MD_S8Match(nodes[3]->raw_string, samples[3], 0)); - TestResult(MD_S8Match(nodes[4]->raw_string, samples[4], 0)); - TestResult(MD_S8Match(nodes[5]->raw_string, samples[5], 0)); + test_result(MD_S8Match(nodes[0]->raw_string, samples[0], 0)); + test_result(MD_S8Match(nodes[1]->raw_string, samples[1], 0)); + test_result(MD_S8Match(nodes[2]->raw_string, samples[2], 0)); + test_result(MD_S8Match(nodes[3]->raw_string, samples[3], 0)); + test_result(MD_S8Match(nodes[4]->raw_string, samples[4], 0)); + test_result(MD_S8Match(nodes[5]->raw_string, samples[5], 0)); } test("String escaping") { { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\``"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\`"), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit("\\`"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("``` \\``` ```"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\``` "), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit(" \\``` "), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`````\\````"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit("``\\`"), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit("``\\`"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\'`"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\'"), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit("\\'"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("''' \\''' '''"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\''' "), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit(" \\''' "), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("'''''\\''''"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit("''\\'"), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit("''\\'"), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("`\\\"`"), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\\\""), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit("\\\""), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\" \\\"\"\" \"\"\""), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit(" \\\"\"\" "), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit(" \\\"\"\" "), 0)); } { ParseResult parse = MD_ParseOneNode(arena, MD_S8Lit("\"\"\"\"\"\\\"\"\"\""), 0); - TestResult(MD_S8Match(parse.node->string, MD_S8Lit("\"\"\\\""), 0)); + test_result(MD_S8Match(parse.node->string, MD_S8Lit("\"\"\\\""), 0)); } } @@ -551,18 +557,18 @@ int main(void) Node *group_first = node->first_child; Node *group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterSemicolon); - TestResult(MD_S8Match(group_first->string, MD_S8Lit("x"), 0)); - TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("y"), 0)); - TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("z"), 0)); - TestResult(group_opl == group_first->next->next->next); + test_result(MD_S8Match(group_first->string, MD_S8Lit("x"), 0)); + test_result(MD_S8Match(group_first->next->string, MD_S8Lit("y"), 0)); + test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("z"), 0)); + test_result(group_opl == group_first->next->next->next); group_first = group_opl; group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterSemicolon); - TestResult(MD_S8Match(group_first->string, MD_S8Lit("a"), 0)); - TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0)); - TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0)); - TestResult(group_opl == group_first->next->next->next); + test_result(MD_S8Match(group_first->string, MD_S8Lit("a"), 0)); + test_result(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0)); + test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0)); + test_result(group_opl == group_first->next->next->next); } { @@ -573,24 +579,24 @@ int main(void) group_first = node->first_child; group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma); - TestResult(MD_S8Match(group_first->string, MD_S8Lit("a"), 0)); - TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0)); - TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0)); - TestResult(group_opl == group_first->next->next->next); + test_result(MD_S8Match(group_first->string, MD_S8Lit("a"), 0)); + test_result(MD_S8Match(group_first->next->string, MD_S8Lit("b"), 0)); + test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("c"), 0)); + test_result(group_opl == group_first->next->next->next); group_first = group_opl; group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma); - TestResult(MD_S8Match(group_first->string, MD_S8Lit("d"), 0)); - TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("e"), 0)); - TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("f"), 0)); - TestResult(group_opl == group_first->next->next->next); + test_result(MD_S8Match(group_first->string, MD_S8Lit("d"), 0)); + test_result(MD_S8Match(group_first->next->string, MD_S8Lit("e"), 0)); + test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("f"), 0)); + test_result(group_opl == group_first->next->next->next); group_first = group_opl; group_opl = MD_FirstNodeWithFlags(group_first->next, NodeFlag_IsAfterComma); - TestResult(MD_S8Match(group_first->string, MD_S8Lit("g"), 0)); - TestResult(MD_S8Match(group_first->next->string, MD_S8Lit("h"), 0)); - TestResult(MD_S8Match(group_first->next->next->string, MD_S8Lit("i"), 0)); - TestResult(group_opl == group_first->next->next->next); + test_result(MD_S8Match(group_first->string, MD_S8Lit("g"), 0)); + test_result(MD_S8Match(group_first->next->string, MD_S8Lit("h"), 0)); + test_result(MD_S8Match(group_first->next->next->string, MD_S8Lit("i"), 0)); + test_result(group_opl == group_first->next->next->next); } } @@ -613,57 +619,57 @@ int main(void) MD_PushChild(tree, a); MD_PushChild(tree, d); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first == 0); - TestResult(MD_NodeDeepMatch(tree, result.node, 0)); + test_result(result.errors.first == 0); + test_result(MD_NodeDeepMatch(tree, result.node, 0)); } // finished unscoped set { MD_String8 text = MD_S8Lit("a:\nb:\nc"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first == 0); - TestResult(result.node->first_child == result.node->last_child); + test_result(result.errors.first == 0); + test_result(result.node->first_child == result.node->last_child); } // unfinished unscoped set { MD_String8 text = MD_S8Lit("a:\nb:\n\n"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } { MD_String8 text = MD_S8Lit("a:\nb:\n"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } { MD_String8 text = MD_S8Lit("a:\nb:"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } // labeled scoped set in unscoped set { MD_String8 text = MD_S8Lit("a: b: {\nx\n} c"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first == 0); - TestResult(MD_ChildCountFromNode(result.node) == 1); - TestResult(MD_ChildCountFromNode(result.node->first_child) == 2); + test_result(result.errors.first == 0); + test_result(MD_ChildCountFromNode(result.node) == 1); + test_result(MD_ChildCountFromNode(result.node->first_child) == 2); } { MD_String8 text = MD_S8Lit("a: b: {\nx\n}\nc"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first == 0); - TestResult(MD_ChildCountFromNode(result.node) == 2); - TestResult(MD_ChildCountFromNode(result.node->first_child) == 1); + test_result(result.errors.first == 0); + test_result(MD_ChildCountFromNode(result.node) == 2); + test_result(MD_ChildCountFromNode(result.node->first_child) == 1); } // scoped set is not unscoped { MD_String8 text = MD_S8Lit("a: {\nx\ny\n} c"); ParseResult result = MD_ParseWholeString(arena, file_name, text); - TestResult(result.errors.first == 0); - TestResult(result.node->first_child != result.node->last_child); + test_result(result.errors.first == 0); + test_result(result.node->first_child != result.node->last_child); } } @@ -673,19 +679,19 @@ int main(void) { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@foo bar")); - TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("foo"), 0)); + test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("foo"), 0)); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@+ bar")); - TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("+"), 0)); + test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("+"), 0)); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@'a b c' bar")); - TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("a b c"), 0)); + test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("a b c"), 0)); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("@100 bar")); - TestResult(MD_NodeHasTag(result.node->first_child, MD_S8Lit("100"), 0)); + test_result(MD_NodeHasTag(result.node->first_child, MD_S8Lit("100"), 0)); } } @@ -696,27 +702,27 @@ int main(void) // tagged in scoped set always legal { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:{@tag {bar}}\n")); - TestResult(result.errors.first == 0); + test_result(result.errors.first == 0); } // tagged label in unscoped set legal { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:@tag bar\n")); - TestResult(result.errors.first == 0); + test_result(result.errors.first == 0); } // unlabeled scoped set in unscoped set illegal { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:bar {bar}\n")); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:bar @tag {bar}\n")); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo:@tag {bar}\n")); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } } @@ -735,7 +741,7 @@ int main(void) for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1) { ParseResult result = MD_ParseWholeString(arena, file_name, *string); - TestResult((result.errors.first == 0) && + test_result((result.errors.first == 0) && (result.node->first_child == result.node->last_child) && (result.node->first_child->flags & NodeFlag_Numeric)); } @@ -761,7 +767,7 @@ int main(void) for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1) { ParseResult result = MD_ParseWholeString(arena, file_name, *string); - TestResult((result.errors.first == 0) && + test_result((result.errors.first == 0) && (result.node->first_child == result.node->last_child) && (result.node->first_child->flags & NodeFlag_Numeric)); } @@ -774,26 +780,26 @@ int main(void) { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo: '(' )")); - TestResult(result.errors.first != 0); + test_result(result.errors.first != 0); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo ':' ( )")); - TestResult(result.errors.first == 0); - TestResult(MD_ChildCountFromNode(result.node) == 3); + test_result(result.errors.first == 0); + test_result(MD_ChildCountFromNode(result.node) == 3); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("'@'bar foo")); - TestResult(result.errors.first == 0); - TestResult(MD_ChildCountFromNode(result.node) == 3); + test_result(result.errors.first == 0); + test_result(MD_ChildCountFromNode(result.node) == 3); } { ParseResult result = MD_ParseWholeString(arena, file_name, MD_S8Lit("foo: '(' ')'")); - TestResult(result.errors.first == 0); - TestResult(MD_ChildCountFromNode(result.node) == 1); - TestResult(MD_ChildCountFromNode(result.node->first_child) == 2); + test_result(result.errors.first == 0); + test_result(MD_ChildCountFromNode(result.node) == 1); + test_result(MD_ChildCountFromNode(result.node->first_child) == 2); } } @@ -807,7 +813,7 @@ int main(void) MD_DebugDumpFromNode(arena, &actual_strings, parse.node, 0, MD_S8Lit(" "), MD_GenerateFlags_Tree); MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0); - TestResult(MD_S8Match(expected, actual, 0)); + test_result(MD_S8Match(expected, actual, 0)); } { MD_String8 code = MD_S8Lit("@foo(1, 2, 3) a: { x y }"); @@ -817,7 +823,7 @@ int main(void) MD_DebugDumpFromNode(arena, &actual_strings, parse.node, 0, MD_S8Lit(" "), MD_GenerateFlags_Tree); MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0); - TestResult(MD_S8Match(expected, actual, 0)); + test_result(MD_S8Match(expected, actual, 0)); } { MD_String8 code = MD_S8Lit("// foo\na"); @@ -827,7 +833,7 @@ int main(void) MD_DebugDumpFromNode(arena, &actual_strings, parse.node, 0, MD_S8Lit(" "), MD_GenerateFlags_Tree|MD_GenerateFlag_Comments); MD_String8 actual = MD_S8ListJoin(arena, actual_strings, 0); - TestResult(MD_S8Match(expected, actual, 0)); + test_result(MD_S8Match(expected, actual, 0)); } { MD_String8 code = MD_S8Lit("@foo @bar @baz a: { b c d e f }"); @@ -836,7 +842,7 @@ int main(void) MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" ")); MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0); ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0); - TestResult(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); + test_result(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); } { MD_String8 code = MD_S8Lit("@foo(x: y: z) @bar(a: b: c) @baz(1: 2: 3) abcdefg: { b: 4, c d: 5; e; f, }"); @@ -845,7 +851,7 @@ int main(void) MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" ")); MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0); ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0); - TestResult(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); + test_result(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); } { MD_String8 code = MD_S8Lit("@foo(x: y: z)\n" @@ -864,7 +870,7 @@ int main(void) MD_ReconstructionFromNode(arena, &reconstruction_strs, parse1.node, 0, MD_S8Lit(" ")); MD_String8 reconstruction = MD_S8ListJoin(arena, reconstruction_strs, 0); ParseResult parse2 = MD_ParseOneNode(arena, reconstruction, 0); - TestResult(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); + test_result(MD_NodeDeepMatch(parse1.node, parse2.node, MD_NodeMatchFlag_TagArguments|MD_NodeMatchFlag_NodeFlags)); } }