Hash :
bd5c44ad
Author :
Thomas de Grivel
Date :
2023-11-03T14:27:52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
/* c3
* Copyright 2022,2023 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "../libc3/str.h"
#include "../libc3/sym.h"
#include "test.h"
#define SYM_TEST_1(test) \
do { \
TEST_ASSERT((sym = sym_1(test))); \
TEST_EQ(sym->str.size, strlen(test)); \
TEST_EQ(strncmp((test), sym->str.ptr.p, strlen(test)), 0); \
TEST_EQ(sym_1(test), sym_1(test)); \
} while (0)
#define SYM_TEST_INSPECT(test, result) \
do { \
const s_sym *sym; \
s_str str; \
assert(test); \
assert(result); \
test_context("sym_inspect(" # test ") -> " # result); \
sym = sym_1(test); \
TEST_EQ(sym_inspect(sym, &str), &str); \
TEST_STRNCMP(str.ptr.p, (result), str.size); \
str_clean(&str); \
test_context(NULL); \
} while (0)
TEST_CASE_PROTOTYPE(sym_1);
const s_sym * sym_test_1_test (const s8 *p);
TEST_CASE_PROTOTYPE(sym_inspect);
void sym_test (void)
{
TEST_CASE_RUN(sym_1);
TEST_CASE_RUN(sym_inspect);
}
TEST_CASE(sym_1)
{
const s_sym *mod;
const s_sym *mod_t;
const s_sym *mod_test;
const s_sym *mod_test123;
const s_sym *sym;
const s_sym *sym_123;
const s_sym *sym_ident;
const s_sym *sym_empty;
const s_sym *sym_t;
const s_sym *sym_test;
const s_sym *sym_test123;
SYM_TEST_1("");
sym_empty = sym;
SYM_TEST_1("");
TEST_EQ(sym, sym_empty);
SYM_TEST_1(" ");
SYM_TEST_1(".");
SYM_TEST_1("..");
SYM_TEST_1("...");
SYM_TEST_1("t");
sym_t = sym;
TEST_ASSERT(sym_t != sym_empty);
SYM_TEST_1("T");
mod_t = sym;
TEST_ASSERT(mod_t != sym_empty);
TEST_ASSERT(mod_t != sym_t);
SYM_TEST_1("test");
sym_test = sym;
SYM_TEST_1("Test");
mod_test = sym;
TEST_ASSERT(mod_test != sym_empty);
TEST_ASSERT(mod_test != sym_t);
TEST_ASSERT(mod_test != mod_t);
TEST_ASSERT(mod_test != sym_test);
SYM_TEST_1("123");
sym_123 = sym;
SYM_TEST_1("test123");
sym_test123 = sym;
SYM_TEST_1("Test123");
mod_test123 = sym;
TEST_ASSERT(sym_test123 != mod_test123);
SYM_TEST_1("123.456");
TEST_ASSERT(sym != sym_empty);
TEST_ASSERT(sym != sym_123);
SYM_TEST_1("test123.test456");
sym_ident = sym;
TEST_ASSERT(sym_ident != sym_test123);
SYM_TEST_1("Test123.Test456");
mod = sym;
TEST_ASSERT(mod != mod_test123);
TEST_ASSERT(mod != sym_ident);
SYM_TEST_1("A");
SYM_TEST_1("É");
SYM_TEST_1("Éo");
SYM_TEST_1("Éoà \n\r\t\v\"");
SYM_TEST_1("a");
SYM_TEST_1("é");
SYM_TEST_1("éo");
SYM_TEST_1("éoà \n\r\t\v\"");
}
TEST_CASE_END(sym_1)
TEST_CASE(sym_inspect)
{
SYM_TEST_INSPECT("", ":\"\"");
SYM_TEST_INSPECT(" ", ":\" \"");
SYM_TEST_INSPECT("\n", ":\"\\n\"");
SYM_TEST_INSPECT("\r", ":\"\\r\"");
SYM_TEST_INSPECT("\t", ":\"\\t\"");
SYM_TEST_INSPECT("\v", ":\"\\v\"");
SYM_TEST_INSPECT("\"", ":\"\\\"\"");
SYM_TEST_INSPECT(".", ":\".\"");
SYM_TEST_INSPECT("..", ":\"..\"");
SYM_TEST_INSPECT("...", ":\"...\"");
SYM_TEST_INSPECT(".. .", ":\".. .\"");
SYM_TEST_INSPECT("t", ":t");
SYM_TEST_INSPECT("T", "T");
SYM_TEST_INSPECT("test", ":test");
SYM_TEST_INSPECT("Test", "Test");
SYM_TEST_INSPECT("123", ":123");
SYM_TEST_INSPECT("test123", ":test123");
SYM_TEST_INSPECT("Test123", "Test123");
SYM_TEST_INSPECT("test 123", ":\"test 123\"");
SYM_TEST_INSPECT("Test 123", ":\"Test 123\"");
SYM_TEST_INSPECT("test123.test456", ":\"test123.test456\"");
SYM_TEST_INSPECT("Test123.Test456", ":\"Test123.Test456\"");
SYM_TEST_INSPECT("test123(test456)", ":\"test123(test456)\"");
SYM_TEST_INSPECT("Test123(Test456)", ":\"Test123(Test456)\"");
SYM_TEST_INSPECT("test123{test456}", ":\"test123{test456}\"");
SYM_TEST_INSPECT("Test123{Test456}", ":\"Test123{Test456}\"");
SYM_TEST_INSPECT("É", "É");
SYM_TEST_INSPECT("Éo", "Éo");
SYM_TEST_INSPECT("Éoà \n\r\t\v\"",
":\"Éoà \\n\\r\\t\\v\\\"\"");
SYM_TEST_INSPECT("é", ":é");
SYM_TEST_INSPECT("éo", ":éo");
SYM_TEST_INSPECT("éoà \n\r\t\v\"",
":\"éoà \\n\\r\\t\\v\\\"\"");
}
TEST_CASE_END(sym_inspect)