// Copyright 2020 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/lang/core/builtin_value.h"
#include "src/tint/lang/wgsl/ast/helper_test.h"
#include "src/tint/lang/wgsl/ast/id_attribute.h"

using namespace tint::core::number_suffixes;  // NOLINT

namespace tint::ast {
namespace {

using VariableTest = TestHelper;

TEST_F(VariableTest, Creation) {
    auto* v = Var("my_var", ty.i32(), core::AddressSpace::kFunction);

    CheckIdentifier(v->name, "my_var");
    CheckIdentifier(v->declared_address_space, "function");
    EXPECT_EQ(v->declared_access, nullptr);
    CheckIdentifier(v->type, "i32");
    EXPECT_EQ(v->source.range.begin.line, 0u);
    EXPECT_EQ(v->source.range.begin.column, 0u);
    EXPECT_EQ(v->source.range.end.line, 0u);
    EXPECT_EQ(v->source.range.end.column, 0u);
}

TEST_F(VariableTest, CreationWithSource) {
    auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
                  ty.f32(), core::AddressSpace::kPrivate, tint::Empty);

    CheckIdentifier(v->name, "i");
    CheckIdentifier(v->declared_address_space, "private");
    CheckIdentifier(v->type, "f32");
    EXPECT_EQ(v->source.range.begin.line, 27u);
    EXPECT_EQ(v->source.range.begin.column, 4u);
    EXPECT_EQ(v->source.range.end.line, 27u);
    EXPECT_EQ(v->source.range.end.column, 5u);
}

TEST_F(VariableTest, CreationEmpty) {
    auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
                  ty.i32(), core::AddressSpace::kWorkgroup, tint::Empty);

    CheckIdentifier(v->name, "a_var");
    CheckIdentifier(v->declared_address_space, "workgroup");
    CheckIdentifier(v->type, "i32");
    EXPECT_EQ(v->source.range.begin.line, 27u);
    EXPECT_EQ(v->source.range.begin.column, 4u);
    EXPECT_EQ(v->source.range.end.line, 27u);
    EXPECT_EQ(v->source.range.end.column, 7u);
}

TEST_F(VariableTest, Assert_Null_Name) {
    EXPECT_DEATH(
        {
            ProgramBuilder b;
            b.Var(static_cast<Identifier*>(nullptr), b.ty.i32());
        },
        "internal compiler error");
}

TEST_F(VariableTest, Assert_DifferentGenerationID_Symbol) {
    EXPECT_DEATH(
        {
            ProgramBuilder b1;
            ProgramBuilder b2;
            b1.Var(b2.Sym("x"), b1.ty.f32());
        },
        "internal compiler error");
}

TEST_F(VariableTest, Assert_DifferentGenerationID_Initializer) {
    EXPECT_DEATH(
        {
            ProgramBuilder b1;
            ProgramBuilder b2;
            b1.Var("x", b1.ty.f32(), b2.Expr(1.2_f));
        },
        "internal compiler error");
}

TEST_F(VariableTest, WithAttributes) {
    auto* var = Var("my_var", ty.i32(), core::AddressSpace::kFunction, Location(1_u),
                    Builtin(core::BuiltinValue::kPosition), Id(1200_u));

    auto& attributes = var->attributes;
    EXPECT_TRUE(ast::HasAttribute<LocationAttribute>(attributes));
    EXPECT_TRUE(ast::HasAttribute<BuiltinAttribute>(attributes));
    EXPECT_TRUE(ast::HasAttribute<IdAttribute>(attributes));

    auto* location = GetAttribute<LocationAttribute>(attributes);
    ASSERT_NE(nullptr, location);
    ASSERT_NE(nullptr, location->expr);
    EXPECT_TRUE(location->expr->Is<IntLiteralExpression>());
}

TEST_F(VariableTest, HasBindingPoint_BothProvided) {
    auto* var = Var("my_var", ty.i32(), core::AddressSpace::kFunction, Binding(2_a), Group(1_a));
    EXPECT_TRUE(var->HasBindingPoint());
}

TEST_F(VariableTest, HasBindingPoint_NeitherProvided) {
    auto* var = Var("my_var", ty.i32(), core::AddressSpace::kFunction, tint::Empty);
    EXPECT_FALSE(var->HasBindingPoint());
}

TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) {
    auto* var = Var("my_var", ty.i32(), core::AddressSpace::kFunction, Binding(2_a));
    EXPECT_FALSE(var->HasBindingPoint());
}

TEST_F(VariableTest, HasBindingPoint_MissingBindingAttribute) {
    auto* var = Var("my_var", ty.i32(), core::AddressSpace::kFunction, Group(1_a));
    EXPECT_FALSE(var->HasBindingPoint());
}

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