Skip to content

Commit 3669837

Browse files
author
Fernando Alvarruiz
committed
Allow empty char arrays as Map keys (bug #67255).
* Map.m (Map): remove check for empty keys. * Map.m: Add test for empty key. Change error message of existing test using empty key.
1 parent 172b5ad commit 3669837

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/+containers/Map.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@
118118
&& strcmpi (varargin{3}, "UniformValues")))
119119
## Get Map keys
120120
keys = varargin{1};
121-
if (isempty (keys))
122-
error ("containers.Map: empty keys are not allowed");
123-
endif
124121
if (! iscell (keys))
125122
if (isnumeric (keys) || islogical (keys))
126123
keys = num2cell (keys);
@@ -650,6 +647,11 @@ function check_types (this)
650647
%! assert (numel (k), 6);
651648
%! assert (m.isKey({"One", "Four"; "Ten", "Five"}), [true,false; false,true]);
652649
650+
## Test empty char array as key
651+
%!test <*67255>
652+
%! m = containers.Map ('', 3);
653+
%! assert (m(''), 3);
654+
653655
## Test numeric keys
654656
%!test
655657
%! key = [1, 2, 3, 4];
@@ -880,7 +882,7 @@ function check_types (this)
880882
## Test input validation
881883
%!error containers.Map (1,2,3)
882884
%!error containers.Map (1,2,3,4,5)
883-
%!error <empty keys are not allowed> containers.Map ([], 1)
885+
%!error <the number of keys and values must match> containers.Map ([], 1)
884886
%!error <number of keys and values must match> containers.Map (1, {2, 3})
885887
%!error <keys must be real .* values> containers.Map ({{1}}, 2)
886888
%!error <keys must be .* scalar .* values> containers.Map ({magic(3)}, 2)

0 commit comments

Comments
 (0)