luau/tests/NonStrictTypeChecker.test.cpp

50 lines
1.3 KiB
C++
Raw Normal View History

2023-09-30 01:22:06 +01:00
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#include "Luau/NonStrictTypeChecker.h"
#include "Fixture.h"
2023-10-06 18:31:16 +01:00
#include "Luau/Common.h"
#include "Luau/Ast.h"
#include "Luau/ModuleResolver.h"
#include "ScopedFlags.h"
2023-09-30 01:22:06 +01:00
#include "doctest.h"
2023-10-06 18:31:16 +01:00
#include <iostream>
2023-09-30 01:22:06 +01:00
using namespace Luau;
2023-10-06 18:31:16 +01:00
struct NonStrictTypeCheckerFixture : Fixture
{
2023-10-13 20:38:31 +01:00
CheckResult checkNonStrict(const std::string& code)
2023-10-06 18:31:16 +01:00
{
2023-10-13 20:38:31 +01:00
ScopedFastFlag flags[] = {
{"LuauCheckedFunctionSyntax", true},
2023-10-20 21:36:26 +01:00
{"DebugLuauDeferredConstraintResolution", true},
2023-10-13 20:38:31 +01:00
};
2023-10-20 21:36:26 +01:00
LoadDefinitionFileResult res = loadDefinition(definitions);
LUAU_ASSERT(res.success);
2023-10-13 20:38:31 +01:00
return check(Mode::Nonstrict, code);
}
2023-09-30 01:22:06 +01:00
2023-10-13 20:38:31 +01:00
std::string definitions = R"BUILTIN_SRC(
2023-10-06 18:31:16 +01:00
declare function @checked abs(n: number): number
)BUILTIN_SRC";
2023-10-13 20:38:31 +01:00
};
2023-10-06 18:31:16 +01:00
2023-10-13 20:38:31 +01:00
TEST_SUITE_BEGIN("NonStrictTypeCheckerTest");
2023-10-06 18:31:16 +01:00
2023-10-13 20:38:31 +01:00
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "simple_non_strict")
2023-10-06 18:31:16 +01:00
{
2023-10-13 20:38:31 +01:00
auto res = checkNonStrict(R"BUILTIN_SRC(
abs("hi")
)BUILTIN_SRC");
2023-10-20 21:36:26 +01:00
LUAU_REQUIRE_ERRORS(res);
REQUIRE(res.errors.size() == 1);
auto err = get<CheckedFunctionCallError>(res.errors[0]);
REQUIRE(err != nullptr);
REQUIRE(err->checkedFunctionName == "abs");
2023-10-06 18:31:16 +01:00
}
2023-09-30 01:22:06 +01:00
TEST_SUITE_END();