mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-13 00:26:00 +00:00
This CL removes the cast operator and converts the tests over to using type constructors. Bug: tint:241 Change-Id: I2526acb61f5624b2e1c068612a2ddcc748c92aed Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28860 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
65 lines
1.8 KiB
C++
65 lines
1.8 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 <memory>
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "src/ast/identifier_expression.h"
|
|
#include "src/ast/module.h"
|
|
#include "src/ast/type/f32_type.h"
|
|
#include "src/ast/type/vector_type.h"
|
|
#include "src/ast/type_constructor_expression.h"
|
|
#include "src/writer/msl/generator_impl.h"
|
|
|
|
namespace tint {
|
|
namespace writer {
|
|
namespace msl {
|
|
namespace {
|
|
|
|
using MslGeneratorImplTest = testing::Test;
|
|
|
|
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
|
ast::type::F32Type f32;
|
|
|
|
ast::ExpressionList params;
|
|
params.push_back(std::make_unique<ast::IdentifierExpression>("id"));
|
|
|
|
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
|
|
|
ast::Module m;
|
|
GeneratorImpl g(&m);
|
|
ASSERT_TRUE(g.EmitExpression(&cast)) << g.error();
|
|
EXPECT_EQ(g.result(), "float(id)");
|
|
}
|
|
|
|
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
|
ast::type::F32Type f32;
|
|
ast::type::VectorType vec3(&f32, 3);
|
|
|
|
ast::ExpressionList params;
|
|
params.push_back(std::make_unique<ast::IdentifierExpression>("id"));
|
|
|
|
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
|
|
|
ast::Module m;
|
|
GeneratorImpl g(&m);
|
|
ASSERT_TRUE(g.EmitExpression(&cast)) << g.error();
|
|
EXPECT_EQ(g.result(), "float3(id)");
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace msl
|
|
} // namespace writer
|
|
} // namespace tint
|