From 272490571da5a2e44ac594dcabbcad9e1344b635 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 16 Nov 2024 20:28:37 +0100 Subject: [PATCH] Sync with latest full-moon test cases --- tests/inputs-full_moon/assignment-4.lua | 2 ++ tests/inputs-full_moon/assignment-5.lua | 1 + tests/inputs-full_moon/body-with-spaces.lua | 3 +++ tests/inputs-full_moon/negative-numbers.lua | 1 + tests/inputs-full_moon/numbers-1.lua | 1 + .../inputs-full_moon/table-constructors-9.lua | 6 +++++ .../compound_assignment.lua | 2 ++ .../multiline_expressions.lua | 12 +++++++++ .../multiline_typeof_regression.lua | 2 ++ .../string_interpolation_regression.lua | 3 +++ .../table_access_modifiers.lua | 4 +++ tests/inputs-luau-full_moon/types.lua | 2 ++ .../types_chained_optionals.lua | 5 ++++ .../types_compound_precedence.lua | 7 ++++++ .../types_generic_no_parameters.lua | 3 ++- .../inputs-luau-full_moon/types_variadic.lua | 3 +++ .../inputs-luau-full_moon/z-escape-string.lua | 5 +++- ...full_moon_test_suite@assignment-4.lua.snap | 8 ++++++ ...full_moon_test_suite@assignment-5.lua.snap | 7 ++++++ ..._moon_test_suite@body-with-spaces.lua.snap | 8 ++++++ ..._moon_test_suite@negative-numbers.lua.snap | 4 ++- ...s__full_moon_test_suite@numbers-1.lua.snap | 7 ++++++ ...n_test_suite@table-constructors-9.lua.snap | 12 +++++++++ ...uau_full_moon@compound_assignment.lua.snap | 5 +++- ...u_full_moon@multiline_expressions.lua.snap | 25 +++++++++++++++++++ ..._moon@multiline_typeof_regression.lua.snap | 7 ++++++ ...n@string_interpolation_regression.lua.snap | 7 ++++++ ..._full_moon@table_access_modifiers.lua.snap | 10 ++++++++ .../tests__luau_full_moon@types.lua.snap | 5 +++- ...full_moon@types_chained_optionals.lua.snap | 11 ++++++++ ...ll_moon@types_compound_precedence.lua.snap | 13 ++++++++++ ..._moon@types_generic_no_parameters.lua.snap | 5 ++-- ...ts__luau_full_moon@types_variadic.lua.snap | 6 ++++- ...s__luau_full_moon@z-escape-string.lua.snap | 5 +++- 34 files changed, 197 insertions(+), 10 deletions(-) create mode 100644 tests/inputs-full_moon/assignment-4.lua create mode 100644 tests/inputs-full_moon/assignment-5.lua create mode 100644 tests/inputs-full_moon/body-with-spaces.lua create mode 100644 tests/inputs-full_moon/numbers-1.lua create mode 100644 tests/inputs-full_moon/table-constructors-9.lua create mode 100644 tests/inputs-luau-full_moon/multiline_expressions.lua create mode 100644 tests/inputs-luau-full_moon/multiline_typeof_regression.lua create mode 100644 tests/inputs-luau-full_moon/string_interpolation_regression.lua create mode 100644 tests/inputs-luau-full_moon/table_access_modifiers.lua create mode 100644 tests/inputs-luau-full_moon/types_chained_optionals.lua create mode 100644 tests/inputs-luau-full_moon/types_compound_precedence.lua create mode 100644 tests/snapshots/tests__full_moon_test_suite@assignment-4.lua.snap create mode 100644 tests/snapshots/tests__full_moon_test_suite@assignment-5.lua.snap create mode 100644 tests/snapshots/tests__full_moon_test_suite@body-with-spaces.lua.snap create mode 100644 tests/snapshots/tests__full_moon_test_suite@numbers-1.lua.snap create mode 100644 tests/snapshots/tests__full_moon_test_suite@table-constructors-9.lua.snap create mode 100644 tests/snapshots/tests__luau_full_moon@multiline_expressions.lua.snap create mode 100644 tests/snapshots/tests__luau_full_moon@multiline_typeof_regression.lua.snap create mode 100644 tests/snapshots/tests__luau_full_moon@string_interpolation_regression.lua.snap create mode 100644 tests/snapshots/tests__luau_full_moon@table_access_modifiers.lua.snap create mode 100644 tests/snapshots/tests__luau_full_moon@types_chained_optionals.lua.snap create mode 100644 tests/snapshots/tests__luau_full_moon@types_compound_precedence.lua.snap diff --git a/tests/inputs-full_moon/assignment-4.lua b/tests/inputs-full_moon/assignment-4.lua new file mode 100644 index 00000000..223ca50d --- /dev/null +++ b/tests/inputs-full_moon/assignment-4.lua @@ -0,0 +1,2 @@ +a = 1 +b = 2 diff --git a/tests/inputs-full_moon/assignment-5.lua b/tests/inputs-full_moon/assignment-5.lua new file mode 100644 index 00000000..8a751ba0 --- /dev/null +++ b/tests/inputs-full_moon/assignment-5.lua @@ -0,0 +1 @@ +gui.Label.Text = "LOADING DATA" .. ("."):rep(dotCount) diff --git a/tests/inputs-full_moon/body-with-spaces.lua b/tests/inputs-full_moon/body-with-spaces.lua new file mode 100644 index 00000000..c0697c93 --- /dev/null +++ b/tests/inputs-full_moon/body-with-spaces.lua @@ -0,0 +1,3 @@ +do + +end \ No newline at end of file diff --git a/tests/inputs-full_moon/negative-numbers.lua b/tests/inputs-full_moon/negative-numbers.lua index da83d445..3b7ccd77 100644 --- a/tests/inputs-full_moon/negative-numbers.lua +++ b/tests/inputs-full_moon/negative-numbers.lua @@ -1,3 +1,4 @@ local foo = x-1 local foo = x -1 print(1+-3) +local foo = -x+1 \ No newline at end of file diff --git a/tests/inputs-full_moon/numbers-1.lua b/tests/inputs-full_moon/numbers-1.lua new file mode 100644 index 00000000..71e00d7f --- /dev/null +++ b/tests/inputs-full_moon/numbers-1.lua @@ -0,0 +1 @@ +_ = 0x02 diff --git a/tests/inputs-full_moon/table-constructors-9.lua b/tests/inputs-full_moon/table-constructors-9.lua new file mode 100644 index 00000000..2ec60090 --- /dev/null +++ b/tests/inputs-full_moon/table-constructors-9.lua @@ -0,0 +1,6 @@ +-- comments separated by tab chars, should be parsed as trailing trivia of the tokens they are next to +-- stylua: ignore +local too = { + x, -- string + y, -- string +} diff --git a/tests/inputs-luau-full_moon/compound_assignment.lua b/tests/inputs-luau-full_moon/compound_assignment.lua index 650b350b..ed2ab3c8 100644 --- a/tests/inputs-luau-full_moon/compound_assignment.lua +++ b/tests/inputs-luau-full_moon/compound_assignment.lua @@ -5,6 +5,7 @@ x += 5 x -= 5 x *= 5 x /= 5 +x //= 5 x %= 5 x ^= 5 @@ -12,6 +13,7 @@ x += y x -= y x *= y x /= y +x //= y x %= y x ^= y diff --git a/tests/inputs-luau-full_moon/multiline_expressions.lua b/tests/inputs-luau-full_moon/multiline_expressions.lua new file mode 100644 index 00000000..c899cbb5 --- /dev/null +++ b/tests/inputs-luau-full_moon/multiline_expressions.lua @@ -0,0 +1,12 @@ +-- Taken from https://github.com/JohnnyMorganz/StyLua/blob/main/tests/inputs/multiline-expressions-3.lua +do + do + do + do + local text = "Players: " .. #Server_Container.ARandomVariableWhichIsVeryLongSoThatThisGetsOverTheColumnLimit.Players_F:GetChildren() - 1 .. "/20" + local ratio = (minAxis - minAxisSize) / delta * (self.props.maxScaleRatio - self.props.minScaleRatio) + self.props.minScaleRatio + local ratio2 = (minAxis - minAxisSize) / delta * (self.props.maxScaleRatio - self.props.minScaleRatio) * self.props.aRandomVariableWhichIsVeryLong + self.props.minScaleRatio + end + end + end +end diff --git a/tests/inputs-luau-full_moon/multiline_typeof_regression.lua b/tests/inputs-luau-full_moon/multiline_typeof_regression.lua new file mode 100644 index 00000000..918ba268 --- /dev/null +++ b/tests/inputs-luau-full_moon/multiline_typeof_regression.lua @@ -0,0 +1,2 @@ +type TypeOf = + typeof({}) diff --git a/tests/inputs-luau-full_moon/string_interpolation_regression.lua b/tests/inputs-luau-full_moon/string_interpolation_regression.lua new file mode 100644 index 00000000..bd3b1b44 --- /dev/null +++ b/tests/inputs-luau-full_moon/string_interpolation_regression.lua @@ -0,0 +1,3 @@ +error( + `a {b} c` +) diff --git a/tests/inputs-luau-full_moon/table_access_modifiers.lua b/tests/inputs-luau-full_moon/table_access_modifiers.lua new file mode 100644 index 00000000..e784583e --- /dev/null +++ b/tests/inputs-luau-full_moon/table_access_modifiers.lua @@ -0,0 +1,4 @@ +type Foo = { + read bar: number, + write baz: number, +} \ No newline at end of file diff --git a/tests/inputs-luau-full_moon/types.lua b/tests/inputs-luau-full_moon/types.lua index eb1d48c6..995d0145 100644 --- a/tests/inputs-luau-full_moon/types.lua +++ b/tests/inputs-luau-full_moon/types.lua @@ -30,9 +30,11 @@ local _foo4: string, _bar1: string local _union: number | string local _multiUnion: number | string | nil +local _leadingUnion: | number | string | nil local _intersection: number & string local _multiIntersection: number & string & nil +local _leadingIntersection: & number & string & nil function _fn0(param: string): string return param diff --git a/tests/inputs-luau-full_moon/types_chained_optionals.lua b/tests/inputs-luau-full_moon/types_chained_optionals.lua new file mode 100644 index 00000000..0809eac6 --- /dev/null +++ b/tests/inputs-luau-full_moon/types_chained_optionals.lua @@ -0,0 +1,5 @@ +type Config = { + option1: string??, -- you probably need it once in a while + option2: string???, -- once a year + option3: string?????? -- once in your life! +} \ No newline at end of file diff --git a/tests/inputs-luau-full_moon/types_compound_precedence.lua b/tests/inputs-luau-full_moon/types_compound_precedence.lua new file mode 100644 index 00000000..5950d4d2 --- /dev/null +++ b/tests/inputs-luau-full_moon/types_compound_precedence.lua @@ -0,0 +1,7 @@ +-- https://github.com/Kampfkarren/full-moon/issues/286 + +-- should be parsed as a function returning a variable amount of values of type "string & T" +type FnA = () -> ...string & T + +-- should be parsed as an intersection of a function returning U... values, and a value of type T +type FnB = () -> U... & T diff --git a/tests/inputs-luau-full_moon/types_generic_no_parameters.lua b/tests/inputs-luau-full_moon/types_generic_no_parameters.lua index 09b69300..85bc070d 100644 --- a/tests/inputs-luau-full_moon/types_generic_no_parameters.lua +++ b/tests/inputs-luau-full_moon/types_generic_no_parameters.lua @@ -1 +1,2 @@ -type Bar = Foo<> \ No newline at end of file +type Bar = Foo<> +type Baz = module.Foo<> \ No newline at end of file diff --git a/tests/inputs-luau-full_moon/types_variadic.lua b/tests/inputs-luau-full_moon/types_variadic.lua index 7eb991df..45669424 100644 --- a/tests/inputs-luau-full_moon/types_variadic.lua +++ b/tests/inputs-luau-full_moon/types_variadic.lua @@ -20,3 +20,6 @@ function Boo:f(name: string, ...: number): () -> (string, ...Foo) -> () return function(_x: string, ...: Foo) end end end + +type Fn = any +type T = Fn<...'ok'> \ No newline at end of file diff --git a/tests/inputs-luau-full_moon/z-escape-string.lua b/tests/inputs-luau-full_moon/z-escape-string.lua index 230a2b44..3167d6c9 100644 --- a/tests/inputs-luau-full_moon/z-escape-string.lua +++ b/tests/inputs-luau-full_moon/z-escape-string.lua @@ -1,2 +1,5 @@ print("testing \z - twelve") \ No newline at end of file + twelve") + +print("Hello \ + World") diff --git a/tests/snapshots/tests__full_moon_test_suite@assignment-4.lua.snap b/tests/snapshots/tests__full_moon_test_suite@assignment-4.lua.snap new file mode 100644 index 00000000..660f2fd8 --- /dev/null +++ b/tests/snapshots/tests__full_moon_test_suite@assignment-4.lua.snap @@ -0,0 +1,8 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Lua51)" +input_file: tests/inputs-full_moon/assignment-4.lua +--- +a = 1 +b = 2 + diff --git a/tests/snapshots/tests__full_moon_test_suite@assignment-5.lua.snap b/tests/snapshots/tests__full_moon_test_suite@assignment-5.lua.snap new file mode 100644 index 00000000..01540fba --- /dev/null +++ b/tests/snapshots/tests__full_moon_test_suite@assignment-5.lua.snap @@ -0,0 +1,7 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Lua51)" +input_file: tests/inputs-full_moon/assignment-5.lua +--- +gui.Label.Text = "LOADING DATA" .. ("."):rep(dotCount) + diff --git a/tests/snapshots/tests__full_moon_test_suite@body-with-spaces.lua.snap b/tests/snapshots/tests__full_moon_test_suite@body-with-spaces.lua.snap new file mode 100644 index 00000000..3ea47137 --- /dev/null +++ b/tests/snapshots/tests__full_moon_test_suite@body-with-spaces.lua.snap @@ -0,0 +1,8 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Lua51)" +input_file: tests/inputs-full_moon/body-with-spaces.lua +--- +do +end + diff --git a/tests/snapshots/tests__full_moon_test_suite@negative-numbers.lua.snap b/tests/snapshots/tests__full_moon_test_suite@negative-numbers.lua.snap index 7405d8ff..2eb4e139 100644 --- a/tests/snapshots/tests__full_moon_test_suite@negative-numbers.lua.snap +++ b/tests/snapshots/tests__full_moon_test_suite@negative-numbers.lua.snap @@ -1,8 +1,10 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Lua51)" +input_file: tests/inputs-full_moon/negative-numbers.lua --- local foo = x - 1 local foo = x - 1 print(1 + -3) +local foo = -x + 1 diff --git a/tests/snapshots/tests__full_moon_test_suite@numbers-1.lua.snap b/tests/snapshots/tests__full_moon_test_suite@numbers-1.lua.snap new file mode 100644 index 00000000..329cdf98 --- /dev/null +++ b/tests/snapshots/tests__full_moon_test_suite@numbers-1.lua.snap @@ -0,0 +1,7 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Lua51)" +input_file: tests/inputs-full_moon/numbers-1.lua +--- +_ = 0x02 + diff --git a/tests/snapshots/tests__full_moon_test_suite@table-constructors-9.lua.snap b/tests/snapshots/tests__full_moon_test_suite@table-constructors-9.lua.snap new file mode 100644 index 00000000..0b91f7f8 --- /dev/null +++ b/tests/snapshots/tests__full_moon_test_suite@table-constructors-9.lua.snap @@ -0,0 +1,12 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Lua51)" +input_file: tests/inputs-full_moon/table-constructors-9.lua +--- +-- comments separated by tab chars, should be parsed as trailing trivia of the tokens they are next to +-- stylua: ignore +local too = { + x, -- string + y, -- string +} + diff --git a/tests/snapshots/tests__luau_full_moon@compound_assignment.lua.snap b/tests/snapshots/tests__luau_full_moon@compound_assignment.lua.snap index 2d3d9054..a67191dd 100644 --- a/tests/snapshots/tests__luau_full_moon@compound_assignment.lua.snap +++ b/tests/snapshots/tests__luau_full_moon@compound_assignment.lua.snap @@ -1,6 +1,7 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/compound_assignment.lua --- local x = 1 local y = 2 @@ -9,6 +10,7 @@ x += 5 x -= 5 x *= 5 x /= 5 +x //= 5 x %= 5 x ^= 5 @@ -16,6 +18,7 @@ x += y x -= y x *= y x /= y +x //= y x %= y x ^= y diff --git a/tests/snapshots/tests__luau_full_moon@multiline_expressions.lua.snap b/tests/snapshots/tests__luau_full_moon@multiline_expressions.lua.snap new file mode 100644 index 00000000..01ad6394 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@multiline_expressions.lua.snap @@ -0,0 +1,25 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/multiline_expressions.lua +--- +-- Taken from https://github.com/JohnnyMorganz/StyLua/blob/main/tests/inputs/multiline-expressions-3.lua +do + do + do + do + local text = "Players: " + .. #Server_Container.ARandomVariableWhichIsVeryLongSoThatThisGetsOverTheColumnLimit.Players_F:GetChildren() - 1 + .. "/20" + local ratio = (minAxis - minAxisSize) / delta * (self.props.maxScaleRatio - self.props.minScaleRatio) + + self.props.minScaleRatio + local ratio2 = (minAxis - minAxisSize) + / delta + * (self.props.maxScaleRatio - self.props.minScaleRatio) + * self.props.aRandomVariableWhichIsVeryLong + + self.props.minScaleRatio + end + end + end +end + diff --git a/tests/snapshots/tests__luau_full_moon@multiline_typeof_regression.lua.snap b/tests/snapshots/tests__luau_full_moon@multiline_typeof_regression.lua.snap new file mode 100644 index 00000000..fb6cf93f --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@multiline_typeof_regression.lua.snap @@ -0,0 +1,7 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/multiline_typeof_regression.lua +--- +type TypeOf = typeof({}) + diff --git a/tests/snapshots/tests__luau_full_moon@string_interpolation_regression.lua.snap b/tests/snapshots/tests__luau_full_moon@string_interpolation_regression.lua.snap new file mode 100644 index 00000000..2e02e8f3 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@string_interpolation_regression.lua.snap @@ -0,0 +1,7 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/string_interpolation_regression.lua +--- +error(`a {b} c`) + diff --git a/tests/snapshots/tests__luau_full_moon@table_access_modifiers.lua.snap b/tests/snapshots/tests__luau_full_moon@table_access_modifiers.lua.snap new file mode 100644 index 00000000..14fd4b00 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@table_access_modifiers.lua.snap @@ -0,0 +1,10 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/table_access_modifiers.lua +--- +type Foo = { + read bar: number, + write baz: number, +} + diff --git a/tests/snapshots/tests__luau_full_moon@types.lua.snap b/tests/snapshots/tests__luau_full_moon@types.lua.snap index 5b794f9a..5fa715c7 100644 --- a/tests/snapshots/tests__luau_full_moon@types.lua.snap +++ b/tests/snapshots/tests__luau_full_moon@types.lua.snap @@ -1,6 +1,7 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/types.lua --- --!strict local _fn3 @@ -34,9 +35,11 @@ local _foo4: string, _bar1: string local _union: number | string local _multiUnion: number | string | nil +local _leadingUnion: | number | string | nil local _intersection: number & string local _multiIntersection: number & string & nil +local _leadingIntersection: & number & string & nil function _fn0(param: string): string return param diff --git a/tests/snapshots/tests__luau_full_moon@types_chained_optionals.lua.snap b/tests/snapshots/tests__luau_full_moon@types_chained_optionals.lua.snap new file mode 100644 index 00000000..b05eddb4 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@types_chained_optionals.lua.snap @@ -0,0 +1,11 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/types_chained_optionals.lua +--- +type Config = { + option1: string??, -- you probably need it once in a while + option2: string???, -- once a year + option3: string??????, -- once in your life! +} + diff --git a/tests/snapshots/tests__luau_full_moon@types_compound_precedence.lua.snap b/tests/snapshots/tests__luau_full_moon@types_compound_precedence.lua.snap new file mode 100644 index 00000000..fcf08b00 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@types_compound_precedence.lua.snap @@ -0,0 +1,13 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/types_compound_precedence.lua +--- +-- https://github.com/Kampfkarren/full-moon/issues/286 + +-- should be parsed as a function returning a variable amount of values of type "string & T" +type FnA = () -> ...string & T + +-- should be parsed as an intersection of a function returning U... values, and a value of type T +type FnB = () -> U... & T + diff --git a/tests/snapshots/tests__luau_full_moon@types_generic_no_parameters.lua.snap b/tests/snapshots/tests__luau_full_moon@types_generic_no_parameters.lua.snap index adec725e..57144629 100644 --- a/tests/snapshots/tests__luau_full_moon@types_generic_no_parameters.lua.snap +++ b/tests/snapshots/tests__luau_full_moon@types_generic_no_parameters.lua.snap @@ -1,9 +1,8 @@ --- source: tests/tests.rs -assertion_line: 40 -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" input_file: tests/inputs-luau-full_moon/types_generic_no_parameters.lua - --- type Bar = Foo<> +type Baz = module.Foo<> diff --git a/tests/snapshots/tests__luau_full_moon@types_variadic.lua.snap b/tests/snapshots/tests__luau_full_moon@types_variadic.lua.snap index 962384d6..29fa391f 100644 --- a/tests/snapshots/tests__luau_full_moon@types_variadic.lua.snap +++ b/tests/snapshots/tests__luau_full_moon@types_variadic.lua.snap @@ -1,6 +1,7 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/types_variadic.lua --- --!strict type Foo = (...number) -> () @@ -25,3 +26,6 @@ function Boo:f(name: string, ...: number): () -> (string, ...Foo) -> () end end +type Fn = any +type T = Fn<..."ok"> + diff --git a/tests/snapshots/tests__luau_full_moon@z-escape-string.lua.snap b/tests/snapshots/tests__luau_full_moon@z-escape-string.lua.snap index 4c4f690d..ccc01eb4 100644 --- a/tests/snapshots/tests__luau_full_moon@z-escape-string.lua.snap +++ b/tests/snapshots/tests__luau_full_moon@z-escape-string.lua.snap @@ -1,8 +1,11 @@ --- source: tests/tests.rs -expression: format(&contents) +expression: "format(&contents, LuaVersion::Luau)" input_file: tests/inputs-luau-full_moon/z-escape-string.lua --- print("testing \z twelve") +print("Hello \ + World") +