dawn-cmake/src/reader/wgsl/parser_impl_test_helper.h
Ben Clayton 2f4096b0d7 Move the ast node ownership from Context to Module
Fixes: tint:335
Change-Id: I128e229daa56d43e7227ecab72269be33b3ee012
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33240
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-18 20:58:20 +00:00

87 lines
2.5 KiB
C++

// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_
#define SRC_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "gtest/gtest.h"
#include "src/context.h"
#include "src/reader/wgsl/parser_impl.h"
namespace tint {
namespace reader {
namespace wgsl {
/// WGSL Parser test class
class ParserImplTest : public testing::Test {
public:
/// Constructor
ParserImplTest();
~ParserImplTest() override;
/// Retrieves the parser from the helper
/// @param str the string to parse
/// @returns the parser implementation
std::unique_ptr<ParserImpl> parser(const std::string& str) {
auto file = std::make_unique<Source::File>("test.wgsl", str);
auto impl = std::make_unique<ParserImpl>(&ctx_, file.get());
files_.emplace_back(std::move(file));
return impl;
}
/// @returns the type manager
TypeManager* tm() { return &(ctx_.type_mgr()); }
private:
std::vector<std::unique_ptr<Source::File>> files_;
Context ctx_;
};
/// WGSL Parser test class with param
template <typename T>
class ParserImplTestWithParam : public testing::TestWithParam<T> {
public:
/// Constructor
ParserImplTestWithParam() = default;
~ParserImplTestWithParam() override = default;
/// Retrieves the parser from the helper
/// @param str the string to parse
/// @returns the parser implementation
std::unique_ptr<ParserImpl> parser(const std::string& str) {
auto file = std::make_unique<Source::File>("test.wgsl", str);
auto impl = std::make_unique<ParserImpl>(&ctx_, file.get());
files_.emplace_back(std::move(file));
return impl;
}
/// @returns the type manager
TypeManager* tm() { return &(ctx_.type_mgr()); }
private:
std::vector<std::unique_ptr<Source::File>> files_;
Context ctx_;
};
} // namespace wgsl
} // namespace reader
} // namespace tint
#endif // SRC_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_