diff options
author | Jonas Gehring <jgehring@fb.com> | 2016-03-17 03:15:06 +0300 |
---|---|---|
committer | Jonas Gehring <jgehring@fb.com> | 2016-03-17 03:15:11 +0300 |
commit | 89217bf5c232302ef772a01c6e5ce0cc5de2cea8 (patch) | |
tree | 2f03017f45da65ff26a5d437910f446cd14dbb49 /test | |
parent | 13361c47c850474a90c759247147cbc3575fef7c (diff) |
Revert to pattern matching in isTypeOf()
This reverts the "enclosed" class matching introduced in 9c75e57, which
broke matching against patterns. In contrast to the original implementation,
non-pattern strings are always matched fully against type names to minimize
surprises caused by e.g. common prefix.
Diffstat (limited to 'test')
-rw-r--r-- | test/test.lua | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/test/test.lua b/test/test.lua index 5536e3d..c1457bb 100644 --- a/test/test.lua +++ b/test/test.lua @@ -2881,21 +2881,22 @@ function torchtest.isTypeOfPartial() 'isTypeOf error: inheritance') end -function torchtest.isTypeOfComposite() - do - local Enclosed = torch.class('Enclosed') - rawset(_G, 'Enclosing', {}) - local Enclosing_Enclosed = torch.class('Enclosing.Enclosed') - end - local enclosed = Enclosed() - local enclosing_enclosed = Enclosing.Enclosed() - - mytester:assert(not torch.isTypeOf(enclosed, Enclosing.Enclosed), - 'isTypeOf error: incorrect composite match') - mytester:assert(not torch.isTypeOf(enclosed, 'Enclosing.Enclosed'), - 'isTypeOf error: incorrect composite match') - mytester:assert(torch.isTypeOf(enclosing_enclosed, 'Enclosed'), - 'isTypeOf error: incorrect composite match') +function torchtest.isTypeOfPattern() + local t = torch.LongTensor() + mytester:assert(torch.isTypeOf(t, torch.LongTensor), + 'isTypeOf error: incorrect match') + mytester:assert(not torch.isTypeOf(t, torch.IntTensor), + 'isTypeOf error: incorrect match') + mytester:assert(torch.isTypeOf(t, 'torch.LongTensor'), + 'isTypeOf error: incorrect match') + mytester:assert(not torch.isTypeOf(t, 'torch.Long'), + 'isTypeOf error: incorrect match') + mytester:assert(torch.isTypeOf(t, 'torch.*Tensor'), + 'isTypeOf error: incorrect match') + mytester:assert(torch.isTypeOf(t, '.*Long'), + 'isTypeOf error: incorrect match') + mytester:assert(not torch.isTypeOf(t, 'torch.IntTensor'), + 'isTypeOf error: incorrect match') end function torchtest.isTensor() |