luau/tests/BuiltinDefinitions.test.cpp

48 lines
1.7 KiB
C++
Raw Normal View History

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#include "Luau/BuiltinDefinitions.h"
2023-01-03 17:33:19 +00:00
#include "Luau/Type.h"
#include "Fixture.h"
#include "doctest.h"
using namespace Luau;
TEST_SUITE_BEGIN("BuiltinDefinitionsTest");
2022-05-13 20:16:50 +01:00
TEST_CASE_FIXTURE(BuiltinsFixture, "lib_documentation_symbols")
{
2023-03-10 19:20:04 +00:00
CHECK(!frontend.globals.globalScope->bindings.empty());
2022-05-13 20:16:50 +01:00
2023-03-10 19:20:04 +00:00
for (const auto& [name, binding] : frontend.globals.globalScope->bindings)
{
std::string nameString(name.c_str());
std::string expectedRootSymbol = "@luau/global/" + nameString;
std::optional<std::string> actualRootSymbol = binding.documentationSymbol;
CHECK_MESSAGE(
actualRootSymbol == expectedRootSymbol, "expected symbol ", expectedRootSymbol, " for global ", nameString, ", got ", actualRootSymbol);
2023-01-03 17:33:19 +00:00
const TableType::Props* props = nullptr;
if (const TableType* ttv = get<TableType>(binding.typeId))
{
props = &ttv->props;
}
2023-01-03 17:33:19 +00:00
else if (const ClassType* ctv = get<ClassType>(binding.typeId))
{
props = &ctv->props;
}
if (props)
{
for (const auto& [propName, prop] : *props)
{
std::string fullPropName = nameString + "." + propName;
std::string expectedPropSymbol = expectedRootSymbol + "." + propName;
std::optional<std::string> actualPropSymbol = prop.documentationSymbol;
CHECK_MESSAGE(actualPropSymbol == expectedPropSymbol, "expected symbol ", expectedPropSymbol, " for ", fullPropName, ", got ",
actualPropSymbol);
}
}
}
}