2020-03-20 19:01:47 +00:00
|
|
|
// 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.
|
|
|
|
|
2020-11-13 18:13:24 +00:00
|
|
|
#include "src/writer/wgsl/test_helper.h"
|
2020-03-20 19:01:47 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
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;
|
|
|
|
}
|
2020-11-13 18:13:24 +00:00
|
|
|
using WgslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
2020-06-26 21:27:59 +00:00
|
|
|
TEST_P(WgslUnaryOpTest, Emit) {
|
2020-03-20 19:01:47 +00:00
|
|
|
auto params = GetParam();
|
|
|
|
|
2020-12-14 22:27:37 +00:00
|
|
|
auto* expr = Expr("expr");
|
|
|
|
auto* op = create<ast::UnaryOpExpression>(params.op, expr);
|
2020-03-20 19:01:47 +00:00
|
|
|
|
2021-01-21 16:15:00 +00:00
|
|
|
GeneratorImpl& gen = Build();
|
|
|
|
|
2020-12-14 22:27:37 +00:00
|
|
|
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
2020-11-13 18:13:24 +00:00
|
|
|
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");
|
2020-03-20 19:01:47 +00:00
|
|
|
}
|
2020-06-23 17:48:40 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest,
|
2020-06-26 21:27:59 +00:00
|
|
|
WgslUnaryOpTest,
|
2020-03-20 19:01:47 +00:00
|
|
|
testing::Values(UnaryOpData{"!", ast::UnaryOp::kNot},
|
|
|
|
UnaryOpData{"-",
|
|
|
|
ast::UnaryOp::kNegation}));
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace wgsl
|
|
|
|
} // namespace writer
|
|
|
|
} // namespace tint
|