Skip to content

Commit

Permalink
Merge 22e9882 into ab4bb35
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed May 17, 2022
2 parents ab4bb35 + 22e9882 commit 323752f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Analysis/src/ToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,10 @@ struct TypeVarStringifier
for (std::string& ss : results)
{
if (!first)
state.emit(" | ");
{
state.newline();
state.emit("| ");
}
state.emit(ss);
first = false;
}
Expand Down Expand Up @@ -798,7 +801,10 @@ struct TypeVarStringifier
for (std::string& ss : results)
{
if (!first)
state.emit(" & ");
{
state.newline();
state.emit("& ");
}
state.emit(ss);
first = false;
}
Expand Down
33 changes: 33 additions & 0 deletions tests/ToString.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,39 @@ TEST_CASE_FIXTURE(Fixture, "functions_are_always_parenthesized_in_unions_or_inte
CHECK_EQ(toString(&itv), "((number, string) -> (string, number)) & ((string, number) -> (number, string))");
}

TEST_CASE_FIXTURE(Fixture, "intersections_respects_use_line_breaks")
{
CheckResult result = check(R"(
local a: ((string) -> string) & ((number) -> number)
)");

ToStringOptions opts;
opts.useLineBreaks = true;

//clang-format off
CHECK_EQ("((number) -> number)\n"
"& ((string) -> string)",
toString(requireType("a"), opts));
//clang-format on
}

TEST_CASE_FIXTURE(Fixture, "unions_respects_use_line_breaks")
{
CheckResult result = check(R"(
local a: string | number | boolean
)");

ToStringOptions opts;
opts.useLineBreaks = true;

//clang-format off
CHECK_EQ("boolean\n"
"| number\n"
"| string",
toString(requireType("a"), opts));
//clang-format on
}

TEST_CASE_FIXTURE(Fixture, "quit_stringifying_table_type_when_length_is_exceeded")
{
TableTypeVar ttv{};
Expand Down

0 comments on commit 323752f

Please sign in to comment.