couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] chttpd commit: updated refs/heads/master to 2fba00d
Date Fri, 28 Aug 2015 12:57:22 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master a49c47417 -> 2fba00db0


Fix 'override' and 'override default' functionality

COUCHDB-2788


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/e6fa441b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/e6fa441b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/e6fa441b

Branch: refs/heads/master
Commit: e6fa441b1c8bc6b51e4c3fb5e3cc6855ee8914cf
Parents: 4de16f8
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Mon Aug 24 17:04:51 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed Aug 26 06:04:36 2015 -0700

----------------------------------------------------------------------
 src/chttpd_handlers.erl | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/e6fa441b/src/chttpd_handlers.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_handlers.erl b/src/chttpd_handlers.erl
index e21986b..85f8318 100644
--- a/src/chttpd_handlers.erl
+++ b/src/chttpd_handlers.erl
@@ -55,11 +55,35 @@ select([], Default) ->
 select([{default, OverrideDefault}], _Default) ->
     OverrideDefault;
 select(Handlers, _Default) ->
-    select(Handlers).
-
-select([Handler]) ->
-    Handler;
-select([{override, Handler}|_]) ->
-    Handler;
-select([_Handler | Rest]) ->
-    select(Rest).
+    [Handler] = do_select(Handlers, []),
+    Handler.
+
+do_select([], Acc) ->
+    Acc;
+do_select([{override, Handler}|_], _Acc) ->
+    [Handler];
+do_select([{default, _}|Rest], Acc) ->
+    do_select(Rest, Acc);
+do_select([Handler], Acc) ->
+    [Handler | Acc];
+do_select([Handler | Rest], Acc) ->
+    do_select(Rest, [Handler | Acc]).
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+select_override_test() ->
+    ?assertEqual(selected, select([{override, selected}, foo], default)),
+    ?assertEqual(selected, select([foo, {override, selected}], default)),
+    ?assertEqual(selected, select([{override, selected}, {override, bar}], default)),
+    ?assertError({badmatch,[bar, foo]}, select([foo, bar], default)).
+
+select_default_override_test() ->
+    ?assertEqual(selected, select([{default, new_default}, selected], old_default)),
+    ?assertEqual(selected, select([selected, {default, new_default}], old_default)),
+    ?assertEqual(selected, select([{default, selected}], old_default)),
+    ?assertEqual(selected, select([], selected)),
+    ?assertEqual(selected,
+        select([{default, new_default}, {override, selected}, bar], old_default)).
+
+-endif.


Mime
View raw message