| author | |
| committer | |
| log | dab3ddab4539b79b1dee4bc82f78c1b3f41ffeb2 |
| tree | b792312c1cf2025041a3370fc9b59b91ff53c9c0 |
| parent | 5a717187571e5eed99087a9b4359f6ac194db1cf |
13 files changed, 286 insertions(+), 284 deletions(-)
test/cases3/array.zig+12| ... | ... | @@ -43,6 +43,18 @@ fn arrayLiteral() { |
| 43 | 43 | assert(hex_mult[1] == 256); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | fn arrayDotLenConstExpr() { | |
| 47 | @setFnTest(this); | |
| 48 | ||
| 49 | assert(@staticEval(some_array.len) == 4); | |
| 50 | } | |
| 51 | ||
| 52 | const ArrayDotLenConstExpr = struct { | |
| 53 | y: [some_array.len]u8, | |
| 54 | }; | |
| 55 | const some_array = []u8 {0, 1, 2, 3}; | |
| 56 | ||
| 57 | ||
| 46 | 58 | |
| 47 | 59 | |
| 48 | 60 | // TODO const assert = @import("std").debug.assert; |
test/cases3/bool.zig+9| ... | ... | @@ -20,6 +20,15 @@ fn nonConstCastBoolToInt(t: bool, f: bool) { |
| 20 | 20 | assert(i32(f) == i32(0)); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | fn boolCmp() { | |
| 24 | @setFnTest(this); | |
| 25 | ||
| 26 | assert(testBoolCmp(true, false) == false); | |
| 27 | } | |
| 28 | fn testBoolCmp(a: bool, b: bool) -> bool { | |
| 29 | a == b | |
| 30 | } | |
| 31 | ||
| 23 | 32 | // TODO const assert = @import("std").debug.assert; |
| 24 | 33 | fn assert(ok: bool) { |
| 25 | 34 | if (!ok) |
test/cases3/cast.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | //fn intToPtrCast() { | |
| 2 | // @setFnTest(this); | |
| 3 | // | |
| 4 | // const x = isize(13); | |
| 5 | // const y = (&u8)(x); | |
| 6 | // const z = usize(y); | |
| 7 | // assert(z == 13); | |
| 8 | //} | |
| 9 | ||
| 10 | // TODO const assert = @import("std").debug.assert; | |
| 11 | fn assert(ok: bool) { | |
| 12 | if (!ok) | |
| 13 | @unreachable(); | |
| 14 | } |
test/cases3/error.zig+30-1| ... | ... | @@ -25,8 +25,11 @@ fn gimmeItBroke() -> []const u8 { |
| 25 | 25 | |
| 26 | 26 | fn errorName() { |
| 27 | 27 | @setFnTest(this); |
| 28 | assert(memeql(@errorName(error.ItBroke), "ItBroke")); | |
| 28 | assert(memeql(@errorName(error.AnError), "AnError")); | |
| 29 | assert(memeql(@errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 29 | 30 | } |
| 31 | error AnError; | |
| 32 | error ALongerErrorName; | |
| 30 | 33 | |
| 31 | 34 | |
| 32 | 35 | fn errorValues() { |
| ... | ... | @@ -53,6 +56,32 @@ fn shouldBeNotEqual(a: error, b: error) { |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | 58 | |
| 59 | fn errBinaryOperator() { | |
| 60 | @setFnTest(this); | |
| 61 | ||
| 62 | const a = errBinaryOperatorG(true) %% 3; | |
| 63 | const b = errBinaryOperatorG(false) %% 3; | |
| 64 | assert(a == 3); | |
| 65 | assert(b == 10); | |
| 66 | } | |
| 67 | error ItBroke; | |
| 68 | fn errBinaryOperatorG(x: bool) -> %isize { | |
| 69 | if (x) { | |
| 70 | error.ItBroke | |
| 71 | } else { | |
| 72 | isize(10) | |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 76 | ||
| 77 | fn unwrapSimpleValueFromError() { | |
| 78 | @setFnTest(this); | |
| 79 | ||
| 80 | const i = %%unwrapSimpleValueFromErrorDo(); | |
| 81 | assert(i == 13); | |
| 82 | } | |
| 83 | fn unwrapSimpleValueFromErrorDo() -> %isize { 13 } | |
| 84 | ||
| 56 | 85 | |
| 57 | 86 | |
| 58 | 87 |
test/cases3/eval.zig+20-6| ... | ... | @@ -1,13 +1,16 @@ |
| 1 | fn fib(x: i32) -> i32 { | |
| 2 | if (x < 2) x else fib(x - 1) + fib(x - 2) | |
| 3 | } | |
| 4 | const fib_7 = fib(7); | |
| 5 | fn compileTimeFib() { | |
| 1 | fn compileTimeRecursion() { | |
| 6 | 2 | @setFnTest(this); |
| 7 | assert(fib_7 == 13); | |
| 3 | ||
| 4 | assert(some_data.len == 21); | |
| 5 | } | |
| 6 | var some_data: [usize(fibbonaci(7))]u8 = undefined; | |
| 7 | fn fibbonaci(x: i32) -> i32 { | |
| 8 | if (x <= 1) return 1; | |
| 9 | return fibbonaci(x - 1) + fibbonaci(x - 2); | |
| 8 | 10 | } |
| 9 | 11 | |
| 10 | 12 | |
| 13 | ||
| 11 | 14 | fn unwrapAndAddOne(blah: ?i32) -> i32 { |
| 12 | 15 | return ??blah + 1; |
| 13 | 16 | } |
| ... | ... | @@ -40,6 +43,17 @@ fn inlineVariableGetsResultOfConstIf() { |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | |
| 46 | fn staticFunctionEvaluation() { | |
| 47 | @setFnTest(this); | |
| 48 | ||
| 49 | assert(statically_added_number == 3); | |
| 50 | } | |
| 51 | const statically_added_number = staticAdd(1, 2); | |
| 52 | fn staticAdd(a: i32, b: i32) -> i32 { a + b } | |
| 53 | ||
| 54 | ||
| 55 | ||
| 56 | ||
| 43 | 57 | |
| 44 | 58 | // TODO const assert = @import("std").debug.assert; |
| 45 | 59 | fn assert(ok: bool) { |
test/cases3/fn.zig+12| ... | ... | @@ -60,6 +60,18 @@ fn separateBlockScopes() { |
| 60 | 60 | assert(c == 10); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | fn callFnWithEmptyString() { | |
| 64 | @setFnTest(this); | |
| 65 | ||
| 66 | acceptsString(""); | |
| 67 | } | |
| 68 | ||
| 69 | fn acceptsString(foo: []u8) { } | |
| 70 | ||
| 71 | ||
| 72 | fn @"weird function name"() { | |
| 73 | @setFnTest(this); | |
| 74 | } | |
| 63 | 75 | |
| 64 | 76 | |
| 65 | 77 | // TODO const assert = @import("std").debug.assert; |
test/cases3/if.zig+20| ... | ... | @@ -24,3 +24,23 @@ fn firstEqlThird(a: i32, b: i32, c: i32) { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
| 27 | fn elseIfExpression() { | |
| 28 | @setFnTest(this); | |
| 29 | ||
| 30 | assert(elseIfExpressionF(1) == 1); | |
| 31 | } | |
| 32 | fn elseIfExpressionF(c: u8) -> u8 { | |
| 33 | if (c == 0) { | |
| 34 | 0 | |
| 35 | } else if (c == 1) { | |
| 36 | 1 | |
| 37 | } else { | |
| 38 | u8(2) | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | // TODO const assert = @import("std").debug.assert; | |
| 43 | fn assert(ok: bool) { | |
| 44 | if (!ok) | |
| 45 | @unreachable(); | |
| 46 | } |
test/cases3/misc.zig+77| ... | ... | @@ -152,6 +152,83 @@ fn globalVariables() { |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
| 155 | fn memcpyAndMemsetIntrinsics() { | |
| 156 | @setFnTest(this); | |
| 157 | ||
| 158 | var foo : [20]u8 = undefined; | |
| 159 | var bar : [20]u8 = undefined; | |
| 160 | ||
| 161 | @memset(&foo[0], 'A', foo.len); | |
| 162 | @memcpy(&bar[0], &foo[0], bar.len); | |
| 163 | ||
| 164 | if (bar[11] != 'A') @unreachable(); | |
| 165 | } | |
| 166 | ||
| 167 | fn builtinStaticEval() { | |
| 168 | @setFnTest(this); | |
| 169 | ||
| 170 | const x : i32 = @staticEval(1 + 2 + 3); | |
| 171 | assert(x == @staticEval(6)); | |
| 172 | } | |
| 173 | ||
| 174 | fn slicing() { | |
| 175 | @setFnTest(this); | |
| 176 | ||
| 177 | var array : [20]i32 = undefined; | |
| 178 | ||
| 179 | array[5] = 1234; | |
| 180 | ||
| 181 | var slice = array[5...10]; | |
| 182 | ||
| 183 | if (slice.len != 5) @unreachable(); | |
| 184 | ||
| 185 | const ptr = &slice[0]; | |
| 186 | if (ptr[0] != 1234) @unreachable(); | |
| 187 | ||
| 188 | var slice_rest = array[10...]; | |
| 189 | if (slice_rest.len != 10) @unreachable(); | |
| 190 | } | |
| 191 | ||
| 192 | ||
| 193 | fn constantEqualFunctionPointers() { | |
| 194 | @setFnTest(this); | |
| 195 | ||
| 196 | const alias = emptyFn; | |
| 197 | assert(@staticEval(emptyFn == alias)); | |
| 198 | } | |
| 199 | ||
| 200 | fn emptyFn() {} | |
| 201 | ||
| 202 | ||
| 203 | fn hexEscape() { | |
| 204 | @setFnTest(this); | |
| 205 | ||
| 206 | assert(memeql("\x68\x65\x6c\x6c\x6f", "hello")); | |
| 207 | } | |
| 208 | ||
| 209 | fn stringConcatenation() { | |
| 210 | @setFnTest(this); | |
| 211 | ||
| 212 | assert(memeql("OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | |
| 213 | } | |
| 214 | ||
| 215 | fn arrayMultOperator() { | |
| 216 | @setFnTest(this); | |
| 217 | ||
| 218 | assert(memeql("ab" ** 5, "ababababab")); | |
| 219 | } | |
| 220 | ||
| 221 | fn stringEscapes() { | |
| 222 | @setFnTest(this); | |
| 223 | ||
| 224 | assert(memeql("\"", "\x22")); | |
| 225 | assert(memeql("\'", "\x27")); | |
| 226 | assert(memeql("\n", "\x0a")); | |
| 227 | assert(memeql("\r", "\x0d")); | |
| 228 | assert(memeql("\t", "\x09")); | |
| 229 | assert(memeql("\\", "\x5c")); | |
| 230 | assert(memeql("\u1234\u0069", "\xe1\x88\xb4\x69")); | |
| 231 | } | |
| 155 | 232 | |
| 156 | 233 | |
| 157 | 234 | // TODO import from std.str |
test/cases3/null.zig+13| ... | ... | @@ -26,6 +26,19 @@ fn nullableType() { |
| 26 | 26 | assert(num == 13); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | fn assignToIfVarPtr() { | |
| 30 | @setFnTest(this); | |
| 31 | ||
| 32 | var maybe_bool: ?bool = true; | |
| 33 | ||
| 34 | if (const *b ?= maybe_bool) { | |
| 35 | *b = false; | |
| 36 | } | |
| 37 | ||
| 38 | assert(??maybe_bool == false); | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 29 | 42 | // TODO const assert = @import("std").debug.assert; |
| 30 | 43 | fn assert(ok: bool) { |
| 31 | 44 | if (!ok) |
test/cases3/struct.zig+34| ... | ... | @@ -123,6 +123,40 @@ fn callStructField(foo: Foo) -> i32 { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
| 126 | fn storeMemberFunctionInVariable() { | |
| 127 | @setFnTest(this); | |
| 128 | ||
| 129 | const instance = MemberFnTestFoo { .x = 1234, }; | |
| 130 | const memberFn = MemberFnTestFoo.member; | |
| 131 | const result = memberFn(instance); | |
| 132 | assert(result == 1234); | |
| 133 | } | |
| 134 | const MemberFnTestFoo = struct { | |
| 135 | x: i32, | |
| 136 | fn member(foo: MemberFnTestFoo) -> i32 { foo.x } | |
| 137 | }; | |
| 138 | ||
| 139 | ||
| 140 | fn callMemberFunctionDirectly() { | |
| 141 | @setFnTest(this); | |
| 142 | ||
| 143 | const instance = MemberFnTestFoo { .x = 1234, }; | |
| 144 | const result = MemberFnTestFoo.member(instance); | |
| 145 | assert(result == 1234); | |
| 146 | } | |
| 147 | ||
| 148 | fn memberFunctions() { | |
| 149 | @setFnTest(this); | |
| 150 | ||
| 151 | const r = MemberFnRand {.seed = 1234}; | |
| 152 | assert(r.getSeed() == 1234); | |
| 153 | } | |
| 154 | const MemberFnRand = struct { | |
| 155 | seed: u32, | |
| 156 | pub fn getSeed(r: MemberFnRand) -> u32 { | |
| 157 | r.seed | |
| 158 | } | |
| 159 | }; | |
| 126 | 160 | |
| 127 | 161 | |
| 128 | 162 | // TODO const assert = @import("std").debug.assert; |
test/cases3/while.zig+44| ... | ... | @@ -31,6 +31,50 @@ fn staticWhileLoop2() -> i32 { |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | fn continueAndBreak() { | |
| 35 | @setFnTest(this); | |
| 36 | ||
| 37 | runContinueAndBreakTest(); | |
| 38 | assert(continue_and_break_counter == 8); | |
| 39 | } | |
| 40 | var continue_and_break_counter: i32 = 0; | |
| 41 | fn runContinueAndBreakTest() { | |
| 42 | var i : i32 = 0; | |
| 43 | while (true) { | |
| 44 | continue_and_break_counter += 2; | |
| 45 | i += 1; | |
| 46 | if (i < 4) { | |
| 47 | continue; | |
| 48 | } | |
| 49 | break; | |
| 50 | } | |
| 51 | assert(i == 4); | |
| 52 | } | |
| 53 | ||
| 54 | fn returnWithImplicitCastFromWhileLoop() { | |
| 55 | @setFnTest(this); | |
| 56 | ||
| 57 | %%returnWithImplicitCastFromWhileLoopTest(); | |
| 58 | } | |
| 59 | fn returnWithImplicitCastFromWhileLoopTest() -> %void { | |
| 60 | while (true) { | |
| 61 | return; | |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | fn whileWithContinueExpr() { | |
| 66 | @setFnTest(this); | |
| 67 | ||
| 68 | var sum: i32 = 0; | |
| 69 | {var i: i32 = 0; while (i < 10; i += 1) { | |
| 70 | if (i == 5) continue; | |
| 71 | sum += i; | |
| 72 | }} | |
| 73 | assert(sum == 40); | |
| 74 | } | |
| 75 | ||
| 76 | ||
| 77 | ||
| 34 | 78 | // TODO const assert = @import("std").debug.assert; |
| 35 | 79 | fn assert(ok: bool) { |
| 36 | 80 | if (!ok) |
test/self_hosted.zig-277| ... | ... | @@ -107,55 +107,6 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 { |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
| 110 | fn builtinConstEval() { | |
| 111 | @setFnTest(this, true); | |
| 112 | ||
| 113 | const x : i32 = @constEval(1 + 2 + 3); | |
| 114 | assert(x == @constEval(6)); | |
| 115 | } | |
| 116 | ||
| 117 | fn slicing() { | |
| 118 | @setFnTest(this, true); | |
| 119 | ||
| 120 | var array : [20]i32 = undefined; | |
| 121 | ||
| 122 | array[5] = 1234; | |
| 123 | ||
| 124 | var slice = array[5...10]; | |
| 125 | ||
| 126 | if (slice.len != 5) @unreachable(); | |
| 127 | ||
| 128 | const ptr = &slice[0]; | |
| 129 | if (ptr[0] != 1234) @unreachable(); | |
| 130 | ||
| 131 | var slice_rest = array[10...]; | |
| 132 | if (slice_rest.len != 10) @unreachable(); | |
| 133 | } | |
| 134 | ||
| 135 | ||
| 136 | fn memcpyAndMemsetIntrinsics() { | |
| 137 | @setFnTest(this, true); | |
| 138 | ||
| 139 | var foo : [20]u8 = undefined; | |
| 140 | var bar : [20]u8 = undefined; | |
| 141 | ||
| 142 | @memset(&foo[0], 'A', foo.len); | |
| 143 | @memcpy(&bar[0], &foo[0], bar.len); | |
| 144 | ||
| 145 | if (bar[11] != 'A') @unreachable(); | |
| 146 | } | |
| 147 | ||
| 148 | ||
| 149 | fn arrayDotLenConstExpr() { | |
| 150 | @setFnTest(this, true); | |
| 151 | } | |
| 152 | ||
| 153 | struct ArrayDotLenConstExpr { | |
| 154 | y: [@constEval(some_array.len)]u8, | |
| 155 | } | |
| 156 | const some_array = []u8 {0, 1, 2, 3}; | |
| 157 | ||
| 158 | ||
| 159 | 110 | fn multilineString() { |
| 160 | 111 | @setFnTest(this, true); |
| 161 | 112 | |
| ... | ... | @@ -182,16 +133,6 @@ fn multilineCString() { |
| 182 | 133 | |
| 183 | 134 | |
| 184 | 135 | |
| 185 | fn constantEqualFunctionPointers() { | |
| 186 | @setFnTest(this, true); | |
| 187 | ||
| 188 | const alias = emptyFn; | |
| 189 | assert(@constEval(emptyFn == alias)); | |
| 190 | } | |
| 191 | ||
| 192 | fn emptyFn() {} | |
| 193 | ||
| 194 | ||
| 195 | 136 | fn genericMallocFree() { |
| 196 | 137 | @setFnTest(this, true); |
| 197 | 138 | |
| ... | ... | @@ -207,32 +148,6 @@ fn memAlloc(inline T: type, n: usize) -> %[]T { |
| 207 | 148 | fn memFree(inline T: type, mem: []T) { } |
| 208 | 149 | |
| 209 | 150 | |
| 210 | fn callFnWithEmptyString() { | |
| 211 | @setFnTest(this, true); | |
| 212 | ||
| 213 | acceptsString(""); | |
| 214 | } | |
| 215 | ||
| 216 | fn acceptsString(foo: []u8) { } | |
| 217 | ||
| 218 | ||
| 219 | fn hexEscape() { | |
| 220 | @setFnTest(this, true); | |
| 221 | ||
| 222 | assert(str.eql("\x68\x65\x6c\x6c\x6f", "hello")); | |
| 223 | } | |
| 224 | ||
| 225 | ||
| 226 | error AnError; | |
| 227 | error ALongerErrorName; | |
| 228 | fn errorNameString() { | |
| 229 | @setFnTest(this, true); | |
| 230 | ||
| 231 | assert(str.eql(@errorName(error.AnError), "AnError")); | |
| 232 | assert(str.eql(@errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 233 | } | |
| 234 | ||
| 235 | ||
| 236 | 151 | fn castUndefined() { |
| 237 | 152 | @setFnTest(this, true); |
| 238 | 153 | |
| ... | ... | @@ -264,90 +179,6 @@ fn outer() -> i64 { |
| 264 | 179 | } |
| 265 | 180 | |
| 266 | 181 | |
| 267 | fn elseIfExpression() { | |
| 268 | @setFnTest(this, true); | |
| 269 | ||
| 270 | assert(elseIfExpressionF(1) == 1); | |
| 271 | } | |
| 272 | fn elseIfExpressionF(c: u8) -> u8 { | |
| 273 | if (c == 0) { | |
| 274 | 0 | |
| 275 | } else if (c == 1) { | |
| 276 | 1 | |
| 277 | } else { | |
| 278 | 2 | |
| 279 | } | |
| 280 | } | |
| 281 | ||
| 282 | fn errBinaryOperator() { | |
| 283 | @setFnTest(this, true); | |
| 284 | ||
| 285 | const a = errBinaryOperatorG(true) %% 3; | |
| 286 | const b = errBinaryOperatorG(false) %% 3; | |
| 287 | assert(a == 3); | |
| 288 | assert(b == 10); | |
| 289 | } | |
| 290 | error ItBroke; | |
| 291 | fn errBinaryOperatorG(x: bool) -> %isize { | |
| 292 | if (x) { | |
| 293 | error.ItBroke | |
| 294 | } else { | |
| 295 | 10 | |
| 296 | } | |
| 297 | } | |
| 298 | ||
| 299 | fn unwrapSimpleValueFromError() { | |
| 300 | @setFnTest(this, true); | |
| 301 | ||
| 302 | const i = %%unwrapSimpleValueFromErrorDo(); | |
| 303 | assert(i == 13); | |
| 304 | } | |
| 305 | fn unwrapSimpleValueFromErrorDo() -> %isize { 13 } | |
| 306 | ||
| 307 | ||
| 308 | fn storeMemberFunctionInVariable() { | |
| 309 | @setFnTest(this, true); | |
| 310 | ||
| 311 | const instance = MemberFnTestFoo { .x = 1234, }; | |
| 312 | const memberFn = MemberFnTestFoo.member; | |
| 313 | const result = memberFn(instance); | |
| 314 | assert(result == 1234); | |
| 315 | } | |
| 316 | struct MemberFnTestFoo { | |
| 317 | x: i32, | |
| 318 | fn member(foo: MemberFnTestFoo) -> i32 { foo.x } | |
| 319 | } | |
| 320 | ||
| 321 | fn callMemberFunctionDirectly() { | |
| 322 | @setFnTest(this, true); | |
| 323 | ||
| 324 | const instance = MemberFnTestFoo { .x = 1234, }; | |
| 325 | const result = MemberFnTestFoo.member(instance); | |
| 326 | assert(result == 1234); | |
| 327 | } | |
| 328 | ||
| 329 | fn memberFunctions() { | |
| 330 | @setFnTest(this, true); | |
| 331 | ||
| 332 | const r = MemberFnRand {.seed = 1234}; | |
| 333 | assert(r.getSeed() == 1234); | |
| 334 | } | |
| 335 | struct MemberFnRand { | |
| 336 | seed: u32, | |
| 337 | pub fn getSeed(r: MemberFnRand) -> u32 { | |
| 338 | r.seed | |
| 339 | } | |
| 340 | } | |
| 341 | ||
| 342 | fn staticFunctionEvaluation() { | |
| 343 | @setFnTest(this, true); | |
| 344 | ||
| 345 | assert(statically_added_number == 3); | |
| 346 | } | |
| 347 | const statically_added_number = staticAdd(1, 2); | |
| 348 | fn staticAdd(a: i32, b: i32) -> i32 { a + b } | |
| 349 | ||
| 350 | ||
| 351 | 182 | fn staticallyInitalizedList() { |
| 352 | 183 | @setFnTest(this, true); |
| 353 | 184 | |
| ... | ... | @@ -369,17 +200,6 @@ fn makePoint(x: i32, y: i32) -> Point { |
| 369 | 200 | } |
| 370 | 201 | |
| 371 | 202 | |
| 372 | fn staticEvalRecursive() { | |
| 373 | @setFnTest(this, true); | |
| 374 | ||
| 375 | assert(some_data.len == 21); | |
| 376 | } | |
| 377 | var some_data: [usize(fibbonaci(7))]u8 = undefined; | |
| 378 | fn fibbonaci(x: i32) -> i32 { | |
| 379 | if (x <= 1) return 1; | |
| 380 | return fibbonaci(x - 1) + fibbonaci(x - 2); | |
| 381 | } | |
| 382 | ||
| 383 | 203 | fn staticEvalListInit() { |
| 384 | 204 | @setFnTest(this, true); |
| 385 | 205 | |
| ... | ... | @@ -407,27 +227,6 @@ fn getFirstByte(inline T: type, mem: []T) -> u8 { |
| 407 | 227 | getByte((&u8)(&mem[0])) |
| 408 | 228 | } |
| 409 | 229 | |
| 410 | fn continueAndBreak() { | |
| 411 | @setFnTest(this, true); | |
| 412 | ||
| 413 | runContinueAndBreakTest(); | |
| 414 | assert(continue_and_break_counter == 8); | |
| 415 | } | |
| 416 | var continue_and_break_counter: i32 = 0; | |
| 417 | fn runContinueAndBreakTest() { | |
| 418 | var i : i32 = 0; | |
| 419 | while (true) { | |
| 420 | continue_and_break_counter += 2; | |
| 421 | i += 1; | |
| 422 | if (i < 4) { | |
| 423 | continue; | |
| 424 | } | |
| 425 | break; | |
| 426 | } | |
| 427 | assert(i == 4); | |
| 428 | } | |
| 429 | ||
| 430 | ||
| 431 | 230 | fn pointerDereferencing() { |
| 432 | 231 | @setFnTest(this, true); |
| 433 | 232 | |
| ... | ... | @@ -471,12 +270,6 @@ fn intToPtrCast() { |
| 471 | 270 | assert(z == 13); |
| 472 | 271 | } |
| 473 | 272 | |
| 474 | fn stringConcatenation() { | |
| 475 | @setFnTest(this, true); | |
| 476 | ||
| 477 | assert(str.eql("OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | |
| 478 | } | |
| 479 | ||
| 480 | 273 | fn constantStructWithNegation() { |
| 481 | 274 | @setFnTest(this, true); |
| 482 | 275 | |
| ... | ... | @@ -496,17 +289,6 @@ const vertices = []Vertex { |
| 496 | 289 | }; |
| 497 | 290 | |
| 498 | 291 | |
| 499 | fn returnWithImplicitCastFromWhileLoop() { | |
| 500 | @setFnTest(this, true); | |
| 501 | ||
| 502 | %%returnWithImplicitCastFromWhileLoopTest(); | |
| 503 | } | |
| 504 | fn returnWithImplicitCastFromWhileLoopTest() -> %void { | |
| 505 | while (true) { | |
| 506 | return; | |
| 507 | } | |
| 508 | } | |
| 509 | ||
| 510 | 292 | fn returnStructByvalFromFunction() { |
| 511 | 293 | @setFnTest(this, true); |
| 512 | 294 | |
| ... | ... | @@ -641,18 +423,6 @@ fn test3_2(f: Test3Foo) { |
| 641 | 423 | |
| 642 | 424 | |
| 643 | 425 | |
| 644 | fn whileWithContinueExpr() { | |
| 645 | @setFnTest(this, true); | |
| 646 | ||
| 647 | var sum: i32 = 0; | |
| 648 | {var i: i32 = 0; while (i < 10; i += 1) { | |
| 649 | if (i == 5) continue; | |
| 650 | sum += i; | |
| 651 | }} | |
| 652 | assert(sum == 40); | |
| 653 | } | |
| 654 | ||
| 655 | ||
| 656 | 426 | fn forLoopWithPointerElemVar() { |
| 657 | 427 | @setFnTest(this, true); |
| 658 | 428 | |
| ... | ... | @@ -685,9 +455,6 @@ struct EmptyStruct { |
| 685 | 455 | } |
| 686 | 456 | |
| 687 | 457 | |
| 688 | fn @"weird function name"() { | |
| 689 | @setFnTest(this, true); | |
| 690 | } | |
| 691 | 458 | |
| 692 | 459 | |
| 693 | 460 | |
| ... | ... | @@ -771,20 +538,6 @@ fn returnsTen() -> %i32 { |
| 771 | 538 | 10 |
| 772 | 539 | } |
| 773 | 540 | |
| 774 | ||
| 775 | ||
| 776 | fn boolCmp() { | |
| 777 | @setFnTest(this, true); | |
| 778 | ||
| 779 | assert(testBoolCmp(true, false) == false); | |
| 780 | } | |
| 781 | fn testBoolCmp(a: bool, b: bool) -> bool { | |
| 782 | @setFnStaticEval(this, false); | |
| 783 | a == b | |
| 784 | } | |
| 785 | ||
| 786 | ||
| 787 | ||
| 788 | 541 | fn takeAddressOfParameter() { |
| 789 | 542 | @setFnTest(this, true); |
| 790 | 543 | |
| ... | ... | @@ -803,24 +556,6 @@ fn testTakeAddressOfParameterNoeval(f: f32) { |
| 803 | 556 | } |
| 804 | 557 | |
| 805 | 558 | |
| 806 | fn arrayMultOperator() { | |
| 807 | @setFnTest(this, true); | |
| 808 | ||
| 809 | assert(str.eql("ab" ** 5, "ababababab")); | |
| 810 | } | |
| 811 | ||
| 812 | fn stringEscapes() { | |
| 813 | @setFnTest(this, true); | |
| 814 | ||
| 815 | assert(str.eql("\"", "\x22")); | |
| 816 | assert(str.eql("\'", "\x27")); | |
| 817 | assert(str.eql("\n", "\x0a")); | |
| 818 | assert(str.eql("\r", "\x0d")); | |
| 819 | assert(str.eql("\t", "\x09")); | |
| 820 | assert(str.eql("\\", "\x5c")); | |
| 821 | assert(str.eql("\u1234\u0069", "\xe1\x88\xb4\x69")); | |
| 822 | } | |
| 823 | ||
| 824 | 559 | fn ifVarMaybePointer() { |
| 825 | 560 | @setFnTest(this, true); |
| 826 | 561 | |
| ... | ... | @@ -845,18 +580,6 @@ struct Particle { |
| 845 | 580 | d: u64, |
| 846 | 581 | } |
| 847 | 582 | |
| 848 | fn assignToIfVarPtr() { | |
| 849 | @setFnTest(this, true); | |
| 850 | ||
| 851 | var maybe_bool: ?bool = true; | |
| 852 | ||
| 853 | if (const *b ?= maybe_bool) { | |
| 854 | *b = false; | |
| 855 | } | |
| 856 | ||
| 857 | assert(??maybe_bool == false); | |
| 858 | } | |
| 859 | ||
| 860 | 583 | fn unsignedWrapping() { |
| 861 | 584 | @setFnTest(this, true); |
| 862 | 585 |
test/self_hosted3.zig+1| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | const test_array = @import("cases3/array.zig"); |
| 3 | 3 | const test_atomics = @import("cases3/atomics.zig"); |
| 4 | 4 | const test_bool = @import("cases3/bool.zig"); |
| 5 | const test_cast= @import("cases3/cast.zig"); | |
| 5 | 6 | const test_defer = @import("cases3/defer.zig"); |
| 6 | 7 | const test_enum = @import("cases3/enum.zig"); |
| 7 | 8 | const test_error = @import("cases3/error.zig"); |