summaryrefslogtreecommitdiff
path: root/test/type_inference/common.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/type_inference/common.lua')
-rw-r--r--test/type_inference/common.lua236
1 files changed, 236 insertions, 0 deletions
diff --git a/test/type_inference/common.lua b/test/type_inference/common.lua
index 5922832b..5fcec805 100644
--- a/test/type_inference/common.lua
+++ b/test/type_inference/common.lua
@@ -4192,3 +4192,239 @@ TEST 'boolean|number' [[
---@type A
local <?x?>
]]
+
+--reverse binary operator tests
+
+TEST 'A' [[
+---@class A
+---@operator add(number): A
+
+---@type A
+local x
+local <?y?> = x + 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator add(number): A
+
+---@type A
+local x
+local <?y?> = 1 + x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator sub(number): A
+
+---@type A
+local x
+local <?y?> = x - 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator sub(number): A
+
+---@type A
+local x
+local <?y?> = 1 - x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator mul(number): A
+
+---@type A
+local x
+local <?y?> = x * 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator mul(number): A
+
+---@type A
+local x
+local <?y?> = 1 * x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator div(number): A
+
+---@type A
+local x
+local <?y?> = x / 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator div(number): A
+
+---@type A
+local x
+local <?y?> = 1 / x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator idiv(number): A
+
+---@type A
+local x
+local <?y?> = x // 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator idiv(number): A
+
+---@type A
+local x
+local <?y?> = 1 // x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator mod(number): A
+
+---@type A
+local x
+local <?y?> = x % 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator mod(number): A
+
+---@type A
+local x
+local <?y?> = 1 % x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator pow(number): A
+
+---@type A
+local x
+local <?y?> = x ^ 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator pow(number): A
+
+---@type A
+local x
+local <?y?> = 1 ^ x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator concat(number): A
+
+---@type A
+local x
+local <?y?> = x .. 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator concat(number): A
+
+---@type A
+local x
+local <?y?> = 1 .. x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator band(number): A
+
+---@type A
+local x
+local <?y?> = x & 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator band(number): A
+
+---@type A
+local x
+local <?y?> = 1 & x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator bor(number): A
+
+---@type A
+local x
+local <?y?> = x | 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator bor(number): A
+
+---@type A
+local x
+local <?y?> = 1 | x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator bxor(number): A
+
+---@type A
+local x
+local <?y?> = x ~ 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator bxor(number): A
+
+---@type A
+local x
+local <?y?> = 1 ~ x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator shl(number): A
+
+---@type A
+local x
+local <?y?> = x << 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator shl(number): A
+
+---@type A
+local x
+local <?y?> = 1 << x
+]]
+
+TEST 'A' [[
+---@class A
+---@operator shr(number): A
+
+---@type A
+local x
+local <?y?> = x >> 1
+]]
+
+TEST 'A' [[
+---@class A
+---@operator shr(number): A
+
+---@type A
+local x
+local <?y?> = 1 >> x
+]]