src/writer: Split UnaryOp TEST_P into TEST_Fs
Once the resolver correctly handles address-of and indirections, the logic around these will be different enough that a parameterized test no longer makes sense. Bug: tint:727 Change-Id: I79c138b12bd6f49d9dbee02c62e594a9b1b4a2db Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51185 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
fe0910fa37
commit
a965ad4d3a
|
@ -19,37 +19,57 @@ namespace writer {
|
|||
namespace hlsl {
|
||||
namespace {
|
||||
|
||||
struct UnaryOpData {
|
||||
const char* name;
|
||||
ast::UnaryOp op;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
|
||||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using HlslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
||||
TEST_P(HlslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
auto name = std::string(params.name);
|
||||
using HlslUnaryOpTest = TestHelper;
|
||||
|
||||
Global("expr", ty.i32(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* op = create<ast::UnaryOpExpression>(params.op, Expr("expr"));
|
||||
TEST_F(HlslUnaryOpTest, AddressOf) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
|
||||
EXPECT_EQ(result(), name.empty() ? "expr" : name + "(expr)");
|
||||
EXPECT_EQ(result(), "expr");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
HlslGeneratorImplTest_UnaryOp,
|
||||
HlslUnaryOpTest,
|
||||
testing::Values(UnaryOpData{"", ast::UnaryOp::kAddressOf},
|
||||
UnaryOpData{"", ast::UnaryOp::kIndirection},
|
||||
UnaryOpData{"!", ast::UnaryOp::kNot},
|
||||
UnaryOpData{"-", ast::UnaryOp::kNegation}));
|
||||
|
||||
TEST_F(HlslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
WrapInFunction(p, op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
|
||||
EXPECT_EQ(result(), "expr");
|
||||
}
|
||||
|
||||
TEST_F(HlslUnaryOpTest, Not) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
|
||||
EXPECT_EQ(result(), "!(expr)");
|
||||
}
|
||||
|
||||
TEST_F(HlslUnaryOpTest, Negation) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
|
||||
EXPECT_EQ(result(), "-(expr)");
|
||||
}
|
||||
} // namespace
|
||||
} // namespace hlsl
|
||||
} // namespace writer
|
||||
|
|
|
@ -19,34 +19,57 @@ namespace writer {
|
|||
namespace msl {
|
||||
namespace {
|
||||
|
||||
struct UnaryOpData {
|
||||
const char* name;
|
||||
ast::UnaryOp op;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
|
||||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using MslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
||||
TEST_P(MslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
Global("expr", ty.i32(), ast::StorageClass::kPrivate);
|
||||
using MslUnaryOpTest = TestHelper;
|
||||
|
||||
auto* op = create<ast::UnaryOpExpression>(params.op, Expr("expr"));
|
||||
TEST_F(MslUnaryOpTest, AddressOf) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");
|
||||
EXPECT_EQ(gen.result(), "&(expr)");
|
||||
}
|
||||
|
||||
TEST_F(MslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
WrapInFunction(p, op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "*(expr)");
|
||||
}
|
||||
|
||||
TEST_F(MslUnaryOpTest, Not) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "!(expr)");
|
||||
}
|
||||
|
||||
TEST_F(MslUnaryOpTest, Negation) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "-(expr)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
MslUnaryOpTest,
|
||||
testing::Values(UnaryOpData{"&", ast::UnaryOp::kAddressOf},
|
||||
UnaryOpData{"*", ast::UnaryOp::kIndirection},
|
||||
UnaryOpData{"!", ast::UnaryOp::kNot},
|
||||
UnaryOpData{"-", ast::UnaryOp::kNegation}));
|
||||
|
||||
} // namespace
|
||||
} // namespace msl
|
||||
|
|
|
@ -19,38 +19,57 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
struct UnaryOpData {
|
||||
const char* name;
|
||||
ast::UnaryOp op;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
|
||||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using WgslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
||||
TEST_P(WgslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
using WgslUnaryOpTest = TestHelper;
|
||||
|
||||
auto* type = (params.op == ast::UnaryOp::kNot)
|
||||
? static_cast<ast::Type*>(ty.bool_())
|
||||
: static_cast<ast::Type*>(ty.i32());
|
||||
Global("expr", type, ast::StorageClass::kPrivate);
|
||||
|
||||
auto* op = create<ast::UnaryOpExpression>(params.op, Expr("expr"));
|
||||
TEST_F(WgslUnaryOpTest, AddressOf) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");
|
||||
EXPECT_EQ(gen.result(), "&(expr)");
|
||||
}
|
||||
|
||||
TEST_F(WgslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
WrapInFunction(p, op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "*(expr)");
|
||||
}
|
||||
|
||||
TEST_F(WgslUnaryOpTest, Not) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "!(expr)");
|
||||
}
|
||||
|
||||
TEST_F(WgslUnaryOpTest, Negation) {
|
||||
Global("expr", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("expr"));
|
||||
WrapInFunction(op);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "-(expr)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
WgslGeneratorImplTest,
|
||||
WgslUnaryOpTest,
|
||||
testing::Values(UnaryOpData{"&", ast::UnaryOp::kAddressOf},
|
||||
UnaryOpData{"*", ast::UnaryOp::kIndirection},
|
||||
UnaryOpData{"!", ast::UnaryOp::kNot},
|
||||
UnaryOpData{"-", ast::UnaryOp::kNegation}));
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
|
|
Loading…
Reference in New Issue