diff --git a/tests/inputs-luau-full_moon/const_function.lua b/tests/inputs-luau-full_moon/const_function.lua new file mode 100644 index 000000000..4cd402f35 --- /dev/null +++ b/tests/inputs-luau-full_moon/const_function.lua @@ -0,0 +1,4 @@ +const function f() end +const function greet(name: string): string + return "Hello, " .. name +end diff --git a/tests/inputs-luau-full_moon/const_variable.lua b/tests/inputs-luau-full_moon/const_variable.lua new file mode 100644 index 000000000..ebdc72ec3 --- /dev/null +++ b/tests/inputs-luau-full_moon/const_variable.lua @@ -0,0 +1,10 @@ +const x = 5 +const f = function() end +const t = { a = 1 } +const x: number = 5 +const a, b = 1, 2 +const x: number, y: string = 1, "hello" +local const = 4 +const a, b = returns_two() +const a, b, c = 1, unpack(t) +const a, b = ... diff --git a/tests/inputs-luau-full_moon/types_leading_union_generic.lua b/tests/inputs-luau-full_moon/types_leading_union_generic.lua new file mode 100644 index 000000000..40ccd7c34 --- /dev/null +++ b/tests/inputs-luau-full_moon/types_leading_union_generic.lua @@ -0,0 +1,15 @@ +-- Issue #350: leading | in generic type arguments +type Test = Box< + | string + | number +> + +type Test2 = Box<| string | number> + +-- Issue #311 comment: leading & in generic type arguments +type Test3 = Generic<& boolean & string> + +type Test4 = Map< + & string & number, + | boolean | nil +> diff --git a/tests/inputs-luau-full_moon/types_leading_union_return.lua b/tests/inputs-luau-full_moon/types_leading_union_return.lua new file mode 100644 index 000000000..db9ad2032 --- /dev/null +++ b/tests/inputs-luau-full_moon/types_leading_union_return.lua @@ -0,0 +1,10 @@ +-- Issue #311 comment: leading | and & in function return types +type UnionReturn = () -> | string | number + +type IntersectionReturn = () -> & string & number + +type NestedReturn = (string) -> | boolean | nil + +-- Also valid in function type annotations +local f: () -> | string | number = nil +local g: (number) -> & string & number = nil diff --git a/tests/snapshots/tests__luau_full_moon@const_function.lua.snap b/tests/snapshots/tests__luau_full_moon@const_function.lua.snap new file mode 100644 index 000000000..0b953ad73 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@const_function.lua.snap @@ -0,0 +1,9 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/const_function.lua +--- +const function f() end +const function greet(name: string): string + return "Hello, " .. name +end diff --git a/tests/snapshots/tests__luau_full_moon@const_variable.lua.snap b/tests/snapshots/tests__luau_full_moon@const_variable.lua.snap new file mode 100644 index 000000000..f2374c6f5 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@const_variable.lua.snap @@ -0,0 +1,15 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/const_variable.lua +--- +const x = 5 +const f = function() end +const t = { a = 1 } +const x: number = 5 +const a, b = 1, 2 +const x: number, y: string = 1, "hello" +local const = 4 +const a, b = returns_two() +const a, b, c = 1, unpack(t) +const a, b = ... diff --git a/tests/snapshots/tests__luau_full_moon@types_leading_union_generic.lua.snap b/tests/snapshots/tests__luau_full_moon@types_leading_union_generic.lua.snap new file mode 100644 index 000000000..c26d0b850 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@types_leading_union_generic.lua.snap @@ -0,0 +1,14 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/types_leading_union_generic.lua +--- +-- Issue #350: leading | in generic type arguments +type Test = Box<| string | number> + +type Test2 = Box<| string | number> + +-- Issue #311 comment: leading & in generic type arguments +type Test3 = Generic<& boolean & string> + +type Test4 = Map<& string & number, | boolean | nil> diff --git a/tests/snapshots/tests__luau_full_moon@types_leading_union_return.lua.snap b/tests/snapshots/tests__luau_full_moon@types_leading_union_return.lua.snap new file mode 100644 index 000000000..e096cab50 --- /dev/null +++ b/tests/snapshots/tests__luau_full_moon@types_leading_union_return.lua.snap @@ -0,0 +1,15 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau-full_moon/types_leading_union_return.lua +--- +-- Issue #311 comment: leading | and & in function return types +type UnionReturn = () -> | string | number + +type IntersectionReturn = () -> & string & number + +type NestedReturn = (string) -> | boolean | nil + +-- Also valid in function type annotations +local f: () -> | string | number = nil +local g: (number) -> & string & number = nil