Add ParserImplTestWithParam to reduce boilerplate
There were a number of places where we were declaring classes derived from `testing::TestWithParam<T>` and then adding the same `parser()` helper logic. Move this common logic down to a new `ParserImplTestWithParam<T>` class, and derive from that instead. Removes a whole bunch of copy-pasta. Change-Id: I8f308b77817fd6327c045d2fdee4462b7f32897a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31401 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: David Neto <dneto@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
bfc2fceb84
commit
5d40a5621b
|
@ -31,24 +31,7 @@ inline std::ostream& operator<<(std::ostream& out, PipelineStageData data) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PipelineStageTest : public testing::TestWithParam<PipelineStageData> {
|
class PipelineStageTest : public ParserImplTestWithParam<PipelineStageData> {};
|
||||||
public:
|
|
||||||
PipelineStageTest() = default;
|
|
||||||
~PipelineStageTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(PipelineStageTest, Parses) {
|
TEST_P(PipelineStageTest, Parses) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
|
@ -31,24 +31,7 @@ inline std::ostream& operator<<(std::ostream& out, StorageClassData data) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StorageClassTest : public testing::TestWithParam<StorageClassData> {
|
class StorageClassTest : public ParserImplTestWithParam<StorageClassData> {};
|
||||||
public:
|
|
||||||
StorageClassTest() = default;
|
|
||||||
~StorageClassTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(StorageClassTest, Parses) {
|
TEST_P(StorageClassTest, Parses) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
|
@ -32,24 +32,7 @@ inline std::ostream& operator<<(std::ostream& out, StructDecorationData data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class StructDecorationTest
|
class StructDecorationTest
|
||||||
: public testing::TestWithParam<StructDecorationData> {
|
: public ParserImplTestWithParam<StructDecorationData> {};
|
||||||
public:
|
|
||||||
StructDecorationTest() = default;
|
|
||||||
~StructDecorationTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(StructDecorationTest, Parses) {
|
TEST_P(StructDecorationTest, Parses) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
|
@ -55,6 +55,36 @@ class ParserImplTest : public testing::Test {
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// WGSL Parser test class with param
|
||||||
|
template <typename T>
|
||||||
|
class ParserImplTestWithParam : public testing::TestWithParam<T> {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
ParserImplTestWithParam() = default;
|
||||||
|
~ParserImplTestWithParam() override = default;
|
||||||
|
|
||||||
|
/// Sets up the test helper
|
||||||
|
void SetUp() override { ctx_.Reset(); }
|
||||||
|
|
||||||
|
/// Tears down the test helper
|
||||||
|
void TearDown() override { impl_ = nullptr; }
|
||||||
|
|
||||||
|
/// Retrieves the parser from the helper
|
||||||
|
/// @param str the string to parse
|
||||||
|
/// @returns the parser implementation
|
||||||
|
ParserImpl* parser(const std::string& str) {
|
||||||
|
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
||||||
|
return impl_.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @returns the type manager
|
||||||
|
TypeManager* tm() { return &(ctx_.type_mgr()); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<ParserImpl> impl_;
|
||||||
|
Context ctx_;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
} // namespace reader
|
} // namespace reader
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -123,24 +123,8 @@ inline std::ostream& operator<<(std::ostream& out, VecData data) {
|
||||||
out << std::string(data.input);
|
out << std::string(data.input);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
class VecTest : public testing::TestWithParam<VecData> {
|
|
||||||
public:
|
|
||||||
VecTest() = default;
|
|
||||||
~VecTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
class VecTest : public ParserImplTestWithParam<VecData> {};
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(VecTest, Parse) {
|
TEST_P(VecTest, Parse) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -157,24 +141,7 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
VecData{"vec3<f32>", 3},
|
VecData{"vec3<f32>", 3},
|
||||||
VecData{"vec4<f32>", 4}));
|
VecData{"vec4<f32>", 4}));
|
||||||
|
|
||||||
class VecMissingGreaterThanTest : public testing::TestWithParam<VecData> {
|
class VecMissingGreaterThanTest : public ParserImplTestWithParam<VecData> {};
|
||||||
public:
|
|
||||||
VecMissingGreaterThanTest() = default;
|
|
||||||
~VecMissingGreaterThanTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(VecMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(VecMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -190,24 +157,7 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
VecData{"vec3<f32", 3},
|
VecData{"vec3<f32", 3},
|
||||||
VecData{"vec4<f32", 4}));
|
VecData{"vec4<f32", 4}));
|
||||||
|
|
||||||
class VecMissingLessThanTest : public testing::TestWithParam<VecData> {
|
class VecMissingLessThanTest : public ParserImplTestWithParam<VecData> {};
|
||||||
public:
|
|
||||||
VecMissingLessThanTest() = default;
|
|
||||||
~VecMissingLessThanTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(VecMissingLessThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(VecMissingLessThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -223,24 +173,7 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
VecData{"vec3", 3},
|
VecData{"vec3", 3},
|
||||||
VecData{"vec4", 4}));
|
VecData{"vec4", 4}));
|
||||||
|
|
||||||
class VecBadType : public testing::TestWithParam<VecData> {
|
class VecBadType : public ParserImplTestWithParam<VecData> {};
|
||||||
public:
|
|
||||||
VecBadType() = default;
|
|
||||||
~VecBadType() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(VecBadType, Handles_Unknown_Type) {
|
TEST_P(VecBadType, Handles_Unknown_Type) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -256,24 +189,7 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
VecData{"vec3<unknown", 3},
|
VecData{"vec3<unknown", 3},
|
||||||
VecData{"vec4<unknown", 4}));
|
VecData{"vec4<unknown", 4}));
|
||||||
|
|
||||||
class VecMissingType : public testing::TestWithParam<VecData> {
|
class VecMissingType : public ParserImplTestWithParam<VecData> {};
|
||||||
public:
|
|
||||||
VecMissingType() = default;
|
|
||||||
~VecMissingType() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(VecMissingType, Handles_Missing_Type) {
|
TEST_P(VecMissingType, Handles_Missing_Type) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -604,24 +520,8 @@ inline std::ostream& operator<<(std::ostream& out, MatrixData data) {
|
||||||
out << std::string(data.input);
|
out << std::string(data.input);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
class MatrixTest : public testing::TestWithParam<MatrixData> {
|
|
||||||
public:
|
|
||||||
MatrixTest() = default;
|
|
||||||
~MatrixTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
class MatrixTest : public ParserImplTestWithParam<MatrixData> {};
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(MatrixTest, Parse) {
|
TEST_P(MatrixTest, Parse) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
@ -646,24 +546,9 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
MatrixData{"mat4x3<f32>", 4, 3},
|
MatrixData{"mat4x3<f32>", 4, 3},
|
||||||
MatrixData{"mat4x4<f32>", 4, 4}));
|
MatrixData{"mat4x4<f32>", 4, 4}));
|
||||||
|
|
||||||
class MatrixMissingGreaterThanTest : public testing::TestWithParam<MatrixData> {
|
class MatrixMissingGreaterThanTest
|
||||||
public:
|
: public ParserImplTestWithParam<MatrixData> {};
|
||||||
MatrixMissingGreaterThanTest() = default;
|
|
||||||
~MatrixMissingGreaterThanTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
TEST_P(MatrixMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(MatrixMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
auto* p = parser(params.input);
|
auto* p = parser(params.input);
|
||||||
|
@ -684,24 +569,8 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
MatrixData{"mat4x3<f32", 4, 3},
|
MatrixData{"mat4x3<f32", 4, 3},
|
||||||
MatrixData{"mat4x4<f32", 4, 4}));
|
MatrixData{"mat4x4<f32", 4, 4}));
|
||||||
|
|
||||||
class MatrixMissingLessThanTest : public testing::TestWithParam<MatrixData> {
|
class MatrixMissingLessThanTest : public ParserImplTestWithParam<MatrixData> {};
|
||||||
public:
|
|
||||||
MatrixMissingLessThanTest() = default;
|
|
||||||
~MatrixMissingLessThanTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
TEST_P(MatrixMissingLessThanTest, Handles_Missing_GreaterThan) {
|
TEST_P(MatrixMissingLessThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
auto* p = parser(params.input);
|
auto* p = parser(params.input);
|
||||||
|
@ -722,24 +591,8 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
MatrixData{"mat4x3 f32>", 4, 3},
|
MatrixData{"mat4x3 f32>", 4, 3},
|
||||||
MatrixData{"mat4x4 f32>", 4, 4}));
|
MatrixData{"mat4x4 f32>", 4, 4}));
|
||||||
|
|
||||||
class MatrixBadType : public testing::TestWithParam<MatrixData> {
|
class MatrixBadType : public ParserImplTestWithParam<MatrixData> {};
|
||||||
public:
|
|
||||||
MatrixBadType() = default;
|
|
||||||
~MatrixBadType() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
TEST_P(MatrixBadType, Handles_Unknown_Type) {
|
TEST_P(MatrixBadType, Handles_Unknown_Type) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
auto* p = parser(params.input);
|
auto* p = parser(params.input);
|
||||||
|
@ -760,24 +613,8 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
MatrixData{"mat4x3<unknown>", 4, 3},
|
MatrixData{"mat4x3<unknown>", 4, 3},
|
||||||
MatrixData{"mat4x4<unknown>", 4, 4}));
|
MatrixData{"mat4x4<unknown>", 4, 4}));
|
||||||
|
|
||||||
class MatrixMissingType : public testing::TestWithParam<MatrixData> {
|
class MatrixMissingType : public ParserImplTestWithParam<MatrixData> {};
|
||||||
public:
|
|
||||||
MatrixMissingType() = default;
|
|
||||||
~MatrixMissingType() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
TEST_P(MatrixMissingType, Handles_Missing_Type) {
|
TEST_P(MatrixMissingType, Handles_Missing_Type) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
auto* p = parser(params.input);
|
auto* p = parser(params.input);
|
||||||
|
|
|
@ -76,24 +76,8 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {
|
||||||
out << std::string(data.input);
|
out << std::string(data.input);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
class BuiltinTest : public testing::TestWithParam<BuiltinData> {
|
|
||||||
public:
|
|
||||||
BuiltinTest() = default;
|
|
||||||
~BuiltinTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
class BuiltinTest : public ParserImplTestWithParam<BuiltinData> {};
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(BuiltinTest, VariableDecoration_Builtin) {
|
TEST_P(BuiltinTest, VariableDecoration_Builtin) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
|
@ -31,24 +31,8 @@ inline std::ostream& operator<<(std::ostream& out, VariableStorageData data) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VariableStorageTest : public testing::TestWithParam<VariableStorageData> {
|
class VariableStorageTest
|
||||||
public:
|
: public ParserImplTestWithParam<VariableStorageData> {};
|
||||||
VariableStorageTest() = default;
|
|
||||||
~VariableStorageTest() override = default;
|
|
||||||
|
|
||||||
void SetUp() override { ctx_.Reset(); }
|
|
||||||
|
|
||||||
void TearDown() override { impl_ = nullptr; }
|
|
||||||
|
|
||||||
ParserImpl* parser(const std::string& str) {
|
|
||||||
impl_ = std::make_unique<ParserImpl>(&ctx_, str);
|
|
||||||
return impl_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<ParserImpl> impl_;
|
|
||||||
Context ctx_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(VariableStorageTest, Parses) {
|
TEST_P(VariableStorageTest, Parses) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
Loading…
Reference in New Issue