mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add unit test for vector literals
This commit is contained in:
parent
83d4de36e0
commit
b3b0e10282
1 changed files with 21 additions and 1 deletions
|
@ -17,12 +17,17 @@ std::string rep(const std::string& s, size_t n);
|
||||||
|
|
||||||
using namespace Luau;
|
using namespace Luau;
|
||||||
|
|
||||||
static std::string compileFunction(const char* source, uint32_t id, int optimizationLevel = 1)
|
static std::string compileFunction(const char* source, uint32_t id, int optimizationLevel = 1, bool enableVectors = false)
|
||||||
{
|
{
|
||||||
Luau::BytecodeBuilder bcb;
|
Luau::BytecodeBuilder bcb;
|
||||||
bcb.setDumpFlags(Luau::BytecodeBuilder::Dump_Code);
|
bcb.setDumpFlags(Luau::BytecodeBuilder::Dump_Code);
|
||||||
Luau::CompileOptions options;
|
Luau::CompileOptions options;
|
||||||
options.optimizationLevel = optimizationLevel;
|
options.optimizationLevel = optimizationLevel;
|
||||||
|
if (enableVectors)
|
||||||
|
{
|
||||||
|
options.vectorLib = "Vector3";
|
||||||
|
options.vectorCtor = "new";
|
||||||
|
}
|
||||||
Luau::compileOrThrow(bcb, source, options);
|
Luau::compileOrThrow(bcb, source, options);
|
||||||
|
|
||||||
return bcb.dumpFunction(id);
|
return bcb.dumpFunction(id);
|
||||||
|
@ -4489,6 +4494,21 @@ L0: RETURN R0 -1
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("VectorLiterals")
|
||||||
|
{
|
||||||
|
CHECK_EQ("\n" + compileFunction("return Vector3.new(1, 2, 3)", 0, 2, true), R"(
|
||||||
|
LOADK R0 K0 []
|
||||||
|
RETURN R0 1
|
||||||
|
)");
|
||||||
|
|
||||||
|
CHECK_EQ("\n" + compileFunction("print(Vector3.new(1, 2, 3))", 0, 2, true), R"(
|
||||||
|
GETIMPORT R0 1 [print]
|
||||||
|
LOADK R1 K2 []
|
||||||
|
CALL R0 1 0
|
||||||
|
RETURN R0 0
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("TypeAssertion")
|
TEST_CASE("TypeAssertion")
|
||||||
{
|
{
|
||||||
// validate that type assertions work with the compiler and that the code inside type assertion isn't evaluated
|
// validate that type assertions work with the compiler and that the code inside type assertion isn't evaluated
|
||||||
|
|
Loading…
Add table
Reference in a new issue