• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/reader/wgsl/parser_impl_test_helper.h"
16 
17 namespace tint {
18 namespace reader {
19 namespace wgsl {
20 namespace {
21 
22 struct StorageClassData {
23   const char* input;
24   ast::StorageClass result;
25 };
operator <<(std::ostream & out,StorageClassData data)26 inline std::ostream& operator<<(std::ostream& out, StorageClassData data) {
27   out << std::string(data.input);
28   return out;
29 }
30 
31 class StorageClassTest : public ParserImplTestWithParam<StorageClassData> {};
32 
TEST_P(StorageClassTest,Parses)33 TEST_P(StorageClassTest, Parses) {
34   auto params = GetParam();
35   auto p = parser(params.input);
36 
37   auto sc = p->expect_storage_class("test");
38   EXPECT_FALSE(sc.errored);
39   EXPECT_FALSE(p->has_error());
40   EXPECT_EQ(sc.value, params.result);
41 
42   auto t = p->next();
43   EXPECT_TRUE(t.IsEof());
44 }
45 INSTANTIATE_TEST_SUITE_P(
46     ParserImplTest,
47     StorageClassTest,
48     testing::Values(
49         StorageClassData{"uniform", ast::StorageClass::kUniform},
50         StorageClassData{"workgroup", ast::StorageClass::kWorkgroup},
51         StorageClassData{"storage", ast::StorageClass::kStorage},
52         StorageClassData{"storage_buffer", ast::StorageClass::kStorage},
53         StorageClassData{"image", ast::StorageClass::kImage},
54         StorageClassData{"private", ast::StorageClass::kPrivate},
55         StorageClassData{"function", ast::StorageClass::kFunction}));
56 
TEST_F(ParserImplTest,StorageClass_NoMatch)57 TEST_F(ParserImplTest, StorageClass_NoMatch) {
58   auto p = parser("not-a-storage-class");
59   auto sc = p->expect_storage_class("test");
60   EXPECT_EQ(sc.errored, true);
61   EXPECT_TRUE(p->has_error());
62   EXPECT_EQ(p->error(), "1:1: invalid storage class for test");
63 
64   auto t = p->next();
65   EXPECT_TRUE(t.IsIdentifier());
66   EXPECT_EQ(t.to_str(), "not");
67 }
68 
69 }  // namespace
70 }  // namespace wgsl
71 }  // namespace reader
72 }  // namespace tint
73