|
| 1 | +import wit.test.list_in_variant.runner; |
| 2 | +import wit.common; |
| 3 | + |
| 4 | +@witExport("$root", "run") |
| 5 | +void run() { |
| 6 | + const WitString[2] hw = ["hello".witList, "world".witList]; |
| 7 | + { |
| 8 | + auto result = listInOption(some(hw[].witList)); |
| 9 | + scope(exit) result.witFree; |
| 10 | + |
| 11 | + assert(result == "hello,world"); |
| 12 | + } |
| 13 | + { |
| 14 | + auto result = listInOption(none!(WitList!WitString)); |
| 15 | + scope(exit) result.witFree; |
| 16 | + |
| 17 | + assert(result == "none"); |
| 18 | + } |
| 19 | + |
| 20 | + const WitString[3] fbb_data = ["foo".witList, "bar".witList, "baz".witList]; |
| 21 | + auto fbb = PayloadOrEmpty.withData(fbb_data.witList); |
| 22 | + { |
| 23 | + auto result = listInVariant(fbb); |
| 24 | + scope(exit) result.witFree; |
| 25 | + |
| 26 | + assert(result == "foo,bar,baz"); |
| 27 | + } |
| 28 | + { |
| 29 | + auto result = listInVariant(PayloadOrEmpty.empty); |
| 30 | + scope(exit) result.witFree; |
| 31 | + |
| 32 | + assert(result == "empty"); |
| 33 | + } |
| 34 | + |
| 35 | + const WitString[3] abc = ["a".witList, "b".witList, "c".witList]; |
| 36 | + { |
| 37 | + auto result = listInResult(Result!(WitList!WitString, WitString).ok(abc[].witList)); |
| 38 | + scope(exit) result.witFree; |
| 39 | + |
| 40 | + assert(result == "a,b,c"); |
| 41 | + } |
| 42 | + { |
| 43 | + auto result = listInResult(Result!(WitList!WitString, WitString).err("oops".witList)); |
| 44 | + scope(exit) result.witFree; |
| 45 | + |
| 46 | + assert(result == "err:oops"); |
| 47 | + } |
| 48 | + |
| 49 | + const WitString[2] hw2 = ["hello".witList, "world".witList]; |
| 50 | + auto s1 = listInOptionWithReturn(some(hw2.witList)); |
| 51 | + { |
| 52 | + auto result = s1.count; |
| 53 | + scope(exit) result.witFree; |
| 54 | + |
| 55 | + assert(result == 2); |
| 56 | + } |
| 57 | + { |
| 58 | + auto result = s1.label; |
| 59 | + scope(exit) result.witFree; |
| 60 | + |
| 61 | + assert(result == "hello,world"); |
| 62 | + } |
| 63 | + auto s2 = listInOptionWithReturn(none!(WitList!WitString)); |
| 64 | + { |
| 65 | + auto result = s2.count; |
| 66 | + scope(exit) result.witFree; |
| 67 | + |
| 68 | + assert(result == 0); |
| 69 | + } |
| 70 | + { |
| 71 | + auto result = s2.label; |
| 72 | + scope(exit) result.witFree; |
| 73 | + |
| 74 | + assert(result == "none"); |
| 75 | + } |
| 76 | + |
| 77 | + const WitString[3] xyz = ["x".witList, "y".witList, "z".witList]; |
| 78 | + { |
| 79 | + auto result = topLevelList(xyz.witList); |
| 80 | + scope(exit) result.witFree; |
| 81 | + |
| 82 | + assert(result == "x,y,z"); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +alias Exports = wit.test.list_in_variant.runner.Exports!( |
| 87 | + run |
| 88 | +); |
0 commit comments