1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- -module(dispatcher_prop).
- -include_lib("proper/include/proper.hrl").
- hostname_head_char() ->
- oneof([choose($a, $z), choose($A, $Z), choose($0, $9)]).
- hostname_char() ->
- oneof([choose($a, $z), choose($A, $Z), choose($0, $9), $-]).
- hostname_label() ->
- ?SUCHTHAT(Label, [hostname_head_char()|list(hostname_char())],
- length(Label) < 64).
- hostname() ->
- ?SUCHTHAT(Hostname,
- ?LET(Labels, list(hostname_label()), string:join(Labels, ".")),
- length(Hostname) > 0 andalso length(Hostname) =< 255).
- port_number() ->
- choose(1, 16#ffff).
- port_str() ->
- oneof(["", ?LET(Port, port_number(), ":" ++ integer_to_list(Port))]).
- server() ->
- ?LET({Hostname, PortStr}, {hostname(), port_str()},
- list_to_binary(Hostname ++ PortStr)).
- prop_split_host_symmetric() ->
- ?FORALL(Server, server(),
- begin case cowboy_dispatcher:split_host(Server) of
- {Tokens, RawHost, undefined} ->
- (Server == RawHost) and (Server == binary_join(Tokens, "."));
- {Tokens, RawHost, Port} ->
- PortBin = (list_to_binary(":" ++ integer_to_list(Port))),
- (Server == << RawHost/binary, PortBin/binary >>)
- and (Server == << (binary_join(Tokens, "."))/binary,
- PortBin/binary >>)
- end end).
- binary_join(Flowers, Leaf) ->
- case Flowers of
- [] -> <<>>;
- [Petal|Pot] -> iolist_to_binary(
- [Petal | [[Leaf | Pollen] || Pollen <- Pot]])
- end.
|