blob: 8600d6a7c81cd44d824947112f6075479ead649f [file] [log] [blame]
<!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.setterWithMatchedType = async () =>
{
const program = `
int operator.foo(int)
{
return 5;
}
int operator.foo=(int, int)
{
return 543;
}
int foo() {
int x;
x.foo = 42;
return x;
}
int bar() {
int x;
return x.foo;
}
`;
assert_equals(await callIntFunction(program, "foo", []), 543);
//assert_equals(await callIntFunction(program, "bar", []), 5);
}
whlslTests.setterWithNoGetterOverload = async () =>
{
await checkFail(
`
struct Foo { }
struct Bar { }
int operator.foo(Foo)
{
return 534;
}
Bar operator.foo=(Bar, int)
{
return Bar();
}
`);
}
whlslTests.setterWithNoGetterOverloadFixed = async () =>
{
const program =`
struct Bar { }
int operator.foo(Bar)
{
return 534;
}
Bar operator.foo=(Bar, int)
{
return Bar();
}
int foo() {
Bar bar;
return bar.foo;
}
int bar() {
Bar bar;
bar.foo = 52;
return bar.foo;
}
`;
assert_equals(await callIntFunction(program, "foo", []), 534);
assert_equals(await callIntFunction(program, "bar", []), 534);
}
whlslTests.recursiveSetters = async () =>
{
let program = `
struct Foo {
int x;
int y;
}
struct Bar {
int a;
int b;
}
int operator.c(Bar bar) { return bar.a; }
Bar operator.bar(Foo foo) { Bar b; b.a = foo.x; b.b = foo.y; return b; }
Bar operator.c=(Bar bar, int newval) { bar.a = newval; return bar; }
Foo operator.bar=(Foo foo, Bar newval) { foo.x = newval.a; foo.y = newval.b; return foo; }
int f() {
Foo foo;
foo.x = foo.y = 3;
foo.bar.c = 8;
return foo.x*10 + foo.y;
}
`;
assert_equals(await callIntFunction(program, "f", []), 83);
}
whlslTests.loneSetter = async () =>
{
await checkFail(
`
int operator.foo=(int, int)
{
return 543;
}
`);
}
whlslTests.loneSetterPointer = async () =>
{
await checkFail(
`
thread int* operator.foo=(thread int* ptr, int)
{
return ptr;
}
`);
}
runTests(whlslTests);
</script>
</html>