Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 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 sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 27 | |
| 28 | //////////////////////////////////////////////////////////////////////////////// |
Ben Clayton | 57ded6a | 2023-08-22 13:22:22 +0000 | [diff] [blame] | 29 | // File generated by 'tools/src/cmd/gen' using the template: |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 30 | // src/tint/lang/core/attribute_test.cc.tmpl |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 31 | // |
Ben Clayton | 57ded6a | 2023-08-22 13:22:22 +0000 | [diff] [blame] | 32 | // To regenerate run: './tools/run gen' |
| 33 | // |
| 34 | // Do not modify this file directly |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 35 | //////////////////////////////////////////////////////////////////////////////// |
| 36 | |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 37 | #include "src/tint/lang/core/attribute.h" |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 38 | |
| 39 | #include <gtest/gtest.h> |
| 40 | |
| 41 | #include <string> |
| 42 | |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 43 | #include "src/tint/utils/text/string.h" |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 44 | |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 45 | namespace tint::core { |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 46 | namespace { |
| 47 | |
| 48 | namespace parse_print_tests { |
| 49 | |
| 50 | struct Case { |
| 51 | const char* string; |
| 52 | Attribute value; |
| 53 | }; |
| 54 | |
| 55 | inline std::ostream& operator<<(std::ostream& out, Case c) { |
| 56 | return out << "'" << std::string(c.string) << "'"; |
| 57 | } |
| 58 | |
| 59 | static constexpr Case kValidCases[] = { |
Corentin Wallez | 0880e06 | 2024-01-30 16:16:45 +0000 | [diff] [blame] | 60 | {"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 Quyen | 59eb7f3 | 2024-05-23 15:44:53 +0000 | [diff] [blame] | 70 | {"input_attachment_index", Attribute::kInputAttachmentIndex}, |
Corentin Wallez | 0880e06 | 2024-01-30 16:16:45 +0000 | [diff] [blame] | 71 | {"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 sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | static 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 Wallez | dfb4eb0 | 2024-01-30 12:06:13 +0000 | [diff] [blame] | 87 | {"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 Quyen | 59eb7f3 | 2024-05-23 15:44:53 +0000 | [diff] [blame] | 111 | {"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 sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | using AttributeParseTest = testing::TestWithParam<Case>; |
| 138 | |
| 139 | TEST_P(AttributeParseTest, Parse) { |
| 140 | const char* string = GetParam().string; |
| 141 | Attribute expect = GetParam().value; |
| 142 | EXPECT_EQ(expect, ParseAttribute(string)); |
| 143 | } |
| 144 | |
| 145 | INSTANTIATE_TEST_SUITE_P(ValidCases, AttributeParseTest, testing::ValuesIn(kValidCases)); |
| 146 | INSTANTIATE_TEST_SUITE_P(InvalidCases, AttributeParseTest, testing::ValuesIn(kInvalidCases)); |
| 147 | |
| 148 | using AttributePrintTest = testing::TestWithParam<Case>; |
| 149 | |
| 150 | TEST_P(AttributePrintTest, Print) { |
| 151 | Attribute value = GetParam().value; |
| 152 | const char* expect = GetParam().string; |
Ben Clayton | 3c54ba5 | 2023-11-28 21:36:08 +0000 | [diff] [blame] | 153 | EXPECT_EQ(expect, ToString(value)); |
dan sinclair | 077d97a | 2023-02-23 19:08:57 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | INSTANTIATE_TEST_SUITE_P(ValidCases, AttributePrintTest, testing::ValuesIn(kValidCases)); |
| 157 | |
| 158 | } // namespace parse_print_tests |
| 159 | |
| 160 | } // namespace |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 161 | } // namespace tint::core |