Hash :
600f4487
Author :
Thomas de Grivel
Date :
2024-07-20T19:00:22
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
/* kc3
* Copyright 2022,2023,2024 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 "../libkc3/str.h"
#include "../libkc3/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 INSPECT_TEST_SYM(test, result) \
do { \
const s_sym *sym; \
s_str str; \
assert(test); \
assert(result); \
test_context("inspect_sym(" # test ") -> " # result); \
sym = sym_1(test); \
TEST_EQ(inspect_sym(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);
void sym_test (void)
{
TEST_CASE_RUN(sym_1);
}
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)