blob: c8eb487f1815a26a77449165326e0ad0225ad30a [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2023 The Dawn & Tint Authors
dan sinclair077d97a2023-02-23 19:08:57 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
dan sinclair077d97a2023-02-23 19:08:57 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
dan sinclair077d97a2023-02-23 19:08:57 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dan sinclair077d97a2023-02-23 19:08:57 +000027
28////////////////////////////////////////////////////////////////////////////////
Ben Clayton57ded6a2023-08-22 13:22:22 +000029// File generated by 'tools/src/cmd/gen' using the template:
Ben Claytoncd52f382023-08-07 13:11:08 +000030// src/tint/lang/core/attribute_test.cc.tmpl
dan sinclair077d97a2023-02-23 19:08:57 +000031//
Ben Clayton57ded6a2023-08-22 13:22:22 +000032// To regenerate run: './tools/run gen'
33//
34// Do not modify this file directly
dan sinclair077d97a2023-02-23 19:08:57 +000035////////////////////////////////////////////////////////////////////////////////
36
Ben Claytoncd52f382023-08-07 13:11:08 +000037#include "src/tint/lang/core/attribute.h"
dan sinclair077d97a2023-02-23 19:08:57 +000038
39#include <gtest/gtest.h>
40
41#include <string>
42
dan sinclair22b4dd22023-07-21 00:40:07 +000043#include "src/tint/utils/text/string.h"
dan sinclair077d97a2023-02-23 19:08:57 +000044
Ben Claytoncd52f382023-08-07 13:11:08 +000045namespace tint::core {
dan sinclair077d97a2023-02-23 19:08:57 +000046namespace {
47
48namespace parse_print_tests {
49
50struct Case {
51 const char* string;
52 Attribute value;
53};
54
55inline std::ostream& operator<<(std::ostream& out, Case c) {
56 return out << "'" << std::string(c.string) << "'";
57}
58
59static constexpr Case kValidCases[] = {
Corentin Wallez0880e062024-01-30 16:16:45 +000060 {"align", Attribute::kAlign},
61 {"binding", Attribute::kBinding},
62 {"blend_src", Attribute::kBlendSrc},
63 {"builtin", Attribute::kBuiltin},
64 {"color", Attribute::kColor},
65 {"compute", Attribute::kCompute},
66 {"diagnostic", Attribute::kDiagnostic},
67 {"fragment", Attribute::kFragment},
68 {"group", Attribute::kGroup},
69 {"id", Attribute::kId},
Le Hoang Quyen59eb7f32024-05-23 15:44:53 +000070 {"input_attachment_index", Attribute::kInputAttachmentIndex},
Corentin Wallez0880e062024-01-30 16:16:45 +000071 {"interpolate", Attribute::kInterpolate},
72 {"invariant", Attribute::kInvariant},
73 {"location", Attribute::kLocation},
74 {"must_use", Attribute::kMustUse},
75 {"size", Attribute::kSize},
76 {"vertex", Attribute::kVertex},
77 {"workgroup_size", Attribute::kWorkgroupSize},
dan sinclair077d97a2023-02-23 19:08:57 +000078};
79
80static constexpr Case kInvalidCases[] = {
81 {"alccn", Attribute::kUndefined},
82 {"3g", Attribute::kUndefined},
83 {"aVign", Attribute::kUndefined},
84 {"bind1ng", Attribute::kUndefined},
85 {"bqnJing", Attribute::kUndefined},
86 {"bindin7ll", Attribute::kUndefined},
Corentin Wallezdfb4eb02024-01-30 12:06:13 +000087 {"blen_sppqHH", Attribute::kUndefined},
88 {"blen_r", Attribute::kUndefined},
89 {"bbndGsrc", Attribute::kUndefined},
90 {"builiivn", Attribute::kUndefined},
91 {"8WWiltin", Attribute::kUndefined},
92 {"bxxltin", Attribute::kUndefined},
93 {"cggor", Attribute::kUndefined},
94 {"VoX", Attribute::kUndefined},
95 {"colo3", Attribute::kUndefined},
96 {"Eompute", Attribute::kUndefined},
97 {"cPTTpute", Attribute::kUndefined},
98 {"compudxx", Attribute::kUndefined},
99 {"diagno44tic", Attribute::kUndefined},
100 {"diaVVSnostic", Attribute::kUndefined},
101 {"2iRRnostic", Attribute::kUndefined},
102 {"rFg9ent", Attribute::kUndefined},
103 {"frament", Attribute::kUndefined},
104 {"ROOrHgeVt", Attribute::kUndefined},
105 {"royp", Attribute::kUndefined},
106 {"n77rrloGp", Attribute::kUndefined},
107 {"grou40", Attribute::kUndefined},
108 {"HH", Attribute::kUndefined},
109 {"p", Attribute::kUndefined},
110 {"1ii", Attribute::kUndefined},
Le Hoang Quyen59eb7f32024-05-23 15:44:53 +0000111 {"input_attachment_iXXdex", Attribute::kUndefined},
112 {"input_attnnIIhme99t55index", Attribute::kUndefined},
113 {"inputYarrHHacaamentSSindex", Attribute::kUndefined},
114 {"nHkkolate", Attribute::kUndefined},
115 {"jRRterogte", Attribute::kUndefined},
116 {"iterpolbe", Attribute::kUndefined},
117 {"invariajt", Attribute::kUndefined},
118 {"ivariant", Attribute::kUndefined},
119 {"ivariqt", Attribute::kUndefined},
120 {"locaioNN", Attribute::kUndefined},
121 {"ocvvion", Attribute::kUndefined},
122 {"loatQQon", Attribute::kUndefined},
123 {"musf_re", Attribute::kUndefined},
124 {"mujt_use", Attribute::kUndefined},
125 {"muswNN82e", Attribute::kUndefined},
126 {"sze", Attribute::kUndefined},
127 {"sirre", Attribute::kUndefined},
128 {"sGze", Attribute::kUndefined},
129 {"verFFex", Attribute::kUndefined},
130 {"vre", Attribute::kUndefined},
131 {"vrrrte", Attribute::kUndefined},
132 {"orkgroup_sze", Attribute::kUndefined},
133 {"DXkgroJJp_size", Attribute::kUndefined},
134 {"wo8kroup_sz", Attribute::kUndefined},
dan sinclair077d97a2023-02-23 19:08:57 +0000135};
136
137using AttributeParseTest = testing::TestWithParam<Case>;
138
139TEST_P(AttributeParseTest, Parse) {
140 const char* string = GetParam().string;
141 Attribute expect = GetParam().value;
142 EXPECT_EQ(expect, ParseAttribute(string));
143}
144
145INSTANTIATE_TEST_SUITE_P(ValidCases, AttributeParseTest, testing::ValuesIn(kValidCases));
146INSTANTIATE_TEST_SUITE_P(InvalidCases, AttributeParseTest, testing::ValuesIn(kInvalidCases));
147
148using AttributePrintTest = testing::TestWithParam<Case>;
149
150TEST_P(AttributePrintTest, Print) {
151 Attribute value = GetParam().value;
152 const char* expect = GetParam().string;
Ben Clayton3c54ba52023-11-28 21:36:08 +0000153 EXPECT_EQ(expect, ToString(value));
dan sinclair077d97a2023-02-23 19:08:57 +0000154}
155
156INSTANTIATE_TEST_SUITE_P(ValidCases, AttributePrintTest, testing::ValuesIn(kValidCases));
157
158} // namespace parse_print_tests
159
160} // namespace
Ben Claytoncd52f382023-08-07 13:11:08 +0000161} // namespace tint::core