summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/parse/comments.spec.ts
blob: af49c496191b2cb07cbb991c44b123f3393538d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
export const description = `Validation tests for comments`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { ShaderValidationTest } from '../shader_validation_test.js';

export const g = makeTestGroup(ShaderValidationTest);

g.test('comments')
  .desc(`Test that valid comments are handled correctly, including nesting.`)
  .fn(t => {
    const code = `
/**
 * Here is my shader.
 *
 * /* I can nest /**/ comments. */
 * // I can nest line comments too.
 **/
@fragment // This is the stage
fn main(/*
no
parameters
*/) -> @location(0) vec4<f32> {
  return/*block_comments_delimit_tokens*/vec4<f32>(.4, .2, .3, .1);
}/* terminated block comments are OK at EOF...*/`;
    t.expectCompileResult(true, code);
  });

g.test('line_comment_eof')
  .desc(`Test that line comments can come at EOF.`)
  .fn(t => {
    const code = `
@fragment
fn main() -> @location(0) vec4<f32> {
  return vec4<f32>(.4, .2, .3, .1);
}
// line comments are OK at EOF...`;
    t.expectCompileResult(true, code);
  });

g.test('line_comment_terminators')
  .desc(`Test that line comments are terminated by any blankspace other than space and \t`)
  .params(u =>
    u
      .combine('blankspace', [
        [' ', 'space'],
        ['\t', 'tab'],
        ['\u000a', 'line_feed'],
        ['\u000b', 'vertical_tab'],
        ['\u000c', 'form_feed'],
        ['\u000d', 'carriage_return'],
        ['\u000d\u000a', 'carriage_return_line_feed'],
        ['\u0085', 'next_line'],
        ['\u2028', 'line_separator'],
        ['\u2029', 'paragraph_separator'],
      ])
      .beginSubcases()
  )
  .fn(t => {
    const code = `// Line comment${t.params.blankspace[0]}const invalid_outside_comment = should_fail`;

    t.expectCompileResult([' ', '\t'].includes(t.params.blankspace[0]), code);
  });

g.test('unterminated_block_comment')
  .desc(`Test that unterminated block comments cause an error`)
  .params(u => u.combine('terminated', [true, false]).beginSubcases())
  .fn(t => {
    const code = `
/**
 * Unterminated block comment.
 *
 ${t.params.terminated ? '*/' : ''}`;

    t.expectCompileResult(t.params.terminated, code);
  });