mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add tests
This commit is contained in:
parent
937c5e91a6
commit
80ecbe6fff
2 changed files with 114 additions and 1 deletions
|
@ -13,8 +13,8 @@
|
|||
LUAU_FASTFLAGVARIABLE(LuauPreloadClosures, false)
|
||||
LUAU_FASTFLAGVARIABLE(LuauPreloadClosuresFenv, false)
|
||||
LUAU_FASTFLAGVARIABLE(LuauPreloadClosuresUpval, false)
|
||||
LUAU_FASTFLAGVARIABLE(LuauGenericSpecialGlobals, false)
|
||||
LUAU_FASTFLAG(LuauIfElseExpressionBaseSupport)
|
||||
LUAU_FASTFLAG(LuauGenericSpecialGlobals)
|
||||
|
||||
namespace Luau
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
LUAU_FASTFLAG(LuauPreloadClosures)
|
||||
LUAU_FASTFLAG(LuauPreloadClosuresFenv)
|
||||
LUAU_FASTFLAG(LuauPreloadClosuresUpval)
|
||||
LUAU_FASTFLAG(LuauGenericSpecialGlobals)
|
||||
|
||||
using namespace Luau;
|
||||
|
||||
|
@ -3670,4 +3671,116 @@ RETURN R0 0
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_CASE("LuauGenericSpecialGlobals")
|
||||
{
|
||||
FFlag::LuauGenericSpecialGlobals.value = false;
|
||||
|
||||
const char* source = R"(
|
||||
print()
|
||||
Game.print()
|
||||
Workspace.print()
|
||||
_G.print()
|
||||
game.print()
|
||||
plugin.print()
|
||||
script.print()
|
||||
shared.print()
|
||||
workspace.print()
|
||||
)";
|
||||
|
||||
// Check Roblox globals are here
|
||||
CHECK_EQ("\n" + compileFunction0(source), R"(
|
||||
GETIMPORT R0 1
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 3
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 5
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 7
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 9
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 11
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 13
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 15
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 17
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
RETURN R0 0
|
||||
)");
|
||||
|
||||
FFlag::LuauGenericSpecialGlobals.value = true;
|
||||
|
||||
// Check Roblox globals are no longer here
|
||||
CHECK_EQ("\n" + compileFunction0(source), R"(
|
||||
GETIMPORT R0 1
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 3
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 5
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 7
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 9
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 11
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 13
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 15
|
||||
CALL R0 0 0
|
||||
GETIMPORT R0 17
|
||||
CALL R0 0 0
|
||||
RETURN R0 0
|
||||
)");
|
||||
|
||||
// Check we can add them back
|
||||
Luau::BytecodeBuilder bcb;
|
||||
bcb.setDumpFlags(Luau::BytecodeBuilder::Dump_Code);
|
||||
Luau::CompileOptions options;
|
||||
const char* mutableGlobals[] = {"Game", "Workspace", "game", "plugin", "script", "shared", "workspace", NULL};
|
||||
options.mutableGlobalNames = &mutableGlobals[0];
|
||||
Luau::compileOrThrow(bcb, source, options);
|
||||
|
||||
CHECK_EQ("\n" + bcb.dumpFunction(0), R"(
|
||||
GETIMPORT R0 1
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 3
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 5
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 7
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 9
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 11
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 13
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 15
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
GETIMPORT R1 17
|
||||
GETTABLEKS R0 R1 K0
|
||||
CALL R0 0 0
|
||||
RETURN R0 0
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
|
Loading…
Add table
Reference in a new issue