foundation-test: Sections: Nowebify.

This commit is contained in:
AwesomeAdam54321 2024-03-09 12:06:34 +08:00
parent 844b7f2148
commit e44d5e1b34
2 changed files with 39 additions and 38 deletions

View file

@ -2,22 +2,23 @@
Choosing which unit test to run on the basis of the command-line arguments. Choosing which unit test to run on the basis of the command-line arguments.
@h Main routine. @ \section{Main routine.}
@d PROGRAM_NAME "foundation-test" <<*>>=
#define PROGRAM_NAME "foundation-test"
@e TEST_STRINGS_CLSW enum TEST_STRINGS_CLSW
@e TEST_RE_CLSW enum TEST_RE_CLSW
@e TEST_DICT_CLSW enum TEST_DICT_CLSW
@e TEST_LITERALS_CLSW enum TEST_LITERALS_CLSW
@e TEST_REPLACEMENT_CLSW enum TEST_REPLACEMENT_CLSW
@e TEST_LISTS_CLSW enum TEST_LISTS_CLSW
@e TEST_STACKS_CLSW enum TEST_STACKS_CLSW
@e TEST_SEMVER_CLSW enum TEST_SEMVER_CLSW
@e TEST_TREES_CLSW enum TEST_TREES_CLSW
@e TEST_JSON_CLSW enum TEST_JSON_CLSW
= <<*>>=
int main(int argc, char **argv) { int main(int argc, char **argv) {
Foundation::start(argc, argv); Foundation::start(argc, argv);
CommandLine::declare_heading(L"inexample: a tool for testing foundation facilities\n"); CommandLine::declare_heading(L"inexample: a tool for testing foundation facilities\n");

View file

@ -2,9 +2,9 @@
A selection of tests for, or demonstrations of, foundation features. A selection of tests for, or demonstrations of, foundation features.
@h Strings. @ \section{Strings.}
= <<*>>=
void Unit::test_strings(void) { void Unit::test_strings(void) {
text_stream *S = Str::new_from_wide_string(L"Jack and Jill"); text_stream *S = Str::new_from_wide_string(L"Jack and Jill");
PRINT("Setup: %S\n", S); PRINT("Setup: %S\n", S);
@ -36,9 +36,9 @@ void Unit::test_strings(void) {
PRINT("%S ci-ne %S? %d\n", A, B, Str::ne_insensitive(A, B)); PRINT("%S ci-ne %S? %d\n", A, B, Str::ne_insensitive(A, B));
} }
@h Literals. @ \section{Literals.}
= <<*>>=
void Unit::test_literals(void) { void Unit::test_literals(void) {
LOG("This is \"tricky"); LOG("%S", I"bananas"); LOG("This is \"tricky"); LOG("%S", I"bananas");
int z = '"'; LOG("%S%d", I"peaches", z); int z = '"'; LOG("%S%d", I"peaches", z);
@ -52,9 +52,9 @@ void Unit::test_literals(void) {
else PRINT("and A == B as pointers, too\n"); else PRINT("and A == B as pointers, too\n");
} }
@h Dictionaries. @ \section{Dictionaries.}
= <<*>>=
void Unit::test_dictionaries(text_stream *arg) { void Unit::test_dictionaries(text_stream *arg) {
dictionary *D = Dictionaries::new(2, TRUE); dictionary *D = Dictionaries::new(2, TRUE);
Dictionaries::log(STDOUT, D); Dictionaries::log(STDOUT, D);
@ -103,9 +103,9 @@ void Unit::test_dictionaries_helper2(text_stream *text, text_file_position *tfp,
Errors::in_text_file("test case won't parse", tfp); Errors::in_text_file("test case won't parse", tfp);
} }
@h Regexp. @ \section{Regexp.}
= <<*>>=
void Unit::test_regexp(text_stream *arg) { void Unit::test_regexp(text_stream *arg) {
filename *F = Filenames::from_text(arg); filename *F = Filenames::from_text(arg);
TextFiles::read(F, FALSE, "unable to read file of test cases", TRUE, TextFiles::read(F, FALSE, "unable to read file of test cases", TRUE,
@ -135,9 +135,9 @@ void Unit::test_regexp_helper(text_stream *text, text_file_position *tfp, void *
Errors::in_text_file("test case won't parse", tfp); Errors::in_text_file("test case won't parse", tfp);
} }
@h Replacements. @ \section{Replacements.}
= <<*>>=
void Unit::test_replacement(text_stream *arg) { void Unit::test_replacement(text_stream *arg) {
filename *F = Filenames::from_text(arg); filename *F = Filenames::from_text(arg);
TextFiles::read(F, FALSE, "unable to read file of test cases", TRUE, TextFiles::read(F, FALSE, "unable to read file of test cases", TRUE,
@ -161,9 +161,9 @@ void Unit::test_replacement_helper(text_stream *text, text_file_position *tfp, v
Errors::in_text_file("test case won't parse", tfp); Errors::in_text_file("test case won't parse", tfp);
} }
@h Linked lists. @ \section{Linked lists.}
= <<*>>=
void Unit::test_linked_lists(void) { void Unit::test_linked_lists(void) {
linked_list *test_list = NEW_LINKED_LIST(text_stream); linked_list *test_list = NEW_LINKED_LIST(text_stream);
PRINT("List (which should be empty) contains:\n"); PRINT("List (which should be empty) contains:\n");
@ -186,9 +186,9 @@ void Unit::test_linked_lists(void) {
PRINT("Last is: %S\n", LAST_IN_LINKED_LIST(text_stream, test_list)); PRINT("Last is: %S\n", LAST_IN_LINKED_LIST(text_stream, test_list));
} }
@h Stacks. @ \section{Stacks.}
= <<*>>=
void Unit::test_stacks(void) { void Unit::test_stacks(void) {
lifo_stack *test_stack = NEW_LIFO_STACK(text_stream); lifo_stack *test_stack = NEW_LIFO_STACK(text_stream);
PRINT("Top of stack is: %S\n", TOP_OF_LIFO_STACK(text_stream, test_stack)); PRINT("Top of stack is: %S\n", TOP_OF_LIFO_STACK(text_stream, test_stack));
@ -213,9 +213,9 @@ void Unit::test_stacks(void) {
if (LIFO_STACK_EMPTY(text_stream, test_stack)) PRINT("Stack is empty\n"); if (LIFO_STACK_EMPTY(text_stream, test_stack)) PRINT("Stack is empty\n");
} }
@h Semantic versions. @ \section{Semantic versions.}
= <<*>>=
void Unit::test_range(OUTPUT_STREAM, text_stream *text) { void Unit::test_range(OUTPUT_STREAM, text_stream *text) {
semantic_version_number V = VersionNumbers::from_text(text); semantic_version_number V = VersionNumbers::from_text(text);
semver_range *R = VersionNumberRanges::compatibility_range(V); semver_range *R = VersionNumberRanges::compatibility_range(V);
@ -316,16 +316,16 @@ void Unit::test_semver(void) {
Unit::test_intersect(STDOUT, I"6.4.2", -1, I"3.5.5", -1); Unit::test_intersect(STDOUT, I"6.4.2", -1, I"3.5.5", -1);
} }
@h Trees. @ \section{Trees.}
@e prince_CLASS enum prince_CLASS
@e princess_CLASS enum princess_CLASS
= <<*>>=
DECLARE_CLASS(prince) DECLARE_CLASS(prince)
DECLARE_CLASS(princess) DECLARE_CLASS(princess)
@ = <<*>>=
typedef struct prince { typedef struct prince {
struct text_stream *boys_name; struct text_stream *boys_name;
CLASS_DEFINITION CLASS_DEFINITION
@ -339,7 +339,7 @@ typedef struct princess {
tree_node_type *M = NULL, *F = NULL; tree_node_type *M = NULL, *F = NULL;
@ = <<*>>=
void Unit::test_trees(void) { void Unit::test_trees(void) {
tree_type *TT = Trees::new_type(I"royal family", &Unit::verifier); tree_type *TT = Trees::new_type(I"royal family", &Unit::verifier);
heterogeneous_tree *royalty = Trees::new(TT); heterogeneous_tree *royalty = Trees::new(TT);
@ -393,7 +393,7 @@ int Unit::princess_verifier(tree_node *N) {
return TRUE; return TRUE;
} }
@ = <<*>>=
void Unit::show_tree(text_stream *OUT, heterogeneous_tree *T) { void Unit::show_tree(text_stream *OUT, heterogeneous_tree *T) {
WRITE("%S\n", T->type->name); WRITE("%S\n", T->type->name);
INDENT; INDENT;
@ -415,9 +415,9 @@ int Unit::visit(tree_node *N, void *state, int L) {
return TRUE; return TRUE;
} }
@h JSON. @ \section{JSON.}
= <<*>>=
dictionary *known_JSON_reqs = NULL; dictionary *known_JSON_reqs = NULL;
void Unit::test_JSON(text_stream *arg) { void Unit::test_JSON(text_stream *arg) {