Jacob Perkins avatar Jacob Perkins committed de08552

more list compatibility tests, works with JSON strings

Comments (0)

Files changed (2)

src/erldis_dict.erl

 update_counter(Key, Client) -> update_counter(Key, 1, Client).
 
 % NOTE: this returns new count value, not a modified dict
-update_counter(Key, 1, Client) ->
-	erldis:incr(Client, Key);
-update_counter(Key, Incr, Client) ->
-	erldis:incrby(Client, Key, Incr).
+update_counter(Key, 1, Client) -> erldis:incr(Client, Key);
+update_counter(Key, Incr, Client) -> erldis:incrby(Client, Key, Incr).

test/erldis_list_compatibility_tests.erl

 	?assertEqual(erldis:decrby(Client, <<"foo">>, 2), 3),
 	?assertEqual(erldis:decrby(Client, "foo", 3), 0).
 
+list_test() ->
+	Client = setup(),
+	?assertEqual(erldis:exists(Client, "foo"), false),
+	?assertEqual(erldis:lpush(Client, "foo", "a"), ok),
+	?assertEqual(erldis:rpush(Client, "foo", "b"), ok),
+	?assertEqual(erldis:lindex(Client, "foo", 0), <<"a">>),
+	?assertEqual(erldis:lindex(Client, "foo", 1), <<"b">>),
+	?assertEqual(erldis:llen(Client, "foo"), 2),
+	?assertEqual(erldis_list:is_list("foo", Client), true).
+
+set_test() ->
+	Client = setup(),
+	?assertEqual(erldis:exists(Client, "foo"), false),
+	?assertEqual(erldis:sadd(Client, "foo", "bar"), true),
+	?assertEqual(erldis:scard(Client, "foo"), 1),
+	?assertEqual(erldis:smembers(Client, "foo"), [<<"bar">>]),
+	?assertEqual(erldis:sismember(Client, "foo", "bar"), true),
+	?assertEqual(erldis_sets:is_set(Client, "foo"), true).
+
+json_test() ->
+	% requires yaws json module
+	Arr = {array, ["a", "b", "c"]},
+	Json = json:encode(Arr),
+	Client = setup(),
+	?assertEqual(erldis:set(Client, "json", Json), ok),
+	GetJson = erldis:get(Client, "json"),
+	?assertEqual(GetJson, list_to_binary(Json)),
+	{ok, Arr2} = json:decode_string(binary_to_list(GetJson)),
+	?assertEqual(Arr, Arr2).
+
 setup() ->
 	% setup
 	application:load(erldis),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.