-
Notifications
You must be signed in to change notification settings - Fork 0
Add test cases from codex #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arthurvergacas
wants to merge
19
commits into
develop
Choose a base branch
from
add-test-cases-from-codex
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1708f04
vinumc/test: add test helper to hold compile helper for tests
arthurvergacas 41337c9
vinumc/test: use compiler function instead of binary in tests where a…
arthurvergacas 582a0a1
vinumc/tests: Add tests for the Codex Vinum overview section
arthurvergacas 292a9e8
vinumc/tests: Add tests for user-defined functions
arthurvergacas 4f023ab
vinumc/tests: Add tests for symbol expansion and binding
arthurvergacas 6556a42
vinumc/tests: Add tests for shot aliases
arthurvergacas 632d31d
vinumc/tests: Add tests for compound symbols
arthurvergacas cb372c2
vinumc/tests: Add tests for scope inheritance and locality
arthurvergacas b3cc04e
vinumc/tests: Add tests for scope and label namespaces
arthurvergacas ee3ad86
vinumc/tests: Add tests for document-scope bindings
arthurvergacas 01cd0a8
vinumc/tests: Add tests for import, overwrite and include
arthurvergacas 98fef8a
vinumc/tests: Add tests for blank reduction on expansion
arthurvergacas 1d9e34f
vinumc/tests: Add tests for escapes and literal blocks
arthurvergacas fcb5760
vinumc/tests: Add tests for pipe filter composition
arthurvergacas e8a4139
vinumc/tests: Add tests for automatic variables
arthurvergacas b635c4d
vinumc/tests: Add tests for deferral retention policies
arthurvergacas 80b7bf3
vinumc/tests: Add tests for if/then/else control structures
arthurvergacas 7e1285d
vinumc/tests: Add tests for preprocessor directives
arthurvergacas 80f4949
vinumc/tests: Add tests for macro replacement
arthurvergacas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #include <vunit/vunit.h> | ||
|
|
||
| #include "test_helpers.h" | ||
|
|
||
| void test_argument_automatic(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[shout : *** [argument] ***]\n" | ||
| "[shout If you drink, don't drive]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "*** If you drink, don't drive ***"); | ||
| } | ||
|
|
||
| void test_automatic_empty_in_definition(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[a : argument was: [argument]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, ""); | ||
| } | ||
|
|
||
| void test_symbol_automatic(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[par : [symbol] said: [argument]]\n" | ||
| "[par Red grapes]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "par said: Red grapes"); | ||
| } | ||
|
|
||
| void test_count_automatic(struct vunit_test_ctx *ctx) { | ||
| char *out = | ||
| compile_program(ctx, "[item One]\n" | ||
| "[item Two]\n" | ||
| "[item Vinum animi speculum est [label foo]]\n" | ||
| "[par The proverb in item [foo_count] in the list above is " | ||
| "due to Alcuin of York (c. 735-804).]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, | ||
| "[item One] [item Two] [item Vinum animi speculum est ] " | ||
| "[par The proverb in item 3 in the list above is due to " | ||
| "Alcuin of York (c. 735-804).]"); | ||
| } | ||
|
|
||
| void test_index_automatic_non_resetting(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[section\n" | ||
| "[footnote [label a] first]\n" | ||
| "]\n" | ||
| "[section\n" | ||
| "[footnote [label b] second]\n" | ||
| "]\n" | ||
| "[a_index] and [b_index]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, | ||
| "[section [footnote first] ] [section [footnote second] ] 1 and 2"); | ||
| } | ||
|
|
||
| void test_content_reserved(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[echo : [content]]\n" | ||
| "[echo hello]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, ""); | ||
| } | ||
|
|
||
| struct vunit_test tests[] = { | ||
| { .name = "argument automatic inside a reference block", | ||
| .test_func = test_argument_automatic, | ||
| .todo = true, | ||
| .todo_msg = "[argument] automatic not expanded in references" }, | ||
| { .name = "automatic variables are empty inside a definition", | ||
| .test_func = test_automatic_empty_in_definition }, | ||
| { .name = "symbol automatic equals the block's name", | ||
| .test_func = test_symbol_automatic, | ||
| .todo = true, | ||
| .todo_msg = "[symbol] automatic not implemented" }, | ||
| { .name = "count is the sequential block count in the scope", | ||
| .test_func = test_count_automatic, | ||
| .todo = true, | ||
| .todo_msg = "[count] automatic not implemented" }, | ||
| { .name = "index is non-resetting across scopes", | ||
| .test_func = test_index_automatic_non_resetting, | ||
| .todo = true, | ||
| .todo_msg = "[index] automatic not implemented" }, | ||
| { .name = "content is reserved and cannot recurse", | ||
| .test_func = test_content_reserved, | ||
| .todo = true, | ||
| .todo_msg = "[content] reserved automatic not implemented" }, | ||
| {}, | ||
| }; | ||
|
|
||
| VUNIT_TEST_SUITE(tests) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include <vunit/vunit.h> | ||
|
|
||
| #include "test_helpers.h" | ||
|
|
||
| void test_blank_reduction_across_newline(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[ brunello : Brunello di\n" | ||
| "Montalcino ]\n" | ||
| "Try [brunello], a great wine from Tuscany.\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Try Brunello di Montalcino, a great wine from Tuscany."); | ||
| } | ||
|
|
||
| void test_leading_trailing_blanks_suppressed(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[a : padded value ]\n" | ||
| "|[a]|\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "|padded value|"); | ||
| } | ||
|
|
||
| void test_symbol_field_blanks_ignored(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[ wine : Merlot]\n" | ||
| "[wine]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Merlot"); | ||
| } | ||
|
|
||
| struct vunit_test tests[] = { | ||
| { .name = "Blank reduction collapses newlines into one space", | ||
| .test_func = test_blank_reduction_across_newline, | ||
| .todo = true, | ||
| .todo_msg = "blank reduction across newlines not implemented" }, | ||
| { .name = "Leading and trailing blanks are suppressed", | ||
| .test_func = test_leading_trailing_blanks_suppressed, | ||
| .todo = true, | ||
| .todo_msg = "leading/trailing blank suppression not implemented" }, | ||
| { .name = "Blanks around symbol field are ignored", | ||
| .test_func = test_symbol_field_blanks_ignored }, | ||
| {}, | ||
| }; | ||
|
|
||
| VUNIT_TEST_SUITE(tests) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #include <vunit/vunit.h> | ||
|
|
||
| #include "test_helpers.h" | ||
|
|
||
| void test_flat_compound_projection(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, | ||
| "[author:\n" | ||
| "[name: Wine Maker]\n" | ||
| "[email: vinum@example.com]\n" | ||
| "]\n" | ||
| "Our friend [author_name] can be reached at [author_email].\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Our friend Wine Maker can be reached at vinum@example.com."); | ||
| } | ||
|
|
||
| void test_nested_compound_projection(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program( | ||
| ctx, "[author:\n" | ||
| "[name:Wine Maker]\n" | ||
| "[email: vinum@example.com]\n" | ||
| "[company :\n" | ||
| "[name : The Amazing Vineyards]\n" | ||
| "[site : www.example.com]\n" | ||
| "]\n" | ||
| "]\n" | ||
| "Contact [author_name] through [author_email], or make an appointment at " | ||
| "[author_company_name] by visiting [author_company_site].\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, | ||
| "Contact Wine Maker through vinum@example.com, or make an " | ||
| "appointment at The Amazing Vineyards by visiting www.example.com."); | ||
| } | ||
|
|
||
| void test_qualified_names_equivalence(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[author_name : Wine Maker]\n" | ||
| "[author_email : vinum@example.com]\n" | ||
| "[author_company_name : The Amazing Vineyards]\n" | ||
| "[author_company_site : www.example.com]\n" | ||
| "[author_name] at [author_company_name]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Wine Maker at The Amazing Vineyards"); | ||
| } | ||
|
|
||
| void test_extend_compound_later(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[wine_body : full]\n" | ||
| "[wine_finish : long]\n" | ||
| "[wine_ballance : harmonious]\n" | ||
| "[wine_body] [wine_finish] [wine_ballance]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "full long harmonious"); | ||
| } | ||
|
|
||
| void test_unnamed_fields_auto_index(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[grape:\n" | ||
| "[: Cabernet Franc]\n" | ||
| "[: Pinot Noir]\n" | ||
| "[: Sauvignon Blanc]\n" | ||
| "]\n" | ||
| "[grape_1] / [grape_2] / [grape_3]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Cabernet Franc / Pinot Noir / Sauvignon Blanc"); | ||
| } | ||
|
|
||
| void test_compound_projects_outer_text(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[wine: cabernet\n" | ||
| "[body : full]\n" | ||
| "sauvignon\n" | ||
| "[finish : long]\n" | ||
| "]\n" | ||
| "[wine] // [wine_body] // [wine_finish]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "cabernet sauvignon // full // long"); | ||
| } | ||
|
|
||
| struct vunit_test tests[] = { | ||
| { .name = "Flat compound projects fields", | ||
| .test_func = test_flat_compound_projection, | ||
| .todo = true, | ||
| .todo_msg = "compound projection (foo_bar) not implemented" }, | ||
| { .name = "Nested compound projects with underscore path", | ||
| .test_func = test_nested_compound_projection, | ||
| .todo = true, | ||
| .todo_msg = "nested compound projection not implemented" }, | ||
| { .name = "Qualified-name form is equivalent to compound form", | ||
| .test_func = test_qualified_names_equivalence, | ||
| .todo = true, | ||
| .todo_msg = "qualified-name form not implemented" }, | ||
| { .name = "Extending a compound via qualified name", | ||
| .test_func = test_extend_compound_later, | ||
| .todo = true, | ||
| .todo_msg = "compound extension via qualified name not implemented" }, | ||
| { .name = "Unnamed inner fields get sequential integer keys", | ||
| .test_func = test_unnamed_fields_auto_index, | ||
| .todo = true, | ||
| .todo_msg = "auto-indexed unnamed compound fields not implemented" }, | ||
| { .name = "Outer compound symbol projects non-block content", | ||
| .test_func = test_compound_projects_outer_text, | ||
| .todo = true, | ||
| .todo_msg = "outer compound projection of free text not implemented" }, | ||
| {}, | ||
| }; | ||
|
|
||
| VUNIT_TEST_SUITE(tests) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #include <vunit/vunit.h> | ||
|
|
||
| #include "test_helpers.h" | ||
|
|
||
| void test_if_truthy(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[if 1 [then: A] [else: B]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "A"); | ||
| } | ||
|
|
||
| void test_if_empty_is_false(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[empty :]\n" | ||
| "[if [empty] [then: A] [else: B]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "B"); | ||
| } | ||
|
|
||
| void test_if_zero_is_false(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[if 0 [then: A] [else: B]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "B"); | ||
| } | ||
|
|
||
| void test_if_with_user_predicate(struct vunit_test_ctx *ctx) { | ||
| // Stand-in for the Codex's [is_workday] example: use a user-defined flag | ||
| // so the test is deterministic and stays independent from VSL. | ||
| char *out = compile_program( | ||
| ctx, "[workday : 1]\n" | ||
| "Order your ticket [if [workday] [then: today] [else: by Monday]]!\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Order your ticket today!"); | ||
| } | ||
|
|
||
| struct vunit_test tests[] = { | ||
| { .name = "if with truthy expression picks then", | ||
| .test_func = test_if_truthy, | ||
| .todo = true, | ||
| .todo_msg = "[if ...] control structure not implemented" }, | ||
| { .name = "if with empty expression picks else", | ||
| .test_func = test_if_empty_is_false, | ||
| .todo = true, | ||
| .todo_msg = "[if ...] control structure not implemented" }, | ||
| { .name = "if with 0 picks else", | ||
| .test_func = test_if_zero_is_false, | ||
| .todo = true, | ||
| .todo_msg = "[if ...] control structure not implemented" }, | ||
| { .name = "if branching on a user-defined predicate", | ||
| .test_func = test_if_with_user_predicate, | ||
| .todo = true, | ||
| .todo_msg = "[if ...] control structure not implemented" }, | ||
| {}, | ||
| }; | ||
|
|
||
| VUNIT_TEST_SUITE(tests) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #include <vunit/vunit.h> | ||
|
|
||
| #include "test_helpers.h" | ||
|
|
||
| // Deferral is a core language concept, but the Codex illustrates it with VSL | ||
| // author functions like [first] and [count]. These tests stand in for them | ||
| // with user-defined functions so only the language semantics are under test. | ||
|
|
||
| void test_nested_author_functions(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[winegrape : Vitis vinifera]\n" | ||
| "[echo : [argument]]\n" | ||
| "[echo [winegrape]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Vitis vinifera"); | ||
| } | ||
|
|
||
| void test_editor_function_preserved_through_vinification(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[defer foreign]\n" | ||
| "[winegrape : [foreign Vitis vinifera]]\n" | ||
| "[winegrape] originates from the Near East\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "[foreign Vitis vinifera] originates from the Near East"); | ||
| } | ||
|
|
||
| void test_scope_lifting_preserves_wrapper(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program( | ||
| ctx, "[defer foreign]\n" | ||
| "[winegrape : [foreign Vitis vinifera]]\n" | ||
| "[echo : [argument]]\n" | ||
| "Other species of [echo [winegrape]] are mainly used for breeding.\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ( | ||
| ctx, out, | ||
| "Other species of [foreign Vitis vinifera] are mainly used for breeding."); | ||
| } | ||
|
|
||
| void test_discard_policy_drops_editor_wrapper(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[defer foreign]\n" | ||
| "[strip : [policy : discard][argument]]\n" | ||
| "[strip [foreign a priori] [foreign in locus]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "a priori in locus"); | ||
| } | ||
|
|
||
| void test_user_function_preserves_nested_editor(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[defer foreign]\n" | ||
| "[my : [argument]]\n" | ||
| "[my [foreign Vitis vinifera]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "[foreign Vitis vinifera]"); | ||
| } | ||
|
|
||
| void test_policy_discard_declaration(struct vunit_test_ctx *ctx) { | ||
| char *out = compile_program(ctx, "[defer foreign]\n" | ||
| "[plain : [policy : discard][argument]]\n" | ||
| "[plain [foreign Vitis vinifera]]\n"); | ||
|
|
||
| VUNIT_ASSERT_STREQ(ctx, out, "Vitis vinifera"); | ||
| } | ||
|
|
||
| struct vunit_test tests[] = { | ||
| { .name = "Plain nested user functions use applicative order", | ||
| .test_func = test_nested_author_functions, | ||
| .todo = true, | ||
| .todo_msg = "[argument] expansion in nested user functions not implemented" }, | ||
| { .name = "Editor function is preserved across vinification", | ||
| .test_func = test_editor_function_preserved_through_vinification, | ||
| .todo = true, | ||
| .todo_msg = "[defer ...] editor function preservation not implemented" }, | ||
| { .name = "Scope lifting preserves the editor wrapper", | ||
| .test_func = test_scope_lifting_preserves_wrapper, | ||
| .todo = true, | ||
| .todo_msg = "[defer ...] scope lifting not implemented" }, | ||
| { .name = "[policy : discard] drops deferred editor wrappers from the argument", | ||
| .test_func = test_discard_policy_drops_editor_wrapper, | ||
| .todo = true, | ||
| .todo_msg = "[policy : discard] not implemented" }, | ||
| { .name = "User-defined functions default to preserve policy", | ||
| .test_func = test_user_function_preserves_nested_editor, | ||
| .todo = true, | ||
| .todo_msg = "default preserve policy for user functions not implemented" }, | ||
| { .name = "[policy : discard] explicitly set inside a user function", | ||
| .test_func = test_policy_discard_declaration, | ||
| .todo = true, | ||
| .todo_msg = "[policy : discard] inside user function not implemented" }, | ||
| {}, | ||
| }; | ||
|
|
||
| VUNIT_TEST_SUITE(tests) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank reduction features, these features are already implemented, however the vinum compiler does not support top-level text (issue #48, fixed by #55, reverted for some reason I don't remember in #61) requiring these tests to be wrapped in a parent block to work.