Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attach comments after whitespace #391

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions tests/Documentation.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,73 @@ TEST_CASE_FIXTURE(Fixture, "attach_comments_to_variable_2")
CHECK_EQ(1, comments.size());
}

TEST_CASE_FIXTURE(Fixture, "dont_attach_comments_before_whitespace")
{
auto result = check(R"(
--- This shouldn't be included

--- A doc comment
local function foo()
end
)");

REQUIRE_EQ(0, result.errors.size());

auto ty = requireType("foo");
auto ftv = Luau::get<Luau::FunctionType>(ty);
REQUIRE(ftv);
REQUIRE(ftv->definition);

auto comments = getCommentLocations(getMainSourceModule(), ftv->definition->definitionLocation);
CHECK_EQ(1, comments.size());
}

TEST_CASE_FIXTURE(Fixture, "dont_attach_comments_before_whitespace_2")
{
auto result = check(R"(
--[[
This shouldn't be included
]]

--[[
A doc comment
]]
local function foo()
end
)");

REQUIRE_EQ(0, result.errors.size());

auto ty = requireType("foo");
auto ftv = Luau::get<Luau::FunctionType>(ty);
REQUIRE(ftv);
REQUIRE(ftv->definition);

auto comments = getCommentLocations(getMainSourceModule(), ftv->definition->definitionLocation);
CHECK_EQ(1, comments.size());
}

TEST_CASE_FIXTURE(Fixture, "include_multiple_comments")
{
auto result = check(R"(
--- This should be included, as it is a part of a whole block of comments
---
--- A doc comment
local function foo()
end
)");

REQUIRE_EQ(0, result.errors.size());

auto ty = requireType("foo");
auto ftv = Luau::get<Luau::FunctionType>(ty);
REQUIRE(ftv);
REQUIRE(ftv->definition);

auto comments = getCommentLocations(getMainSourceModule(), ftv->definition->definitionLocation);
CHECK_EQ(3, comments.size());
}

TEST_CASE_FIXTURE(Fixture, "print_comments")
{
auto result = check(R"(
Expand Down