Browse Source

key/fs tests

tonpa 4 years ago
parent
commit
ff4eb8228d
2 changed files with 16 additions and 2 deletions
  1. 6 2
      src/stores/kvs_rocks.erl
  2. 10 0
      test/fd_test.exs

+ 6 - 2
src/stores/kvs_rocks.erl

@@ -19,15 +19,19 @@ tb(T)      -> term_to_binary(T).
 fmt([]) -> [];
 fmt(K) -> tb(K).
 
+% put
+
 key(R)     when is_tuple(R) andalso tuple_size(R) > 1 -> key(e(1,R), e(2,R));
 key(R)     -> key(R,[]).
 key(Tab,R) when is_tuple(R) andalso tuple_size(R) > 1 -> key(Tab, e(2,R));
 key(Tab,R) -> iolist_to_binary([lists:join(<<"/">>, lists:flatten([<<>>, fmt(Tab), fmt(R)]))]).
 
+% get
+
 fd(Key) ->
-  B = lists:reverse(binary:split(tb(Key), [<<"/">>], [global, trim_all])),
+  B = lists:reverse(binary:split(tb(Key), [<<"/">>], [global])),
   B1 = lists:reverse(case B of [] -> [];[X] -> [X];[_|T] -> T end),
-  iolist_to_binary(lists:join(<<"/">>, [<<>>]++B1)).
+  iolist_to_binary(lists:join(<<"/">>, B1)).
 
 o(<<>>,FK,_,_) -> {ok,FK,[],[]};
 o(Key,FK,Dir,Fx) ->

+ 10 - 0
test/fd_test.exs

@@ -5,6 +5,16 @@ defmodule Fd.Test do
     require KVS
     import Record
 
+    test "fd_test", kvs do
+       assert "//erp" = :kvs_rocks.fd "//erp/orgs"
+       assert "/erp" = :kvs_rocks.fd "/erp/orgs"
+    end
+
+    test "key_test", kvs do
+       assert "//erp/orgs" = :kvs_rocks.key "/erp/orgs"
+       assert "/erp/orgs"  = :kvs_rocks.key "erp/orgs"
+    end
+
     defrecord(:msg, id: [], body: [])
 
     setup do: (on_exit(fn -> :ok = :kvs.leave();:ok = :kvs.destroy() end);:kvs.join())