mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-14 19:31:25 +00:00
This CL adds tests for the UnaryDerivativeExpression AST element. Bug: tint:11 Change-Id: Ieabfdcb7940aedc58a3455b74c0ddb508b4859ff Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/16673 Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
89 lines
2.9 KiB
C++
89 lines
2.9 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.
|
|
|
|
#include "src/ast/unary_derivative_expression.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "src/ast/identifier_expression.h"
|
|
|
|
namespace tint {
|
|
namespace ast {
|
|
|
|
using UnaryDerivativeExpressionTest = testing::Test;
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, Creation) {
|
|
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
auto ident_ptr = ident.get();
|
|
|
|
UnaryDerivativeExpression d(UnaryDerivative::kDpdy,
|
|
DerivativeModifier::kCoarse, std::move(ident));
|
|
EXPECT_EQ(d.param(), ident_ptr);
|
|
EXPECT_EQ(d.modifier(), DerivativeModifier::kCoarse);
|
|
EXPECT_EQ(d.op(), UnaryDerivative::kDpdy);
|
|
}
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, Creation_WithSource) {
|
|
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
|
|
UnaryDerivativeExpression d(Source{20, 2}, UnaryDerivative::kDpdy,
|
|
DerivativeModifier::kCoarse, std::move(ident));
|
|
auto src = d.source();
|
|
EXPECT_EQ(src.line, 20);
|
|
EXPECT_EQ(src.column, 2);
|
|
}
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, IsUnaryDerivative) {
|
|
UnaryDerivativeExpression d;
|
|
EXPECT_TRUE(d.IsUnaryDerivative());
|
|
}
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, IsValid) {
|
|
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
UnaryDerivativeExpression d(UnaryDerivative::kDpdy,
|
|
DerivativeModifier::kCoarse, std::move(ident));
|
|
EXPECT_TRUE(d.IsValid());
|
|
}
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, IsValid_NullParam) {
|
|
UnaryDerivativeExpression d(UnaryDerivative::kDpdy,
|
|
DerivativeModifier::kCoarse, nullptr);
|
|
EXPECT_FALSE(d.IsValid());
|
|
}
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, IsValid_InvalidParam) {
|
|
auto ident = std::make_unique<IdentifierExpression>("");
|
|
UnaryDerivativeExpression d(UnaryDerivative::kDpdy,
|
|
DerivativeModifier::kCoarse, std::move(ident));
|
|
EXPECT_FALSE(d.IsValid());
|
|
}
|
|
|
|
TEST_F(UnaryDerivativeExpressionTest, ToStr) {
|
|
auto ident = std::make_unique<IdentifierExpression>("ident");
|
|
UnaryDerivativeExpression d(UnaryDerivative::kDpdy,
|
|
DerivativeModifier::kCoarse, std::move(ident));
|
|
std::ostringstream out;
|
|
d.to_str(out, 2);
|
|
EXPECT_EQ(out.str(), R"( UnaryDerivative{
|
|
dpdy
|
|
coarse
|
|
Identifier{ident}
|
|
}
|
|
)");
|
|
}
|
|
|
|
} // namespace ast
|
|
} // namespace tint
|