Skip to content

Commit 4d6c56e

Browse files
Update external test cases (#1062)
1 parent 648d2af commit 4d6c56e

File tree

3 files changed

+147
-25
lines changed

3 files changed

+147
-25
lines changed

tests/inputs-luau-full_moon/type_instantiation.lua

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--[[
2+
3+
Taken from https://github.com/luau-lang/luau/blob/535f92589bdc304c8a2012d6cfad5e7b9faff2f7/tests/conformance/explicit_type_instantiations.luau
4+
5+
MIT License
6+
7+
Copyright (c) 2019-2025 Roblox Corporation
8+
Copyright (c) 1994–2019 Lua.org, PUC-Rio.
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy of
11+
this software and associated documentation files (the "Software"), to deal in
12+
the Software without restriction, including without limitation the rights to
13+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14+
of the Software, and to permit persons to whom the Software is furnished to do
15+
so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
28+
]]
29+
30+
-- Tests to ensure explicit type instantiations don't change runtime behavior
31+
local function identity<T>(x: T): T
32+
return x
33+
end
34+
35+
assert(identity<<number>>(1) == 1)
36+
37+
local function multipleReturns<T>(x: T): (T, T)
38+
return x, x
39+
end
40+
41+
local a, b = multipleReturns<<number>>(1)
42+
assert(a == 1 and b == 1)
43+
44+
local function typePacks<T...>(...: T...): T...
45+
return ...
46+
end
47+
48+
local a, b = typePacks<<(string, number)>>(1, "a")
49+
assert(a == 1 and b == "a")
50+
51+
local t = {}
52+
function t:method<T>(x: T): T
53+
assert(self == t)
54+
return x
55+
end
56+
57+
assert(t:method(1) == 1)
58+
59+
function t:methodTypePacks<T...>(...: T...): T...
60+
assert(self == t)
61+
return ...
62+
end
63+
64+
local a, b = t:methodTypePacks<<(string, number)>>(1, "a")
65+
assert(a == 1 and b == "a")
66+
67+
-- full-moon tests
68+
local complicatedExpr = expr<<A<B<C>>>>()
69+
local complicatedMethod = a:method<<A<B<C>>>>()
70+
71+
return "OK"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
source: tests/tests.rs
3+
expression: "format(&contents, LuaVersion::Luau)"
4+
input_file: tests/inputs-luau-full_moon/type_instantiations.lua
5+
---
6+
--[[
7+
8+
Taken from https://github.com/luau-lang/luau/blob/535f92589bdc304c8a2012d6cfad5e7b9faff2f7/tests/conformance/explicit_type_instantiations.luau
9+
10+
MIT License
11+
12+
Copyright (c) 2019-2025 Roblox Corporation
13+
Copyright (c) 19942019 Lua.org, PUC-Rio.
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy of
16+
this software and associated documentation files (the "Software"), to deal in
17+
the Software without restriction, including without limitation the rights to
18+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
19+
of the Software, and to permit persons to whom the Software is furnished to do
20+
so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE.
32+
33+
]]
34+
35+
-- Tests to ensure explicit type instantiations don't change runtime behavior
36+
local function identity<T>(x: T): T
37+
return x
38+
end
39+
40+
assert(identity<<number>>(1) == 1)
41+
42+
local function multipleReturns<T>(x: T): (T, T)
43+
return x, x
44+
end
45+
46+
local a, b = multipleReturns<<number>>(1)
47+
assert(a == 1 and b == 1)
48+
49+
local function typePacks<T...>(...: T...): T...
50+
return ...
51+
end
52+
53+
local a, b = typePacks<<(string, number)>>(1, "a")
54+
assert(a == 1 and b == "a")
55+
56+
local t = {}
57+
function t:method<T>(x: T): T
58+
assert(self == t)
59+
return x
60+
end
61+
62+
assert(t:method(1) == 1)
63+
64+
function t:methodTypePacks<T...>(...: T...): T...
65+
assert(self == t)
66+
return ...
67+
end
68+
69+
local a, b = t:methodTypePacks<<(string, number)>>(1, "a")
70+
assert(a == 1 and b == "a")
71+
72+
-- full-moon tests
73+
local complicatedExpr = expr<<A<B<C>>>>()
74+
local complicatedMethod = a:method<<A<B<C>>>>()
75+
76+
return "OK"

0 commit comments

Comments
 (0)