diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-01-12 16:15:10 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-01-12 16:15:10 +0100 |
commit | fdf921c0adff5317e426e798f8a716ca97046383 (patch) | |
tree | d0e27a2e798fb078ff5f9cbb5af409b9c5a21061 /source/tests/defer.test.c | |
parent | d36df5359dcb371d775a9ef10626cd0f7f996002 (diff) | |
download | kit-fdf921c0adff5317e426e798f8a716ca97046383.zip |
Refactor; defer with fblocks
Diffstat (limited to 'source/tests/defer.test.c')
-rw-r--r-- | source/tests/defer.test.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/tests/defer.test.c b/source/tests/defer.test.c new file mode 100644 index 0000000..0eb8557 --- /dev/null +++ b/source/tests/defer.test.c @@ -0,0 +1,37 @@ +#if defined(__clang__) || defined(__APPLE__) +# include "../kit/defer.h" + +# define KIT_TEST_FILE defer_block +# include "../kit/test.h" + +TEST("defer") { + int defer_ref x = 1; + + { + defer { + x = 2; + }; + + x = 3; + } + + REQUIRE_EQ(x, 2); +} + +TEST("defer capture") { + int defer_ref x = 1; + + { + defer { + if (x == 3) + x = 2; + }; + + x = 3; + } + + REQUIRE_EQ(x, 2); +} + +# undef KIT_TEST_FILE +#endif |