Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 71 lines (55 sloc) 2.199 kb
26e79be @vinoski allow functions to be specified as values in ehtml
vinoski authored
1 -module(ehtml_test).
2
3 -include_lib("eunit/include/eunit.hrl").
4
5 -export([mfa_fun/1, nested_mfa_fun/1, nested_mfa_attr_fun/1]).
6
7 get_title() ->
8 "Funtest Title".
9
10 simple_fun_test() ->
11 {ehtml, E} = {ehtml, [{title, [], fun get_title/0}]},
12 Title = "\n<title>" ++ get_title() ++ "</title>",
13 Title = lists:flatten(yaws_api:ehtml_expand(E)).
14
15 mfa_fun(Args) ->
16 Args.
17
18 mfa_test() ->
19 Args = ["another ", "string"],
20 {ehtml, E} = {ehtml, [{p, [], {?MODULE, mfa_fun, Args}}]},
21 P = lists:flatten(["\n<p>", Args, "</p>"]),
22 P = lists:flatten(yaws_api:ehtml_expand(E)).
23
24 nested_fun_test() ->
25 Value = "paragraph",
26 {ehtml, E} = {ehtml, [fun() -> [{p, [], Value}] end]},
27 P = lists:flatten(["\n<p>", Value, "</p>"]),
28 P = lists:flatten(yaws_api:ehtml_expand(E)).
29
30 nested_mfa_fun(Args) ->
31 fun() -> [{p, [], fun() -> Args end}] end.
32
33 nested_mfa_test() ->
34 Args = ["another ", "string"],
35 {ehtml, E} = {ehtml, [{?MODULE, nested_mfa_fun, Args}]},
36 P = lists:flatten(["\n<p>", Args, "</p>"]),
37 P = lists:flatten(yaws_api:ehtml_expand(E)).
38
39 get_link() ->
40 "http://yaws.hyber.org/".
41
42 simple_attr_test() ->
43 Link = "link",
44 {ehtml, E} = {ehtml, [{a, [{href, fun get_link/0}], Link}]},
45 A = lists:flatten(["<a href=\"", get_link(), "\">", Link, "</a>"]),
46 A = lists:flatten(yaws_api:ehtml_expand(E)).
47
48 mfa_attr_test() ->
49 Args = [get_link()],
50 Link = "link",
51 {ehtml, E} = {ehtml, [{a, [{href, {?MODULE, mfa_fun, Args}}], Link}]},
52 A = lists:flatten(["<a href=\"", Args, "\">", Link, "</a>"]),
53 A = lists:flatten(yaws_api:ehtml_expand(E)).
54
55 nested_attr_test() ->
56 Link = "link",
57 {ehtml, E} = {ehtml, [{a, [{href, fun() -> fun get_link/0 end}], Link}]},
58 A = lists:flatten(["<a href=\"", get_link(), "\">", Link, "</a>"]),
59 A = lists:flatten(yaws_api:ehtml_expand(E)).
60
61 nested_mfa_attr_fun(Args) ->
62 {?MODULE, mfa_fun, Args}.
63
64 nested_mfa_attr_test() ->
65 Args = [get_link()],
66 Link = "link",
67 {ehtml, E} = {ehtml,
68 [{a, [{href, {?MODULE, nested_mfa_attr_fun, Args}}], Link}]},
69 A = lists:flatten(["<a href=\"", Args, "\">", Link, "</a>"]),
70 A = lists:flatten(yaws_api:ehtml_expand(E)).
Something went wrong with that request. Please try again.