-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
153 additions
and
12 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,59 @@ | ||
local util = require("spec.util") | ||
|
||
describe("Is<T>:", function() | ||
|
||
it("is_ function", util.check [[ | ||
local record Is<T> end | ||
local record MyRecord | ||
a: number | ||
end | ||
local record OtherRecord | ||
a: boolean | ||
end | ||
local r : MyRecord | OtherRecord = { a = 1 } | ||
local n : number | ||
local function is_myrecord(x: any): Is<MyRecord> | ||
if x is table then | ||
local a = x.a | ||
return (a is number) | ||
else return false end | ||
end | ||
if is_myrecord(r) then | ||
n = r.a | ||
end | ||
]]) | ||
|
||
it("is_ method", util.check [[ | ||
local record Is<T> end | ||
local record A | ||
is_b : function(self : A | B) : Is<B> | ||
end | ||
local record B | ||
is_b : function(self : A | B) : Is<B> | ||
b_field : string | ||
end | ||
local b1 : B = { | ||
is_b = function(self : A | B) : Is<B> | ||
-- In a real program this would actually do something | ||
return true | ||
end, | ||
b_field = "yes", | ||
} | ||
local ab : A | B = b1 | ||
if ab:is_b() then | ||
local b2 : B = ab | ||
local s : string = b2.b_field | ||
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