File: mochiweb_base64url_tests.erl

package info (click to toggle)
rabbitmq-server 3.3.5-1.1
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 12,004 kB
  • sloc: erlang: 78,203; python: 3,187; xml: 2,843; makefile: 903; sh: 831; java: 660; perl: 64; ruby: 63
file content (27 lines) | stat: -rw-r--r-- 687 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-module(mochiweb_base64url_tests).
-include_lib("eunit/include/eunit.hrl").

id(X) ->
    ?assertEqual(
       X,
       mochiweb_base64url:decode(mochiweb_base64url:encode(X))),
    ?assertEqual(
       X,
       mochiweb_base64url:decode(
         binary_to_list(mochiweb_base64url:encode(binary_to_list(X))))).

random_binary(Short,Long) ->
    << <<(random:uniform(256) - 1)>>
     || _ <- lists:seq(1, Short + random:uniform(1 + Long - Short) - 1) >>.

empty_test() ->
    id(<<>>).

onechar_test() ->
    [id(<<C>>) || C <- lists:seq(0,255)],
    ok.

nchar_test() ->
    %% 1000 tests of 2-6 char strings
    [id(B) || _ <- lists:seq(1,1000), B <- [random_binary(2, 6)]],
    ok.