// 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 "gtest/gtest-spi.h"
#include "src/tint/lang/wgsl/ast/test_helper.h"

namespace tint::ast {
namespace {

using CallExpressionTest = TestHelper;

TEST_F(CallExpressionTest, CreationIdentifier) {
    auto* func = Expr("func");
    tint::Vector params{
        Expr("param1"),
        Expr("param2"),
    };

    auto* stmt = Call(func, params);
    EXPECT_EQ(stmt->target, func);

    const auto& vec = stmt->args;
    ASSERT_EQ(vec.Length(), 2u);
    EXPECT_EQ(vec[0], params[0]);
    EXPECT_EQ(vec[1], params[1]);
}

TEST_F(CallExpressionTest, CreationIdentifier_WithSource) {
    auto* func = Expr("func");
    auto* stmt = Call(Source{{20, 2}}, func);
    EXPECT_EQ(stmt->target, func);

    auto src = stmt->source;
    EXPECT_EQ(src.range.begin.line, 20u);
    EXPECT_EQ(src.range.begin.column, 2u);
}

TEST_F(CallExpressionTest, CreationType) {
    auto* type = Expr(ty.f32());
    tint::Vector params{
        Expr("param1"),
        Expr("param2"),
    };

    auto* stmt = Call(type, params);
    EXPECT_EQ(stmt->target, type);

    const auto& vec = stmt->args;
    ASSERT_EQ(vec.Length(), 2u);
    EXPECT_EQ(vec[0], params[0]);
    EXPECT_EQ(vec[1], params[1]);
}

TEST_F(CallExpressionTest, CreationType_WithSource) {
    auto* type = Expr(ty.f32());
    auto* stmt = Call(Source{{20, 2}}, type);
    EXPECT_EQ(stmt->target, type);

    auto src = stmt->source;
    EXPECT_EQ(src.range.begin.line, 20u);
    EXPECT_EQ(src.range.begin.column, 2u);
}

TEST_F(CallExpressionTest, IsCall) {
    auto* func = Expr("func");
    auto* stmt = Call(func);
    EXPECT_TRUE(stmt->Is<CallExpression>());
}

TEST_F(CallExpressionTest, Assert_Null_Identifier) {
    EXPECT_FATAL_FAILURE(
        {
            ProgramBuilder b;
            b.Call(static_cast<Identifier*>(nullptr));
        },
        "internal compiler error");
}

TEST_F(CallExpressionTest, Assert_Null_Param) {
    EXPECT_FATAL_FAILURE(
        {
            ProgramBuilder b;
            b.Call(b.Ident("func"), tint::Vector{
                                        b.Expr("param1"),
                                        nullptr,
                                        b.Expr("param2"),
                                    });
        },
        "internal compiler error");
}

TEST_F(CallExpressionTest, Assert_DifferentGenerationID_Identifier) {
    EXPECT_FATAL_FAILURE(
        {
            ProgramBuilder b1;
            ProgramBuilder b2;
            b1.Call(b2.Ident("func"));
        },
        "internal compiler error");
}

TEST_F(CallExpressionTest, Assert_DifferentGenerationID_Type) {
    EXPECT_FATAL_FAILURE(
        {
            ProgramBuilder b1;
            ProgramBuilder b2;
            b1.Call(b2.ty.f32());
        },
        "internal compiler error");
}

TEST_F(CallExpressionTest, Assert_DifferentGenerationID_Param) {
    EXPECT_FATAL_FAILURE(
        {
            ProgramBuilder b1;
            ProgramBuilder b2;
            b1.Call(b1.Ident("func"), b2.Expr("param1"));
        },
        "internal compiler error");
}

}  // namespace
}  // namespace tint::ast
