From 2575bda2e09d02674e6f79350f57e0d1d5e1dc75 Mon Sep 17 00:00:00 2001 From: levovix0 Date: Sun, 5 Jun 2022 17:26:03 +0300 Subject: [PATCH] add complex expressions swizzle test --- tests/test.nim | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/test.nim b/tests/test.nim index 2d2c0bc..4d74b3c 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -350,6 +350,75 @@ block: b.g = 123 doAssert b == dvec4(4.0, 123.0, 2.0, 1.0) +block: + # Test swizzle with complex expressions + var a = [ + vec2(1, 2), + vec2(3, 4), + vec2(5, 6), + vec2(7, 8), + ] + var i = 0 + proc f(): var Vec2 = + # function with side effects + result = a[i] + inc i + + doAssert f().yx == vec2(2, 1) + doAssert f().gr == vec2(4, 3) + doAssert f().ts == vec2(6, 5) + doAssert f().yx == vec2(8, 7) + doAssert i == 4 + + i = 0 + f().yx = f() + doAssert a[0] == vec2(4, 3) + doAssert a[1] == vec2(3, 4) + doAssert i == 2 + + var b = [ + vec3(1, 2, 3), + vec3(4, 5, 6), + vec3(7, 8, 9), + ] + i = 0 + proc g(): var Vec3 = + # function with side effects + result = b[i] + inc i + + doAssert g().yxz == vec3(2, 1, 3) + doAssert g().bgr == vec3(6, 5, 4) + doAssert g().tps == vec3(8, 9, 7) + doAssert i == 3 + + i = 0 + g().yxz = g() + doAssert b[0] == vec3(5, 4, 6) + doAssert b[1] == vec3(4, 5, 6) + doAssert i == 2 + + var c = [ + vec4(1, 2, 3, 4), + vec4(5, 6, 7, 8), + ] + i = 0 + proc h(): var Vec4 = + # function with side effects + result = c[i] + inc i + + doAssert h().yxzw == vec4(2, 1, 3, 4) + doAssert h().tqsp == vec4(6, 8, 5, 7) + doAssert i == 2 + + i = 0 + h().wzyx = h() + doAssert c[0] == vec4(8, 7, 6, 5) + doAssert c[1] == vec4(5, 6, 7, 8) + doAssert i == 2 + + block: # Test basic mat constructors. block: