Hash :
f990b98e
Author :
Thomas de Grivel
Date :
2022-12-06T13:37:43
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
/* c3
* Copyright 2022 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software excepted
* on Apple computers 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"
const s_sym * sym_test_1_test (const s8 *p)
{
uw len;
const s_sym *sym;
len = strlen(p);
TEST_ASSERT((sym = sym_1(p)));
TEST_EQ(sym->str.size, len);
TEST_EQ(strncmp(p, sym->str.ptr.p, len), 0);
TEST_EQ(sym_1(p), sym_1(p));
return sym;
}
void sym_test_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_empty;
const s_sym *sym_t;
const s_sym *sym_test;
const s_sym *sym_test123;
sym_empty = sym_test_1_test("");
TEST_EQ(sym_test_1_test(""), sym_empty);
sym_test_1_test(" ");
sym_test_1_test(".");
sym_test_1_test("..");
sym_test_1_test("...");
sym_t = sym_test_1_test("t");
TEST_ASSERT(sym_t != sym_empty);
mod_t = sym_test_1_test("T");
TEST_ASSERT(mod_t != sym_empty);
TEST_ASSERT(mod_t != sym_t);
sym_test = sym_test_1_test("test");
mod_test = sym_test_1_test("Test");
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_123 = sym_test_1_test("123");
sym_test123 = sym_test_1_test("test123");
mod_test123 = sym_test_1_test("Test123");
TEST_ASSERT(sym_test123 != mod_test123);
sym = sym_test_1_test("123.456");
TEST_ASSERT(sym != sym_empty);
TEST_ASSERT(sym != sym_123);
sym = sym_test_1_test("test123.test456");
TEST_ASSERT(sym != sym_test123);
mod = sym_test_1_test("Test123.Test456");
TEST_ASSERT(mod != mod_test123);
TEST_ASSERT(mod != sym);
sym_test_1_test("A");
sym_test_1_test("É");
sym_test_1_test("Éo");
sym_test_1_test("Éoà \n\r\t\v\"");
sym_test_1_test("a");
sym_test_1_test("é");
sym_test_1_test("éo");
sym_test_1_test("éoà \n\r\t\v\"");
}
void sym_test_delete_all ()
{
sym_delete_all();
test_ok();
}
#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)
void sym_test_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\\\"\"");
}
void sym_test ()
{
sym_test_delete_all();
sym_test_1();
sym_test_delete_all();
sym_test_inspect();
sym_test_delete_all();
}