mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
Respect useLineBreaks for union/intersect toString (#487)
* Respect useLineBreaks for union/intersect toString * Apply suggestions from code review Co-authored-by: Andy Friesen <andy.friesen@gmail.com> Co-authored-by: Andy Friesen <andy.friesen@gmail.com>
This commit is contained in:
parent
ab4bb355a3
commit
f2191b9e4d
@ -745,7 +745,10 @@ struct TypeVarStringifier
|
||||
for (std::string& ss : results)
|
||||
{
|
||||
if (!first)
|
||||
state.emit(" | ");
|
||||
{
|
||||
state.newline();
|
||||
state.emit("| ");
|
||||
}
|
||||
state.emit(ss);
|
||||
first = false;
|
||||
}
|
||||
@ -798,7 +801,10 @@ struct TypeVarStringifier
|
||||
for (std::string& ss : results)
|
||||
{
|
||||
if (!first)
|
||||
state.emit(" & ");
|
||||
{
|
||||
state.newline();
|
||||
state.emit("& ");
|
||||
}
|
||||
state.emit(ss);
|
||||
first = false;
|
||||
}
|
||||
|
@ -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{};
|
||||
|
Loading…
Reference in New Issue
Block a user