Mercurial > repos > public > sbplib
changeset 951:a6c5e73ff44e
Better errors in Map()
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 07 Dec 2018 16:10:58 +0100 |
parents | 306f5b3cd7bc |
children | 2c5b9cfc3f25 92c3c170e90b |
files | Map.m MapTest.m |
diffstat | 2 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Map.m Sat Nov 24 14:55:48 2018 +0000 +++ b/Map.m Fri Dec 07 16:10:58 2018 +0100 @@ -59,6 +59,9 @@ function v = subsref(obj, S) switch S(1).type case '()' + if length(S.subs) > 1 + error('sbplib:Map:multipleKeys', 'Multiple dimensions are not supported. Use a cell array as a key instead.'); + end k = S.subs{1}; try v = get(obj, k); @@ -81,6 +84,9 @@ function obj = subsasgn(obj, S, v); switch S(1).type case '()' + if length(S.subs) > 1 + error('sbplib:Map:multipleKeys', 'Multiple dimensions are not supported. Use a cell array as a key instead.'); + end k = S.subs{1}; set(obj, k, v); otherwise
--- a/MapTest.m Sat Nov 24 14:55:48 2018 +0000 +++ b/MapTest.m Fri Dec 07 16:10:58 2018 +0100 @@ -12,6 +12,21 @@ }; end +function testMultiKey(testCase) + map = Map + + function setMultiKey() + map(1,2) = 1; + end + + function getMultiKey() + v = map(1,2); + end + + testCase.verifyError(@setMultiKey,'sbplib:Map:multipleKeys') + testCase.verifyError(@getMultiKey,'sbplib:Map:multipleKeys') +end + function testSetAndGet(testCase) keyValuePairs = getKeyValuePairs();