From 6ebd54af6221f0e65d4436c9d071d4e5878297fa Mon Sep 17 00:00:00 2001 From: SeanTheBuilder1 Date: Sat, 3 Aug 2024 14:27:37 +0800 Subject: test: add test case for reversed binary operators --- test/type_inference/common.lua | 236 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) (limited to 'test/type_inference') 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 ]] + +--reverse binary operator tests + +TEST 'A' [[ +---@class A +---@operator add(number): A + +---@type A +local x +local = x + 1 +]] + +TEST 'A' [[ +---@class A +---@operator add(number): A + +---@type A +local x +local = 1 + x +]] + +TEST 'A' [[ +---@class A +---@operator sub(number): A + +---@type A +local x +local = x - 1 +]] + +TEST 'A' [[ +---@class A +---@operator sub(number): A + +---@type A +local x +local = 1 - x +]] + +TEST 'A' [[ +---@class A +---@operator mul(number): A + +---@type A +local x +local = x * 1 +]] + +TEST 'A' [[ +---@class A +---@operator mul(number): A + +---@type A +local x +local = 1 * x +]] + +TEST 'A' [[ +---@class A +---@operator div(number): A + +---@type A +local x +local = x / 1 +]] + +TEST 'A' [[ +---@class A +---@operator div(number): A + +---@type A +local x +local = 1 / x +]] + +TEST 'A' [[ +---@class A +---@operator idiv(number): A + +---@type A +local x +local = x // 1 +]] + +TEST 'A' [[ +---@class A +---@operator idiv(number): A + +---@type A +local x +local = 1 // x +]] + +TEST 'A' [[ +---@class A +---@operator mod(number): A + +---@type A +local x +local = x % 1 +]] + +TEST 'A' [[ +---@class A +---@operator mod(number): A + +---@type A +local x +local = 1 % x +]] + +TEST 'A' [[ +---@class A +---@operator pow(number): A + +---@type A +local x +local = x ^ 1 +]] + +TEST 'A' [[ +---@class A +---@operator pow(number): A + +---@type A +local x +local = 1 ^ x +]] + +TEST 'A' [[ +---@class A +---@operator concat(number): A + +---@type A +local x +local = x .. 1 +]] + +TEST 'A' [[ +---@class A +---@operator concat(number): A + +---@type A +local x +local = 1 .. x +]] + +TEST 'A' [[ +---@class A +---@operator band(number): A + +---@type A +local x +local = x & 1 +]] + +TEST 'A' [[ +---@class A +---@operator band(number): A + +---@type A +local x +local = 1 & x +]] + +TEST 'A' [[ +---@class A +---@operator bor(number): A + +---@type A +local x +local = x | 1 +]] + +TEST 'A' [[ +---@class A +---@operator bor(number): A + +---@type A +local x +local = 1 | x +]] + +TEST 'A' [[ +---@class A +---@operator bxor(number): A + +---@type A +local x +local = x ~ 1 +]] + +TEST 'A' [[ +---@class A +---@operator bxor(number): A + +---@type A +local x +local = 1 ~ x +]] + +TEST 'A' [[ +---@class A +---@operator shl(number): A + +---@type A +local x +local = x << 1 +]] + +TEST 'A' [[ +---@class A +---@operator shl(number): A + +---@type A +local x +local = 1 << x +]] + +TEST 'A' [[ +---@class A +---@operator shr(number): A + +---@type A +local x +local = x >> 1 +]] + +TEST 'A' [[ +---@class A +---@operator shr(number): A + +---@type A +local x +local = 1 >> x +]] -- cgit v1.2.3