2020-04-22 00:23:49 +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.
|
|
|
|
|
|
|
|
#include "src/ast/expression.h"
|
|
|
|
|
2020-11-13 21:58:28 +00:00
|
|
|
#include "src/ast/test_helper.h"
|
2021-01-21 15:42:10 +00:00
|
|
|
#include "src/type/alias_type.h"
|
|
|
|
#include "src/type/i32_type.h"
|
2020-04-22 00:23:49 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace ast {
|
|
|
|
namespace {
|
|
|
|
|
2020-12-14 22:30:57 +00:00
|
|
|
class FakeExpr : public Expression {
|
2020-04-22 00:23:49 +00:00
|
|
|
public:
|
2020-12-14 22:30:57 +00:00
|
|
|
FakeExpr() : Expression(Source{}) {}
|
2020-04-22 00:23:49 +00:00
|
|
|
|
2020-12-14 22:30:57 +00:00
|
|
|
FakeExpr* Clone(CloneContext*) const override { return nullptr; }
|
2020-04-22 00:23:49 +00:00
|
|
|
bool IsValid() const override { return true; }
|
|
|
|
void to_str(std::ostream&, size_t) const override {}
|
|
|
|
};
|
|
|
|
|
2020-11-13 21:58:28 +00:00
|
|
|
using ExpressionTest = TestHelper;
|
2020-04-22 00:23:49 +00:00
|
|
|
|
|
|
|
TEST_F(ExpressionTest, set_result_type) {
|
2020-12-14 22:30:57 +00:00
|
|
|
FakeExpr e;
|
|
|
|
e.set_result_type(ty.i32);
|
2020-04-22 00:23:49 +00:00
|
|
|
ASSERT_NE(e.result_type(), nullptr);
|
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_TRUE(e.result_type()->Is<type::I32>());
|
2020-04-22 00:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ExpressionTest, set_result_type_alias) {
|
2020-12-16 21:38:40 +00:00
|
|
|
auto* a = ty.alias("a", ty.i32);
|
|
|
|
auto* b = ty.alias("b", a);
|
2020-04-22 00:23:49 +00:00
|
|
|
|
2020-12-14 22:30:57 +00:00
|
|
|
FakeExpr e;
|
2020-12-16 21:38:40 +00:00
|
|
|
e.set_result_type(b);
|
2020-04-22 00:23:49 +00:00
|
|
|
ASSERT_NE(e.result_type(), nullptr);
|
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_TRUE(e.result_type()->Is<type::I32>());
|
2020-04-22 00:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace ast
|
2020-04-22 00:24:11 +00:00
|
|
|
} // namespace tint
|