• 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/ast/struct_block_decoration.h"
16 #include "src/reader/wgsl/parser_impl_test_helper.h"
17 
18 namespace tint {
19 namespace reader {
20 namespace wgsl {
21 namespace {
22 
23 struct DecorationData {
24   const char* input;
25   bool is_block;
26 };
operator <<(std::ostream & out,DecorationData data)27 inline std::ostream& operator<<(std::ostream& out, DecorationData data) {
28   out << std::string(data.input);
29   return out;
30 }
31 
32 class DecorationTest : public ParserImplTestWithParam<DecorationData> {};
33 
TEST_P(DecorationTest,Parses)34 TEST_P(DecorationTest, Parses) {
35   auto params = GetParam();
36   auto p = parser(params.input);
37 
38   auto deco = p->decoration();
39   ASSERT_FALSE(p->has_error());
40   EXPECT_TRUE(deco.matched);
41   EXPECT_FALSE(deco.errored);
42   ASSERT_NE(deco.value, nullptr);
43   auto* struct_deco = deco.value->As<ast::Decoration>();
44   ASSERT_NE(struct_deco, nullptr);
45   EXPECT_EQ(struct_deco->Is<ast::StructBlockDecoration>(), params.is_block);
46 }
47 INSTANTIATE_TEST_SUITE_P(ParserImplTest,
48                          DecorationTest,
49                          testing::Values(DecorationData{"block", true}));
50 
TEST_F(ParserImplTest,Decoration_NoMatch)51 TEST_F(ParserImplTest, Decoration_NoMatch) {
52   auto p = parser("not-a-stage");
53   auto deco = p->decoration();
54   EXPECT_FALSE(deco.matched);
55   EXPECT_FALSE(deco.errored);
56   ASSERT_EQ(deco.value, nullptr);
57 }
58 
59 }  // namespace
60 }  // namespace wgsl
61 }  // namespace reader
62 }  // namespace tint
63