diff options
Diffstat (limited to 'testes/api.lua')
| -rw-r--r-- | testes/api.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/testes/api.lua b/testes/api.lua index 5da03641..0966ed19 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
| @@ -241,6 +241,23 @@ assert(a == 20 and b == false) | |||
| 241 | a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a1, 2, 20) | 241 | a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a1, 2, 20) |
| 242 | assert(a == 20 and b == true) | 242 | assert(a == 20 and b == true) |
| 243 | 243 | ||
| 244 | |||
| 245 | do -- testing lessthan and lessequal with metamethods | ||
| 246 | local mt = {__lt = function (a,b) return a[1] < b[1] end, | ||
| 247 | __le = function (a,b) return a[1] <= b[1] end, | ||
| 248 | __eq = function (a,b) return a[1] == b[1] end} | ||
| 249 | local function O (x) | ||
| 250 | return setmetatable({x}, mt) | ||
| 251 | end | ||
| 252 | |||
| 253 | local a, b = T.testC("compare LT 2 3; pushint 10; return 2", O(1), O(2)) | ||
| 254 | assert(a == true and b == 10) | ||
| 255 | local a, b = T.testC("compare LE 2 3; pushint 10; return 2", O(3), O(2)) | ||
| 256 | assert(a == false and b == 10) | ||
| 257 | local a, b = T.testC("compare EQ 2 3; pushint 10; return 2", O(3), O(3)) | ||
| 258 | assert(a == true and b == 10) | ||
| 259 | end | ||
| 260 | |||
| 244 | -- testing length | 261 | -- testing length |
| 245 | local t = setmetatable({x = 20}, {__len = function (t) return t.x end}) | 262 | local t = setmetatable({x = 20}, {__len = function (t) return t.x end}) |
| 246 | a,b,c = T.testC([[ | 263 | a,b,c = T.testC([[ |
