diff options
author | SeanTheBuilder1 <seanthebuilder52@gmail.com> | 2024-08-03 14:27:37 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2024-08-06 21:13:33 +0800 |
commit | 6ebd54af6221f0e65d4436c9d071d4e5878297fa (patch) | |
tree | 13a360515271b1e8261acae2bed8d002c83cd8ea | |
parent | 15c716da6c690b7b8dcb90d9eec13a449dfc0e05 (diff) | |
download | lua-language-server-6ebd54af6221f0e65d4436c9d071d4e5878297fa.zip |
test: add test case for reversed binary operators
-rw-r--r-- | test/type_inference/common.lua | 236 |
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 +]] |