Respect useLineBreaks for union/intersect toString

This commit is contained in:
JohnnyMorganz 2022-05-17 15:37:07 +01:00
parent ab4bb355a3
commit bcae1e935c
2 changed files with 41 additions and 4 deletions

View file

@ -744,8 +744,10 @@ struct TypeVarStringifier
bool first = true;
for (std::string& ss : results)
{
if (!first)
state.emit(" | ");
if (!first) {
state.newline();
state.emit("| ");
}
state.emit(ss);
first = false;
}
@ -797,8 +799,10 @@ struct TypeVarStringifier
bool first = true;
for (std::string& ss : results)
{
if (!first)
state.emit(" & ");
if (!first) {
state.newline();
state.emit("& ");
}
state.emit(ss);
first = false;
}

View file

@ -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{};