diff options
Diffstat (limited to 'test/references')
-rw-r--r-- | test/references/all.lua | 135 | ||||
-rw-r--r-- | test/references/init.lua | 136 |
2 files changed, 135 insertions, 136 deletions
diff --git a/test/references/all.lua b/test/references/all.lua index c27beb3c..a9442ae1 100644 --- a/test/references/all.lua +++ b/test/references/all.lua @@ -76,3 +76,138 @@ local function f() end local a, b = f() return a.x, b.<!x!> ]] + +TEST [[ +local <?mt?> = {} +function <!mt!>:x() + <!self!>:x() +end +]] + +TEST [[ +local mt = {} +function mt:<?x?>() + self:<!x!>() +end +]] + +TEST [[ +---@class Dog +local mt = {} +function mt:<?eat?>() +end + +---@class Master +local mt2 = {} +function mt2:init() + ---@type Dog + local foo = self:doSomething() + ---@type Dog + self.dog = getDog() +end +function mt2:feed() + self.dog:<!eat!>() +end +function mt2:doSomething() +end +]] + +-- 泛型的反向搜索 +TEST [[ +---@class Dog +local <?Dog?> = {} + +---@generic T +---@param type1 T +---@return T +function foobar(type1) +end + +local <!v1!> = foobar(<!Dog!>) +]] + +TEST [[ +---@class Dog +local Dog = {} +function Dog:<?eat?>() +end + +---@generic T +---@param type1 T +---@return T +function foobar(type1) + return {} +end + +local v1 = foobar(Dog) +v1:<!eat!>() +]] + +TEST [[ +---@class Dog +local Dog = {} +function Dog:<?eat?>() +end + +---@class Master +local Master = {} + +---@generic T +---@param type1 string +---@param type2 T +---@return T +function Master:foobar(type1, type2) + return {} +end + +local v1 = Master:foobar("", Dog) +v1.<!eat!>() +]] + +TEST [[ +---@class A +local <?A?> + +---@generic T +---@param self T +---@return T +function m.f(self) end + +local <!b!> = m.f(<!A!>) +]] + +TEST [[ +---@class A +local <?A?> + +---@generic T +---@param self T +---@return T +function m:f() end + +local <!b!> = m.f(<!A!>) +]] + +TEST [[ +---@class A +local <?A?> + +---@generic T +---@param self T +---@return T +function <!A!>.f(self) end + +local <!b!> = <!A!>:f() +]] + +TEST [[ +---@class A +local <?A?> + +---@generic T +---@param self T +---@return T +function <!A!>:f() end + +local <!b!> = <!A!>:f() +]] diff --git a/test/references/init.lua b/test/references/init.lua index e6abc3bd..e90cb2a8 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -218,13 +218,6 @@ end ]] TEST [[ -local <?mt?> = {} -function <!mt!>:x() - <!self!>:x() -end -]] - -TEST [[ local mt = {} function mt:<!x!>() self:<?x?>() @@ -232,13 +225,6 @@ end ]] TEST [[ -local mt = {} -function mt:<?x?>() - self:<!x!>() -end -]] - -TEST [[ a.<!b!>.c = 1 print(a.<?b?>.c) ]] @@ -312,125 +298,3 @@ TEST [[ ---@return <?xxx?> function f() end ]] - -TEST [[ ----@class Dog -local mt = {} -function mt:<?eat?>() -end - ----@class Master -local mt2 = {} -function mt2:init() - ---@type Dog - local foo = self:doSomething() - ---@type Dog - self.dog = getDog() -end -function mt2:feed() - self.dog:<!eat!>() -end -function mt2:doSomething() -end -]] - --- TODO 支持泛型 -do return end -TEST [[ ----@class Dog -local <?Dog?> = {} - ----@generic T ----@param type1 T ----@return T -function foobar(type1) -end - -local <!v1!> = foobar(<!Dog!>) -]] - -TEST [[ ----@class Dog -local Dog = {} -function Dog:<?eat?>() -end - ----@generic T ----@param type1 T ----@return T -function foobar(type1) - return {} -end - -local v1 = foobar(Dog) -v1:<!eat!>() -]] - -TEST [[ ----@class Dog -local Dog = {} -function Dog:<?eat?>() -end - ----@class Master -local Master = {} - ----@generic T ----@param type1 string ----@param type2 T ----@return T -function Master:foobar(type1, type2) - return {} -end - -local v1 = Master:foobar("", Dog) -v1.<!eat!>() -]] - -TEST [[ ----@class A -local <?A?> - ----@generic T ----@param self T ----@return T -function m.f(self) end - -local <!b!> = m.f(<!A!>) -]] - -TEST [[ ----@class A -local <?A?> - ----@generic T ----@param self T ----@return T -function m:f() end - -local <!b!> = m.f(<!A!>) -]] - -TEST [[ ----@class A -local <?A?> - ----@generic T ----@param self T ----@return T -function <!A!>.f(self) end - -local <!b!> = <!A!>:f() -]] - -TEST [[ ----@class A -local <?A?> - ----@generic T ----@param self T ----@return T -function <!A!>:f() end - -local <!b!> = <!A!>:f() -]] |