2022-10-27 23:22:49 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
#include "Fixture.h"
|
|
|
|
|
|
|
|
#include "doctest.h"
|
|
|
|
#include "Luau/Common.h"
|
|
|
|
#include "ScopedFlags.h"
|
|
|
|
|
|
|
|
using namespace Luau;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct NegationFixture : Fixture
|
|
|
|
{
|
|
|
|
TypeArena arena;
|
2022-12-09 18:07:25 +00:00
|
|
|
ScopedFastFlag sff[1]{
|
2022-10-27 23:22:49 +01:00
|
|
|
{"LuauSubtypeNormalizer", true},
|
|
|
|
};
|
|
|
|
|
|
|
|
NegationFixture()
|
|
|
|
{
|
2022-11-04 17:02:37 +00:00
|
|
|
registerHiddenTypes(*this, arena);
|
2022-10-27 23:22:49 +01:00
|
|
|
}
|
|
|
|
};
|
2022-11-04 17:02:37 +00:00
|
|
|
} // namespace
|
2022-10-27 23:22:49 +01:00
|
|
|
|
|
|
|
TEST_SUITE_BEGIN("Negations");
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(NegationFixture, "negated_string_is_a_subtype_of_string")
|
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
function foo(arg: string) end
|
|
|
|
local a: string & Not<"Hello">
|
|
|
|
foo(a)
|
|
|
|
)");
|
|
|
|
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(NegationFixture, "string_is_not_a_subtype_of_negated_string")
|
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
function foo(arg: string & Not<"hello">) end
|
|
|
|
local a: string
|
|
|
|
foo(a)
|
|
|
|
)");
|
|
|
|
|
|
|
|
LUAU_REQUIRE_ERROR_COUNT(1, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_SUITE_END();
|