mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-17 17:42:23 -07:00
test cases for integer/float lexing to get C style integers, JSON/C style floats
This commit is contained in:
+4
-4
@@ -676,14 +676,14 @@ MD_FUNCTION MD_i64 MD_CStyleIntFromString(MD_String8 string);
|
||||
MD_FUNCTION MD_f64 MD_F64FromString(MD_String8 string);
|
||||
|
||||
//~ Enum/Flag Strings
|
||||
MD_FUNCTION MD_String8 MD_StringFromNodeKind(MD_NodeKind kind);
|
||||
MD_FUNCTION MD_String8List MD_StringListFromNodeFlags(MD_NodeFlags flags);
|
||||
MD_FUNCTION MD_String8 MD_StringFromNodeKind(MD_NodeKind kind);
|
||||
MD_FUNCTION MD_String8List MD_StringListFromNodeFlags(MD_NodeFlags flags);
|
||||
|
||||
//~ Unicode Conversions
|
||||
MD_FUNCTION MD_UnicodeConsume MD_CodepointFromUtf8(MD_u8 *str, MD_u64 max);
|
||||
MD_FUNCTION MD_UnicodeConsume MD_CodepointFromUtf16(MD_u16 *str, MD_u64 max);
|
||||
MD_FUNCTION MD_u32 MD_Utf8FromCodepoint(MD_u8 *out, MD_u32 codepoint);
|
||||
MD_FUNCTION MD_u32 MD_Utf16FromCodepoint(MD_u16 *out, MD_u32 codepoint);
|
||||
MD_FUNCTION MD_u32 MD_Utf8FromCodepoint(MD_u8 *out, MD_u32 codepoint);
|
||||
MD_FUNCTION MD_u32 MD_Utf16FromCodepoint(MD_u16 *out, MD_u32 codepoint);
|
||||
MD_FUNCTION MD_String8 MD_S8FromS16(MD_String16 str);
|
||||
MD_FUNCTION MD_String16 MD_S16FromS8(MD_String8 str);
|
||||
MD_FUNCTION MD_String8 MD_S8FromS32(MD_String32 str);
|
||||
|
||||
@@ -746,5 +746,87 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
Test("Integer Lexing")
|
||||
{
|
||||
MD_String8 file_name = MD_S8Lit("raw_text");
|
||||
|
||||
MD_String8 test_strings[] = {
|
||||
MD_S8Lit("0765"),
|
||||
MD_S8Lit("+0765"), // NOTE(allen): not sure about the "+" cases here
|
||||
MD_S8Lit("-0765"),
|
||||
MD_S8Lit("0xABC"),
|
||||
MD_S8Lit("+0xABC"),
|
||||
MD_S8Lit("-0xABC"),
|
||||
MD_S8Lit("0x123"),
|
||||
MD_S8Lit("0b010"),
|
||||
MD_S8Lit("+0b010"),
|
||||
MD_S8Lit("-0b010"),
|
||||
};
|
||||
|
||||
MD_String8 *string = test_strings;
|
||||
for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1){
|
||||
MD_ParseResult result = MD_ParseWholeString(file_name, *string);
|
||||
TestResult((result.first_error == 0) &&
|
||||
(result.node->first_child == result.node->last_child) &&
|
||||
(result.node->first_child->flags & MD_NodeFlag_Numeric));
|
||||
}
|
||||
}
|
||||
|
||||
Test("Float Lexing")
|
||||
{
|
||||
MD_String8 file_name = MD_S8Lit("raw_text");
|
||||
|
||||
MD_String8 test_strings[] = {
|
||||
MD_S8Lit("0"),
|
||||
MD_S8Lit("1"),
|
||||
MD_S8Lit("-1"),
|
||||
MD_S8Lit("+1"), // NOTE(allen): not sure about "+1"
|
||||
MD_S8Lit("0.5"),
|
||||
MD_S8Lit("-0.5"),
|
||||
MD_S8Lit("-1.5"),
|
||||
MD_S8Lit("1e2"),
|
||||
MD_S8Lit("-1e2"),
|
||||
MD_S8Lit("1e+2"),
|
||||
MD_S8Lit("1e-2"),
|
||||
MD_S8Lit("-1e+2"),
|
||||
MD_S8Lit("1.5e2"),
|
||||
MD_S8Lit("-1.5e2"),
|
||||
MD_S8Lit("1.5e+2"),
|
||||
MD_S8Lit("1.5e-2"),
|
||||
MD_S8Lit("-1.5e+2"),
|
||||
};
|
||||
|
||||
MD_String8 *string = test_strings;
|
||||
for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1){
|
||||
MD_ParseResult result = MD_ParseWholeString(file_name, *string);
|
||||
TestResult((result.first_error == 0) &&
|
||||
(result.node->first_child == result.node->last_child) &&
|
||||
(result.node->first_child->flags & MD_NodeFlag_Numeric));
|
||||
}
|
||||
}
|
||||
|
||||
Test("Float Lexing Pt 2")
|
||||
{
|
||||
MD_String8 file_name = MD_S8Lit("raw_text");
|
||||
|
||||
MD_String8 test_strings[] = {
|
||||
MD_S8Lit("0765.1"),
|
||||
MD_S8Lit("0765e2"),
|
||||
MD_S8Lit("0xABC.1"),
|
||||
MD_S8Lit("0xABCe2"),
|
||||
MD_S8Lit("0x123.1"),
|
||||
MD_S8Lit("0x123e2"),
|
||||
MD_S8Lit("0b010.1"),
|
||||
MD_S8Lit("0b010e2"),
|
||||
};
|
||||
|
||||
MD_String8 *string = test_strings;
|
||||
for (int i = 0; i < MD_ArrayCount(test_strings); i += 1, string += 1){
|
||||
MD_ParseResult result = MD_ParseWholeString(file_name, *string);
|
||||
TestResult((result.first_error == 0) &&
|
||||
(result.node->first_child != result.node->last_child));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user