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 #ifndef SRC_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_ 16 #define SRC_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_ 17 18 #include <memory> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "gtest/gtest.h" 24 #include "src/reader/wgsl/parser_impl.h" 25 26 namespace tint { 27 namespace reader { 28 namespace wgsl { 29 30 /// WGSL Parser test class 31 class ParserImplTest : public testing::Test, public ProgramBuilder { 32 public: 33 /// Constructor 34 ParserImplTest(); 35 ~ParserImplTest() override; 36 37 /// Retrieves the parser from the helper 38 /// @param str the string to parse 39 /// @returns the parser implementation parser(const std::string & str)40 std::unique_ptr<ParserImpl> parser(const std::string& str) { 41 auto file = std::make_unique<Source::File>("test.wgsl", str); 42 auto impl = std::make_unique<ParserImpl>(file.get()); 43 files_.emplace_back(std::move(file)); 44 return impl; 45 } 46 47 private: 48 std::vector<std::unique_ptr<Source::File>> files_; 49 }; 50 51 /// WGSL Parser test class with param 52 template <typename T> 53 class ParserImplTestWithParam : public testing::TestWithParam<T>, 54 public ProgramBuilder { 55 public: 56 /// Constructor 57 ParserImplTestWithParam() = default; 58 ~ParserImplTestWithParam() override = default; 59 60 /// Retrieves the parser from the helper 61 /// @param str the string to parse 62 /// @returns the parser implementation parser(const std::string & str)63 std::unique_ptr<ParserImpl> parser(const std::string& str) { 64 auto file = std::make_unique<Source::File>("test.wgsl", str); 65 auto impl = std::make_unique<ParserImpl>(file.get()); 66 files_.emplace_back(std::move(file)); 67 return impl; 68 } 69 70 private: 71 std::vector<std::unique_ptr<Source::File>> files_; 72 }; 73 74 } // namespace wgsl 75 } // namespace reader 76 } // namespace tint 77 78 #endif // SRC_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_ 79