-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error messages for > do not have the operands flipped
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
local util = require("spec.util") | ||
|
||
describe(">=", function() | ||
it("ok", util.check([[ | ||
local x = 1 | ||
local y = 2 | ||
local z = true | ||
if x >= y then | ||
z = false | ||
end | ||
]])) | ||
|
||
it("fail", util.check_type_error([[ | ||
local x = 1 | ||
local y = "hello" | ||
local z = true | ||
if x >= y then | ||
z = false | ||
end | ||
]], { | ||
{ msg = "cannot use operator '>=' for types integer and string" } | ||
})) | ||
|
||
it("fails with not gotcha", util.check_type_error([[ | ||
local x = 10 | ||
local y = 20 | ||
if not x >= y then | ||
print("wat") | ||
end | ||
]], { | ||
{ msg = "cannot use operator '>=' for types boolean and integer" } | ||
})) | ||
|
||
it(">= on aliases to comparable types return boolean", util.check([[ | ||
local type Test = integer | ||
local function f(a: Test, b: Test) : boolean | ||
return a >= b | ||
end | ||
]])) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
local util = require("spec.util") | ||
|
||
describe(">", function() | ||
it("ok", util.check([[ | ||
local x = 1 | ||
local y = 2 | ||
local z = true | ||
if x > y then | ||
z = false | ||
end | ||
]])) | ||
|
||
it("fail", util.check_type_error([[ | ||
local x = 1 | ||
local y = "hello" | ||
local z = true | ||
if x > y then | ||
z = false | ||
end | ||
]], { | ||
{ msg = "cannot use operator '>' for types integer and string" } | ||
})) | ||
|
||
it("fails with not gotcha", util.check_type_error([[ | ||
local x = 10 | ||
local y = 20 | ||
if not x > y then | ||
print("wat") | ||
end | ||
]], { | ||
{ msg = "cannot use operator '>' for types boolean and integer" } | ||
})) | ||
|
||
it("> on aliases to comparable types return boolean", util.check([[ | ||
local type Test = integer | ||
local function f(a: Test, b: Test) : boolean | ||
return a > b | ||
end | ||
]])) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
local util = require("spec.util") | ||
|
||
describe("<=", function() | ||
it("ok", util.check([[ | ||
local x = 1 | ||
local y = 2 | ||
local z = true | ||
if x <= y then | ||
z = false | ||
end | ||
]])) | ||
|
||
it("fail", util.check_type_error([[ | ||
local x = 1 | ||
local y = "hello" | ||
local z = true | ||
if x <= y then | ||
z = false | ||
end | ||
]], { | ||
{ msg = "cannot use operator '<=' for types integer and string" } | ||
})) | ||
|
||
it("fails with not gotcha", util.check_type_error([[ | ||
local x = 10 | ||
local y = 20 | ||
if not x <= y then | ||
print("wat") | ||
end | ||
]], { | ||
{ msg = "cannot use operator '<=' for types boolean and integer" } | ||
})) | ||
|
||
it("<= on aliases to comparable types return boolean", util.check([[ | ||
local type Test = integer | ||
local function f(a: Test, b: Test) : boolean | ||
return a <= b | ||
end | ||
]])) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters