| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Test prefix/postfix.</title> |
| <script src="js/test-harness.js"></script> |
| <script src="../js/webgpu-functions.js"></script> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script> |
| const whlslTests = {}; |
| |
| whlslTests.prefixPlusPlus = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| ++x; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 65); |
| } |
| |
| whlslTests.prefixPlusPlusResult = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| return ++x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 65); |
| } |
| |
| whlslTests.postfixPlusPlus = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| x++; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 65); |
| } |
| |
| whlslTests.postfixPlusPlusResult = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| return x++; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 64); |
| } |
| |
| whlslTests.prefixMinusMinus = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| --x; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 63); |
| } |
| |
| whlslTests.prefixMinusMinusResult = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| return --x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 63); |
| } |
| |
| whlslTests.postfixMinusMinus = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| x--; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 63); |
| } |
| |
| whlslTests.postfixMinusMinusResult = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| return x--; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(64)]), 64); |
| } |
| |
| whlslTests.plusEquals = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| x += 42; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 + 42); |
| } |
| |
| whlslTests.plusEqualsResult = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| return x += 42; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 + 42); |
| } |
| |
| whlslTests.minusEquals = async () => { |
| let program = ` |
| int foo(int x) |
| { |
| x -= 42; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 - 42); |
| } |
| |
| whlslTests.minusEqualsResult = async () => { |
| let program = ` |
| int foo(int x) |
| { |
| return x -= 42; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 - 42); |
| } |
| |
| whlslTests.timesEquals = async () => { |
| let program = ` |
| int foo(int x) |
| { |
| x *= 42; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 * 42); |
| } |
| |
| whlslTests.timesEqualsResult = async () => { |
| let program = ` |
| int foo(int x) |
| { |
| return x *= 42; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(385)]), 385 * 42); |
| } |
| |
| runTests(whlslTests); |
| </script> |
| </html> |