mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-17 02:26:07 +00:00
create() is currently just a simple forwarder to std::make_unique<>, but will be later replaced with a function that returns a raw pointer, and owned by the context. Bug: tint:322 Change-Id: I0e68992963f52e432d4d485feae1123f35732552 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32664 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
113 lines
3.3 KiB
C++
113 lines
3.3 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/assignment_statement.h"
|
|
|
|
#include "src/ast/identifier_expression.h"
|
|
#include "src/ast/test_helper.h"
|
|
|
|
namespace tint {
|
|
namespace ast {
|
|
namespace {
|
|
|
|
using AssignmentStatementTest = TestHelper;
|
|
|
|
TEST_F(AssignmentStatementTest, Creation) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
|
|
auto* lhs_ptr = lhs.get();
|
|
auto* rhs_ptr = rhs.get();
|
|
|
|
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
|
|
EXPECT_EQ(stmt.lhs(), lhs_ptr);
|
|
EXPECT_EQ(stmt.rhs(), rhs_ptr);
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, CreationWithSource) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
|
|
AssignmentStatement stmt(Source{Source::Location{20, 2}}, std::move(lhs),
|
|
std::move(rhs));
|
|
auto src = stmt.source();
|
|
EXPECT_EQ(src.range.begin.line, 20u);
|
|
EXPECT_EQ(src.range.begin.column, 2u);
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, IsAssign) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
|
|
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
|
|
EXPECT_TRUE(stmt.IsAssign());
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, IsValid) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
|
|
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
|
|
EXPECT_TRUE(stmt.IsValid());
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
|
|
AssignmentStatement stmt;
|
|
stmt.set_rhs(std::move(rhs));
|
|
EXPECT_FALSE(stmt.IsValid());
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
|
|
AssignmentStatement stmt;
|
|
stmt.set_lhs(std::move(lhs));
|
|
EXPECT_FALSE(stmt.IsValid());
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
|
|
auto lhs = create<ast::IdentifierExpression>("");
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
|
|
EXPECT_FALSE(stmt.IsValid());
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
auto rhs = create<ast::IdentifierExpression>("");
|
|
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
|
|
EXPECT_FALSE(stmt.IsValid());
|
|
}
|
|
|
|
TEST_F(AssignmentStatementTest, ToStr) {
|
|
auto lhs = create<ast::IdentifierExpression>("lhs");
|
|
auto rhs = create<ast::IdentifierExpression>("rhs");
|
|
|
|
AssignmentStatement stmt(std::move(lhs), std::move(rhs));
|
|
std::ostringstream out;
|
|
stmt.to_str(out, 2);
|
|
|
|
EXPECT_EQ(out.str(), R"( Assignment{
|
|
Identifier{lhs}
|
|
Identifier{rhs}
|
|
}
|
|
)");
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace ast
|
|
} // namespace tint
|