| <!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.indexAnderWithNothingWrong = async () => |
| { |
| let program = ` |
| struct Foo { |
| int x; |
| } |
| thread int* operator&[](thread Foo* foo, uint) |
| { |
| return &foo->x; |
| } |
| int foo() |
| { |
| Foo x; |
| x.x = 13; |
| return x[666]; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", []), 13); |
| } |
| |
| whlslTests.indexAnderWithWrongNumberOfArguments = async () => |
| { |
| await checkFail( |
| ` |
| thread int* operator&[]() |
| { |
| int x; |
| return &x; |
| } |
| `); |
| |
| await checkFail( |
| ` |
| struct Foo { |
| int x; |
| } |
| thread int* operator&[](thread Foo* foo) |
| { |
| return &foo->x; |
| } |
| `); |
| |
| await checkFail( |
| ` |
| struct Foo { |
| int x; |
| } |
| thread int* operator&[](thread Foo* foo, uint, uint) |
| { |
| return &foo->x; |
| } |
| `); |
| } |
| |
| runTests(whlslTests); |
| </script> |
| </html> |