From 03e8366b7e11e1b6c971f70d22fef07f7ad32448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Tue, 20 Feb 2024 23:49:31 +0300 Subject: optionals v0.2.0: custom-named optionals Can now declare custom named optionals, in order to declare optionals for two-token type names. --- optional/optional-test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'optional/optional-test.c') diff --git a/optional/optional-test.c b/optional/optional-test.c index 88577d3..73597e5 100644 --- a/optional/optional-test.c +++ b/optional/optional-test.c @@ -2,9 +2,11 @@ #include "../utest/utest.h" #include +#include -OPTIONALDEC(int); -OPTIONALDEC(char); +DECL_OPTIONAL(int); +DECL_OPTIONAL(char); +DECL_NAMED_OPTIONAL(str, char *); struct my_struct { OPTIONAL(int) a; @@ -27,6 +29,12 @@ TEST_BEGIN(test_optional_example) OPTIONAL(char) y = OPTNONE; OPTIONAL(char) z = OPTSOME('z'); + + OPTIONAL(str) s = OPTSOME("hello, world!"); + + expect(!strcmp(opt_default(s, "NULL!"), "hello, world!"), + "expected to contain string \"hello, world!\""); + float xy, xz; expect(opt_has(my.a), "expected to contain something"); -- cgit v1.2.3