From 4c4e20994a5c4d248d15ee98255931502e8f02e5 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 12 Oct 2024 08:52:03 -0300 Subject: [PATCH] test --- .../tests/options/option_unwrap_ifexpr_test.v | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 vlib/v/tests/options/option_unwrap_ifexpr_test.v diff --git a/vlib/v/tests/options/option_unwrap_ifexpr_test.v b/vlib/v/tests/options/option_unwrap_ifexpr_test.v new file mode 100644 index 00000000000000..267f67c23c5121 --- /dev/null +++ b/vlib/v/tests/options/option_unwrap_ifexpr_test.v @@ -0,0 +1,28 @@ +type TestSmart = ?string | int + +fn test_simple_case() { + o := ?string('abc') + dump(o) + a := if o == none { + 'none' + } else { + '${o} exists' + } + dump(a) + assert a == 'abc exists' +} + +fn test_comptime_smartcast() { + t := TestSmart(?string('foobar')) + $for v in TestSmart.variants { + if t is v { + $if t is ?string { + if t == none { + panic('error') + } else { + assert t == 'foobar' + } + } + } + } +}