| <!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.simpleEnum = async () => { |
| let program = ` |
| enum Foo { |
| War, |
| Famine, |
| Pestilence, |
| Death |
| } |
| |
| Foo _war() |
| { |
| return Foo.War; |
| } |
| |
| bool war() |
| { |
| return _war() == Foo.War; |
| } |
| |
| Foo _famine() |
| { |
| return Foo.Famine; |
| } |
| |
| bool famine() |
| { |
| return _famine() == Foo.Famine; |
| } |
| |
| Foo _pestilence() |
| { |
| return Foo.Pestilence; |
| } |
| |
| bool pestilence() |
| { |
| return _pestilence() == Foo.Pestilence; |
| } |
| |
| Foo _death() |
| { |
| return Foo.Death; |
| } |
| |
| bool death() |
| { |
| return _death() == Foo.Death; |
| } |
| |
| bool _equals(Foo a, Foo b) |
| { |
| return a == b; |
| } |
| |
| bool _notEquals(Foo a, Foo b) |
| { |
| return a != b; |
| } |
| |
| bool testSimpleEqual() |
| { |
| return _equals(Foo.War, Foo.War); |
| } |
| |
| bool testAnotherEqual() |
| { |
| return _equals(Foo.Pestilence, Foo.Pestilence); |
| } |
| |
| bool testNotEqual() |
| { |
| return _equals(Foo.Famine, Foo.Death); |
| } |
| |
| bool testSimpleNotEqual() |
| { |
| return _notEquals(Foo.War, Foo.War); |
| } |
| |
| bool testAnotherNotEqual() |
| { |
| return _notEquals(Foo.Pestilence, Foo.Pestilence); |
| } |
| |
| bool testNotNotEqual() |
| { |
| return _notEquals(Foo.Famine, Foo.Death); |
| } |
| |
| int _intWar() |
| { |
| return int(_war()); |
| } |
| |
| int intWar() |
| { |
| return _intWar(); |
| } |
| |
| int _intFamine() |
| { |
| return int(_famine()); |
| } |
| |
| int intFamine() |
| { |
| return _intFamine(); |
| } |
| |
| int _intPestilence() |
| { |
| return int(_pestilence()); |
| } |
| |
| int intPestilence() |
| { |
| return _intPestilence(); |
| } |
| |
| int _intDeath() |
| { |
| return int(_death()); |
| } |
| |
| int intDeath() |
| { |
| return _intDeath(); |
| } |
| |
| bool intWarBackwards() |
| { |
| return Foo(_intWar()) == Foo.War; |
| } |
| |
| bool intFamineBackwards() |
| { |
| return Foo(_intFamine()) == Foo.Famine; |
| } |
| |
| bool intPestilenceBackwards() |
| { |
| return Foo(_intPestilence()) == Foo.Pestilence; |
| } |
| |
| bool intDeathBackwards() |
| { |
| return Foo(_intDeath()) == Foo.Death; |
| } |
| `; |
| |
| assert_equals(await callBoolFunction(program, "war", []), true); |
| assert_equals(await callBoolFunction(program, "famine", []), true); |
| assert_equals(await callBoolFunction(program, "pestilence", []), true); |
| assert_equals(await callBoolFunction(program, "death", []), true); |
| |
| assert_equals(await callBoolFunction(program, "testSimpleEqual", []), true); |
| assert_equals(await callBoolFunction(program, "testAnotherEqual", []), true); |
| assert_equals(await callBoolFunction(program, "testNotEqual", []), false); |
| assert_equals(await callBoolFunction(program, "testSimpleNotEqual", []), false); |
| assert_equals(await callBoolFunction(program, "testAnotherNotEqual", []), false); |
| assert_equals(await callBoolFunction(program, "testNotNotEqual", []), true); |
| assert_equals(await callIntFunction(program, "intWar", []), 0); |
| assert_equals(await callIntFunction(program, "intFamine", []), 1); |
| assert_equals(await callIntFunction(program, "intPestilence", []), 2); |
| assert_equals(await callIntFunction(program, "intDeath", []), 3); |
| |
| assert_equals(await callBoolFunction(program, "intWarBackwards", []), true); |
| assert_equals(await callBoolFunction(program, "intFamineBackwards", []), true); |
| assert_equals(await callBoolFunction(program, "intPestilenceBackwards", []), true); |
| assert_equals(await callBoolFunction(program, "intDeathBackwards", []), true); |
| }; |
| |
| whlslTests.enumWithExplicitIntBase = async () => { |
| let program = ` |
| enum Foo : int { |
| War, |
| Famine, |
| Pestilence, |
| Death |
| } |
| |
| Foo _war() |
| { |
| return Foo.War; |
| } |
| |
| bool war() |
| { |
| return _war() == Foo.War; |
| } |
| |
| Foo _famine() |
| { |
| return Foo.Famine; |
| } |
| |
| bool famine() |
| { |
| return _famine() == Foo.Famine; |
| } |
| |
| Foo _pestilence() |
| { |
| return Foo.Pestilence; |
| } |
| |
| bool pestilence() |
| { |
| return _pestilence() == Foo.Pestilence; |
| } |
| |
| Foo _death() |
| { |
| return Foo.Death; |
| } |
| |
| bool death() |
| { |
| return _death() == Foo.Death; |
| } |
| |
| bool _equals(Foo a, Foo b) |
| { |
| return a == b; |
| } |
| |
| bool _notEquals(Foo a, Foo b) |
| { |
| return a != b; |
| } |
| |
| bool testSimpleEqual() |
| { |
| return _equals(Foo.War, Foo.War); |
| } |
| |
| bool testAnotherEqual() |
| { |
| return _equals(Foo.Pestilence, Foo.Pestilence); |
| } |
| |
| bool testNotEqual() |
| { |
| return _equals(Foo.Famine, Foo.Death); |
| } |
| |
| bool testSimpleNotEqual() |
| { |
| return _notEquals(Foo.War, Foo.War); |
| } |
| |
| bool testAnotherNotEqual() |
| { |
| return _notEquals(Foo.Pestilence, Foo.Pestilence); |
| } |
| |
| bool testNotNotEqual() |
| { |
| return _notEquals(Foo.Famine, Foo.Death); |
| } |
| |
| int _intWar() |
| { |
| return int(_war()); |
| } |
| |
| int intWar() |
| { |
| return _intWar(); |
| } |
| |
| int _intFamine() |
| { |
| return int(_famine()); |
| } |
| |
| int intFamine() |
| { |
| return _intFamine(); |
| } |
| |
| int _intPestilence() |
| { |
| return int(_pestilence()); |
| } |
| |
| int intPestilence() |
| { |
| return _intPestilence(); |
| } |
| |
| int _intDeath() |
| { |
| return int(_death()); |
| } |
| |
| int intDeath() |
| { |
| return _intDeath(); |
| } |
| |
| bool intWarBackwards() |
| { |
| return Foo(_intWar()) == Foo.War; |
| } |
| |
| bool intFamineBackwards() |
| { |
| return Foo(_intFamine()) == Foo.Famine; |
| } |
| |
| bool intPestilenceBackwards() |
| { |
| return Foo(_intPestilence()) == Foo.Pestilence; |
| } |
| |
| bool intDeathBackwards() |
| { |
| return Foo(_intDeath()) == Foo.Death; |
| } |
| `; |
| |
| assert_equals(await callBoolFunction(program, "war", []), true); |
| assert_equals(await callBoolFunction(program, "famine", []), true); |
| assert_equals(await callBoolFunction(program, "pestilence", []), true); |
| assert_equals(await callBoolFunction(program, "death", []), true); |
| |
| assert_equals(await callBoolFunction(program, "testSimpleEqual", []), true); |
| assert_equals(await callBoolFunction(program, "testAnotherEqual", []), true); |
| assert_equals(await callBoolFunction(program, "testNotEqual", []), false); |
| assert_equals(await callBoolFunction(program, "testSimpleNotEqual", []), false); |
| assert_equals(await callBoolFunction(program, "testAnotherNotEqual", []), false); |
| assert_equals(await callBoolFunction(program, "testNotNotEqual", []), true); |
| assert_equals(await callIntFunction(program, "intWar", []), 0); |
| assert_equals(await callIntFunction(program, "intFamine", []), 1); |
| assert_equals(await callIntFunction(program, "intPestilence", []), 2); |
| assert_equals(await callIntFunction(program, "intDeath", []), 3); |
| |
| assert_equals(await callBoolFunction(program, "intWarBackwards", []), true); |
| assert_equals(await callBoolFunction(program, "intFamineBackwards", []), true); |
| assert_equals(await callBoolFunction(program, "intPestilenceBackwards", []), true); |
| assert_equals(await callBoolFunction(program, "intDeathBackwards", []), true); |
| }; |
| |
| runTests(whlslTests); |
| </script> |
| </html> |