| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Test prefix/postfix.</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 = {}; |
| const epsilon = 0.0001; |
| |
| const keywords = [ |
| "struct" |
| , "typedef" |
| , "enum" |
| , "operator" |
| , "if" |
| , "else" |
| , "continue" |
| , "break" |
| , "switch" |
| , "case" |
| , "default" |
| , "fallthrough" |
| , "for" |
| , "while" |
| , "do" |
| , "return" |
| , "null" |
| , "true" |
| , "false" |
| , "constant" |
| , "device" |
| , "threadgroup" |
| , "thread" |
| , "space" |
| , "vertex" |
| , "fragment" |
| , "compute" |
| , "numthreads" |
| , "SV_InstanceID" |
| , "SV_VertexID" |
| , "PSIZE" |
| , "SV_Position" |
| , "SV_IsFrontFace" |
| , "SV_SampleIndex" |
| , "SV_InnerCoverage" |
| , "SV_Target" |
| , "SV_Depth" |
| , "SV_Coverage" |
| , "SV_DispatchThreadID" |
| , "SV_GroupID" |
| , "SV_GroupIndex" |
| , "SV_GroupThreadID" |
| , "attribute" |
| , "register" |
| , "specialized" |
| , "native" |
| , "restricted" |
| , "_" |
| , "auto" |
| , "protocol" |
| , "const" |
| , "static" |
| , "nointerpolation" |
| , "noperspective" |
| , "uniform" |
| , "centroid" |
| , "sample" |
| ]; |
| |
| const suffixes = ["foo", "1337", "_foo"]; |
| |
| whlslTests.lexingKeywordLikeIdentifiers = async () => { |
| for (const keyword of keywords) { |
| for (const suffix of suffixes) { |
| const variableName = keyword + suffix; |
| const program = ` |
| int foo() { |
| int ${variableName} = 42; |
| return ${variableName}; |
| } |
| `; |
| |
| assert_equals(await callIntFunction(program, "foo", []), 42); |
| } |
| } |
| |
| }; |
| |
| whlslTests.keywordsAsIdentifiers = async () => { |
| |
| for (const keyword of keywords) { |
| const variableName = keyword; |
| const program = ` |
| void foo() { |
| int ${variableName} = 42; |
| } |
| `; |
| await checkFail(program); |
| } |
| }; |
| |
| whlslTests.comments = async () => { |
| await checkFail(` |
| /* |
| `); |
| await checkFail(` |
| */ |
| `); |
| |
| await checkFail(` |
| int foo() { |
| return 4/**/2; |
| } |
| `); |
| |
| }; |
| |
| whlslTests.operatorNames = async () => { |
| await checkFail(` |
| struct Foo { |
| } |
| |
| int operator.$(Foo) { |
| return 42; |
| } |
| `); |
| |
| await checkFail(` |
| struct Foo { |
| } |
| |
| int operator.#(Foo) { |
| return 42; |
| } |
| `); |
| |
| await checkFail(` |
| struct Foo { |
| } |
| |
| int operator.@(Foo) { |
| return 42; |
| } |
| `); |
| |
| await checkFail(` |
| struct Foo { |
| } |
| |
| int operator.*%(Foo) { |
| return 42; |
| } |
| `); |
| |
| await checkFail(` |
| int operator&&(int x, int y) { |
| return 42; |
| } |
| `); |
| |
| await checkFail(` |
| bool operator||(int x, int y) { |
| return 42; |
| } |
| `); |
| }; |
| |
| runTests(whlslTests); |
| </script> |
| </html> |