blob: cc4a5cdcfedb6fa687a56d34a0b0fb88a2a96387 [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Enums.</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.simpleEnumFromInt = async () => {
let program = `
enum Foo {
A,
B,
C
}
int foo(int x) {
return int(Foo(x));
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(42)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(0)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(1)]), 1);
assert_equals(await callIntFunction(program, "foo", [makeInt(2)]), 2);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(2147483647)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(-2147483648)]), 0);
};
whlslTests.simpleEnumFromUint = async () => {
let program = `
enum Foo : uint {
A,
B,
C
}
uint foo(uint x) {
return uint(Foo(x));
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(0)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(1)]), 1);
assert_equals(await callUintFunction(program, "foo", [makeUint(2)]), 2);
assert_equals(await callUintFunction(program, "foo", [makeUint(42)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(1000000)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(4294967295)]), 0);
};
whlslTests.weirdEnumFromInt = async () => {
let program = `
enum Foo : int {
A = 42,
B = -1000,
C = 101010,
D = 0
}
int foo(int x) {
return int(Foo(x));
}
`;
assert_equals(await callIntFunction(program, "foo", [makeInt(0)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(42)]), 42);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1000)]), -1000);
assert_equals(await callIntFunction(program, "foo", [makeInt(101010)]), 101010);
assert_equals(await callIntFunction(program, "foo", [makeInt(-1)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(2147483647)]), 0);
assert_equals(await callIntFunction(program, "foo", [makeInt(-2147483648)]), 0);
};
whlslTests.weirdEnumFromUint = async () => {
let program = `
enum Foo : uint {
A = 42,
C = 101010,
D = 0
}
uint foo(uint x) {
return uint(Foo(x));
}
`;
assert_equals(await callUintFunction(program, "foo", [makeUint(0)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(42)]), 42);
assert_equals(await callUintFunction(program, "foo", [makeUint(101010)]), 101010);
assert_equals(await callUintFunction(program, "foo", [makeUint(4294967295)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(1)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(41)]), 0);
assert_equals(await callUintFunction(program, "foo", [makeUint(101011)]), 0);
};
runTests(whlslTests);
</script>
</html>