blob: 9c97ab8e4ea2690409aafb6786cb2d96cf8c6732 [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Test prefix/postfix.</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.indexAnderDoesntReturnPointer = async () =>
{
await checkFail(
`
struct Foo {
int x;
}
int operator&[](thread Foo* foo, uint)
{
return foo->x;
}
`);
}
whlslTests.indexAnderDoesntTakeReference = async () =>
{
await checkFail(
`
struct Foo {
int x;
}
thread int* operator&[](Foo foo, uint)
{
return &foo.x;
}
`);
}
whlslTests.anderDoesntReturnPointer = async () => {
await checkFail(
`
struct Foo {
int x;
}
int operator&.foo(thread Foo* foo)
{
return foo->x;
}
`);
}
whlslTests.anderDoesntTakeReference = async () =>
{
await checkFail(
`
struct Foo {
int x;
}
thread int* operator&.foo(Foo foo)
{
return &foo.x;
}
`);
}
whlslTests.anderWithBadIndex = async () =>
{
await checkFail(`int foo(thread int[] x) { return x[-1]; }`);
await checkFail(`int foo(thread int[] x) { return x[1.f]; }`);
await checkFail(`int foo(thread int[] x, int y) { return x[y]; }`);
await checkFail(`int foo(thread int[] x, float y) { return x[y]; }`);
}
whlslTests.anderWithNothingWrong = async () =>
{
let program = `
struct Foo {
int x;
}
thread int* operator&.foo(thread Foo* foo)
{
return &foo->x;
}
int foo()
{
Foo x;
x.x = 13;
return x.foo;
}
`;
assert_equals(await callIntFunction(program, "foo", []), 13);
}
whlslTests.anderWithWrongNumberOfArguments = async () => {
await checkFail(
`
thread int* operator&.foo()
{
int x;
return &x;
}
`);
await checkFail(
`
struct Foo {
int x;
}
thread int* operator&.foo(thread Foo* foo, int blah)
{
return &foo->x;
}
`);
}
runTests(whlslTests);
</script>
</html>