<!--
Copyright (c) 2021 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL GLSL Conformance Tests - Non Reserved Words</title>
<link rel="stylesheet" href="../../../../webgl_test_files/resources/js-test-style.css"/>
<link rel="stylesheet" href="../../../../webgl_test_files/resources/glsl-feature-tests.css"/>
<script src="../../../../webgl_test_files/js/js-test-pre.js"></script>
<script src="../../../../webgl_test_files/js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vertexShader0" type="text/something-not-javascript">
struct $replaceMe {
  vec4 $replaceMe;
};
struct Foo {
  $replaceMe $replaceMe;
};
attribute vec4 position;
void main()
{
    Foo f;
    f.$replaceMe.$replaceMe = position;
    gl_Position = f.$replaceMe.$replaceMe;
}
</script>
<script id="fragmentShader0" type="text/something-not-javascript">
precision mediump float;
vec4 $replaceMe() {
    return vec4(0,1,0,1);
}
void main()
{
    gl_FragColor = $replaceMe();
}
</script>
<script id="vertexShader1" type="text/something-not-javascript">
attribute vec4 $replaceMe;
void main()
{
    gl_Position = $replaceMe;
}
</script>
<script id="fragmentShader1" type="text/something-not-javascript">
precision mediump float;
vec4 foo(vec4 $replaceMe) {
  return $replaceMe;
}
void main()
{
    gl_FragColor = foo(vec4(1,0,1,1));
}
</script>
<script id="vertexShader2" type="text/something-not-javascript">
varying vec4 $replaceMe;
attribute vec4 position;
void main()
{
    gl_Position = position;
    $replaceMe = position;
}
</script>
<script id="fragmentShader2" type="text/something-not-javascript">
precision mediump float;
varying vec4 $replaceMe;
void main()
{
    gl_FragColor = $replaceMe;
}
</script>
<script id="vertexShader3" type="text/something-not-javascript">
attribute vec4 position;
void main()
{
    gl_Position = position;
}
</script>
<script id="fragmentShader3" type="text/something-not-javascript">
precision mediump float;
uniform vec4 $replaceMe;
void main()
{
    gl_FragColor = $replaceMe;
}
</script>
<script>
"use strict";

var MetalWords = [
  "alignas",
  "alignof",
  "as_type",
  "and",
  "auto",
  "catch",
  "char",
  "const_cast",
  "constant",
  "constexpr",
  "decltype",
  "delete",
  "device",
  "dynamic_cast",
  "explicit",
  "export",
  "fragment",
  "friend",
  "int16_t",
  "int32_t",
  "int64_t",
  "int8_t",
  "kernel",
  "main0",
  "metal",
  "mutable",
  "new",
  "noexcept",
  "nullptr_t",
  "nullptr",
  "operator",
  "override",
  "or",
  "private",
  "protected",
  "ptrdiff_t",
  "ray_data",
  "register",
  "signed",
  "size_t",
  "stage_in",
  "static_assert",
  "static_cast",
  "thread_local",
  "thread",
  "threadgroup_imageblock",
  "threadgroup",
  "throw",
  "try",
  "typeid",
  "typename",
  "uchar",
  "uint16_t",
  "uint32_t",
  "uint64_t",
  "uint8_t",
  "ushort",
  "vertex",
  "virtual",
  "wchar_t",
  "xor",
  "NAN",
  "INFINITY",
  "Pragma",
  "_Pragma",
  "ANGLE_1",
  "INT_MAX",
];


description();

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();

var sources = [];
for (var ii = 0; ii < 4; ++ii) {
  var vsrc = document.getElementById("vertexShader" + ii).text;
  var fsrc = document.getElementById("fragmentShader" + ii).text;
  sources.push({vsrc: vsrc, fsrc: fsrc});
}

var badWordNdx = 0;
var listNdx = 0;

function testNextWord() {
  var list = MetalWords;
  if (listNdx >= list.length) {
      finishTest();
      return;
  }
  testWord(list[listNdx]);
  ++listNdx;
  setTimeout(testNextWord, 0);
}
testNextWord();

function testWord(word) {
  debug("");
  debug("testing: " + word);

  sources.forEach(src => {
    var vs = src.vsrc.replace(/\$replaceMe/g, word);
    var fs = src.fsrc.replace(/\$replaceMe/g, word);

    var success = true;
    var program = wtu.loadProgram(gl, vs, fs, function(msg) {
      debug(msg);
      success = false;
    }, true);
    if (success) {
      testPassed("shader with: '" + word + "' compiled");
    } else {
      testFailed("shader with: '" + word + "' failed to compile");
    }
    if (program) {
      gl.deleteProgram(program);
    }
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no GL errors");
  });
}


var successfullyParsed = true;
</script>
</body>
</html>


