Skip to content

Commit

Permalink
Sync with latest full-moon test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed Nov 16, 2024
1 parent 3d4d07f commit 2724905
Show file tree
Hide file tree
Showing 34 changed files with 197 additions and 10 deletions.
2 changes: 2 additions & 0 deletions tests/inputs-full_moon/assignment-4.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = 1
b = 2
1 change: 1 addition & 0 deletions tests/inputs-full_moon/assignment-5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gui.Label.Text = "LOADING DATA" .. ("."):rep(dotCount)
3 changes: 3 additions & 0 deletions tests/inputs-full_moon/body-with-spaces.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
do

end
1 change: 1 addition & 0 deletions tests/inputs-full_moon/negative-numbers.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local foo = x-1
local foo = x -1
print(1+-3)
local foo = -x+1
1 change: 1 addition & 0 deletions tests/inputs-full_moon/numbers-1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_ = 0x02
6 changes: 6 additions & 0 deletions tests/inputs-full_moon/table-constructors-9.lua
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions tests/inputs-luau-full_moon/compound_assignment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ x += 5
x -= 5
x *= 5
x /= 5
x //= 5
x %= 5
x ^= 5

x += y
x -= y
x *= y
x /= y
x //= y
x %= y
x ^= y

Expand Down
12 changes: 12 additions & 0 deletions tests/inputs-luau-full_moon/multiline_expressions.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/inputs-luau-full_moon/multiline_typeof_regression.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type TypeOf =
typeof({})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error(
`a {b} c`
)
4 changes: 4 additions & 0 deletions tests/inputs-luau-full_moon/table_access_modifiers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type Foo = {
read bar: number,
write baz: number,
}
2 changes: 2 additions & 0 deletions tests/inputs-luau-full_moon/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/inputs-luau-full_moon/types_chained_optionals.lua
Original file line number Diff line number Diff line change
@@ -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!
}
7 changes: 7 additions & 0 deletions tests/inputs-luau-full_moon/types_compound_precedence.lua
Original file line number Diff line number Diff line change
@@ -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...> = () -> U... & T
3 changes: 2 additions & 1 deletion tests/inputs-luau-full_moon/types_generic_no_parameters.lua
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
type Bar = Foo<>
type Bar = Foo<>
type Baz = module.Foo<>
3 changes: 3 additions & 0 deletions tests/inputs-luau-full_moon/types_variadic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ function Boo:f(name: string, ...: number): () -> (string, ...Foo) -> ()
return function(_x: string, ...: Foo) end
end
end

type Fn<U...> = any
type T = Fn<...'ok'>
5 changes: 4 additions & 1 deletion tests/inputs-luau-full_moon/z-escape-string.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
print("testing \z
twelve")
twelve")

print("Hello \
World")
8 changes: 8 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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)

8 changes: 8 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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

4 changes: 3 additions & 1 deletion tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: tests/tests.rs
expression: "format(&contents, LuaVersion::Lua51)"
input_file: tests/inputs-full_moon/numbers-1.lua
---
_ = 0x02

12 changes: 12 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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
}

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,13 +10,15 @@ x += 5
x -= 5
x *= 5
x /= 5
x //= 5
x %= 5
x ^= 5

x += y
x -= y
x *= y
x /= y
x //= y
x %= y
x ^= y

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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({})

Original file line number Diff line number Diff line change
@@ -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`)

Original file line number Diff line number Diff line change
@@ -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,
}

5 changes: 4 additions & 1 deletion tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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!
}

Original file line number Diff line number Diff line change
@@ -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...> = () -> U... & T

Original file line number Diff line number Diff line change
@@ -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<>

Original file line number Diff line number Diff line change
@@ -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) -> ()
Expand All @@ -25,3 +26,6 @@ function Boo:f(name: string, ...: number): () -> (string, ...Foo) -> ()
end
end

type Fn<U...> = any
type T = Fn<..."ok">

5 changes: 4 additions & 1 deletion tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 2724905

Please sign in to comment.