aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2017-05-03 18:22:45 +0200
committerSverker Eriksson <[email protected]>2017-05-10 11:38:42 +0200
commit95dec7497abbdb06defcb23e99fa31e06597496e (patch)
tree202e04472d05dcbd326fcd1616a3d919b7b16f02 /lib/stdlib/test
parentffa80a41370025ed2fb95967e731f13cc7e45e4f (diff)
downloadotp-95dec7497abbdb06defcb23e99fa31e06597496e.tar.gz
otp-95dec7497abbdb06defcb23e99fa31e06597496e.tar.bz2
otp-95dec7497abbdb06defcb23e99fa31e06597496e.zip
erts: Fix ets:select_replace with {const, NewTuple}
Enable ets:select_replace to do a generic single object compare-and-swap operation of any ets-tuple using a matchspec like this: [{Old, [], [{const, New}]}] The only exception when this does not work is if the key contains maps or atoms looking like variables (like '$1').
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r--lib/stdlib/test/ets_SUITE.erl20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl
index 2dfd481665..13a3f99e7e 100644
--- a/lib/stdlib/test/ets_SUITE.erl
+++ b/lib/stdlib/test/ets_SUITE.erl
@@ -1349,6 +1349,26 @@ t_select_replace(Config) when is_list(Config) ->
NeqPairs(X,Y)) || X <- Terms, Y <- Terms],
+ %% Wrap entire tuple with 'const'
+ [[begin
+ Old = {Key, 1, 2},
+ ets:insert(T2, Old),
+ 1 = ets:select_replace(T2, [{Old, [], [{const, New}]}]),
+ [New] = ets:lookup(T2, Key),
+ ets:delete(T2, Key)
+ end || New <- [{Key, 1, 2}, {Key, 3, 4}, {Key, 1}, {Key, 1, 2, 3}, {Key}]
+ ]
+ || Key <- [{1, tuple}, {nested, {tuple, {a,b}}} | Terms]],
+
+ %% 'const' wrap does not work with maps or variables in keys
+ [[begin
+ Old = {Key, 1, 2},
+ {'EXIT',{badarg,_}} = (catch ets:select_replace(T2, [{Old, [], [{const, New}]}]))
+ end || New <- [{Key, 1, 2}, {Key, 3, 4}, {Key, 1}, {Key, 1, 2, 3}, {Key}]
+ ]
+ || Key <- [#{a => 1}, {nested, #{a => 1}}, '$1']],
+
+
ets:delete(T2),
verify_etsmem(EtsMem).