luau/tests/NonStrictTypeChecker.test.cpp

50 lines
1.3 KiB
C++
Raw Normal View History

2023-09-30 08:22:06 +08: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-07 01:31:16 +08:00
#include "Luau/Common.h"
#include "Luau/Ast.h"
#include "Luau/ModuleResolver.h"
#include "ScopedFlags.h"
2023-09-30 08:22:06 +08:00
#include "doctest.h"
2023-10-07 01:31:16 +08:00
#include <iostream>
2023-09-30 08:22:06 +08:00
using namespace Luau;
2023-10-07 01:31:16 +08:00
struct NonStrictTypeCheckerFixture : Fixture
{
2023-10-14 03:38:31 +08:00
CheckResult checkNonStrict(const std::string& code)
2023-10-07 01:31:16 +08:00
{
2023-10-14 03:38:31 +08:00
ScopedFastFlag flags[] = {
{"LuauCheckedFunctionSyntax", true},
2023-10-21 04:36:26 +08:00
{"DebugLuauDeferredConstraintResolution", true},
2023-10-14 03:38:31 +08:00
};
2023-10-21 04:36:26 +08:00
LoadDefinitionFileResult res = loadDefinition(definitions);
LUAU_ASSERT(res.success);
2023-10-14 03:38:31 +08:00
return check(Mode::Nonstrict, code);
}
2023-09-30 08:22:06 +08:00
2023-10-14 03:38:31 +08:00
std::string definitions = R"BUILTIN_SRC(
2023-10-07 01:31:16 +08:00
declare function @checked abs(n: number): number
)BUILTIN_SRC";
2023-10-14 03:38:31 +08:00
};
2023-10-07 01:31:16 +08:00
2023-10-14 03:38:31 +08:00
TEST_SUITE_BEGIN("NonStrictTypeCheckerTest");
2023-10-07 01:31:16 +08:00
2023-10-14 03:38:31 +08:00
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "simple_non_strict")
2023-10-07 01:31:16 +08:00
{
2023-10-14 03:38:31 +08:00
auto res = checkNonStrict(R"BUILTIN_SRC(
abs("hi")
)BUILTIN_SRC");
2023-10-21 04:36:26 +08: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-07 01:31:16 +08:00
}
2023-09-30 08:22:06 +08:00
TEST_SUITE_END();