|
| 1 | +local utils = require('utils') |
| 2 | + |
| 3 | +local cases = { |
| 4 | + {typename = 'nil', value = 'nil'}, |
| 5 | + {typename = 'boolean', value = 'true'}, |
| 6 | + {typename = 'number', value = '42'}, |
| 7 | + -- FIXME: This test case is disabled, because __tostring |
| 8 | + -- metamethod isn't checked for string base metatable. |
| 9 | + -- See also https://github.com/tarantool/tarantool/issues/6746. |
| 10 | + -- {'string', '"teststr"'}, |
| 11 | + {typename = 'table', value = '{}'}, |
| 12 | + {typename = 'function', value = 'function() end'}, |
| 13 | + {typename = 'userdata', value = 'newproxy()'}, |
| 14 | + {typename = 'thread', value = 'coroutine.create(function() end)'}, |
| 15 | + {typename = 'cdata', value = '1ULL'} |
| 16 | +} |
| 17 | + |
| 18 | +local checks = {} |
| 19 | + |
| 20 | +for i, case in pairs(cases) do |
| 21 | + checks[i] = { |
| 22 | + arg = {('"%s"'):format(case.value), case.typename}, |
| 23 | + msg = ('%s'):format(case.typename), |
| 24 | + res = ('__tostring is reloaded for %s'):format(case.typename), |
| 25 | + test = 'is', |
| 26 | + } |
| 27 | +end |
| 28 | + |
| 29 | +utils.selfrun(arg, checks) |
| 30 | + |
| 31 | +----- Test payload. ---------------------------------------------- |
| 32 | + |
| 33 | +local test = [[ |
| 34 | + local testvar = %s |
| 35 | + debug.setmetatable(testvar, {__tostring = function(o) |
| 36 | + return ('__tostring is reloaded for %s'):format(type(o)) |
| 37 | + end}) |
| 38 | + print(testvar) |
| 39 | +]] |
| 40 | + |
| 41 | +pcall(load(test:format(unpack(arg)))) |
0 commit comments