mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
d47b2f1dfe
- Type mismatch errors now show detailed information for compound types, highlighting the mismatching component - Fix string.pack bug on ARM when packing negative numbers using unsigned formats - Implement bit32.countlz/countrz (RFC RFC: bit32.countlz/countrz #89) - Minor compiler throughput optimization (~2% faster compilation) - Improve transpiler behavior for edge cases and better test coverage (not exposed through CLI at the moment) - Improve error recovery when parsing invalid assignments - Build fixes for fuzzing targets
81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "Fixture.h"
|
|
|
|
#include "Luau/AstQuery.h"
|
|
|
|
#include "doctest.h"
|
|
|
|
using namespace Luau;
|
|
|
|
struct DocumentationSymbolFixture : Fixture
|
|
{
|
|
std::optional<DocumentationSymbol> getDocSymbol(const std::string& source, Position position)
|
|
{
|
|
check(source);
|
|
|
|
SourceModule* sourceModule = getMainSourceModule();
|
|
ModulePtr module = getMainModule();
|
|
|
|
return getDocumentationSymbolAtPosition(*sourceModule, *module, position);
|
|
}
|
|
};
|
|
|
|
TEST_SUITE_BEGIN("AstQuery::getDocumentationSymbolAtPosition");
|
|
|
|
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "binding")
|
|
{
|
|
std::optional<DocumentationSymbol> global = getDocSymbol(R"(
|
|
local a = string.sub()
|
|
)",
|
|
Position(1, 21));
|
|
|
|
CHECK_EQ(global, "@luau/global/string");
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "prop")
|
|
{
|
|
std::optional<DocumentationSymbol> substring = getDocSymbol(R"(
|
|
local a = string.sub()
|
|
)",
|
|
Position(1, 27));
|
|
|
|
CHECK_EQ(substring, "@luau/global/string.sub");
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "event_callback_arg")
|
|
{
|
|
ScopedFastFlag sffs[] = {
|
|
{"LuauPersistDefinitionFileTypes", true},
|
|
};
|
|
|
|
loadDefinition(R"(
|
|
declare function Connect(fn: (string) -> ())
|
|
)");
|
|
|
|
std::optional<DocumentationSymbol> substring = getDocSymbol(R"(
|
|
Connect(function(abc)
|
|
end)
|
|
)",
|
|
Position(1, 27));
|
|
|
|
CHECK_EQ(substring, "@test/global/Connect/param/0/param/0");
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "overloaded_fn")
|
|
{
|
|
ScopedFastFlag sffs{"LuauStoreMatchingOverloadFnType", true};
|
|
|
|
loadDefinition(R"(
|
|
declare foo: ((string) -> number) & ((number) -> string)
|
|
)");
|
|
|
|
std::optional<DocumentationSymbol> symbol = getDocSymbol(R"(
|
|
foo("asdf")
|
|
)",
|
|
Position(1, 10));
|
|
|
|
CHECK_EQ(symbol, "@test/global/foo/overload/(string) -> number");
|
|
}
|
|
|
|
TEST_SUITE_END();
|