| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Test structs.</title> |
| <script src="js/whlsl-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.indexSetterWithNoGetterOverload = async () => |
| { |
| await checkFail( |
| ` |
| struct Foo { } |
| struct Bar { } |
| int operator[](Foo, uint) |
| { |
| return 534; |
| } |
| Bar operator[]=(Bar, uint, int) |
| { |
| return Bar(); |
| } |
| `); |
| |
| }; |
| |
| whlslTests.indexSetterWithNoGetterOverloadFixed = async () => |
| { |
| const program = ` |
| struct Bar { } |
| int operator[](Bar, uint) |
| { |
| return 534; |
| } |
| Bar operator[]=(Bar, uint, int) |
| { |
| return Bar(); |
| } |
| int foo() { return Bar()[0]; } |
| int bar() { |
| Bar b; |
| b[0] = 400; |
| return b[0]; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", []), 534); |
| assert_equals(await callIntFunction(program, "bar", []), 534); |
| }; |
| |
| whlslTests.notLoneIndexSetter = async () => |
| { |
| const program = ` |
| int operator[](int, uint) |
| { |
| return 65; |
| } |
| int operator[]=(int, uint, int) |
| { |
| return 543; |
| } |
| int foo() { |
| int x; |
| return x[0]; |
| } |
| int bar() { |
| int x; |
| x[0] = 42; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", []), 65); |
| assert_equals(await callIntFunction(program, "bar", []), 543); |
| }; |
| |
| whlslTests.loneIndexSetter = async () => |
| { |
| await checkFail( |
| ` |
| int operator[]=(int, uint, int) |
| { |
| return 543; |
| } |
| `); |
| |
| }; |
| |
| whlslTests.loneIndexSetterPointer = async () => |
| { |
| await checkFail( |
| ` |
| thread int* operator[]=(thread int* ptr, uint, int) |
| { |
| return ptr; |
| } |
| `); |
| |
| }; |
| |
| runTests(whlslTests); |
| </script> |
| </html> |