diff --git a/rebar.lock b/rebar.lock new file mode 100644 index 0000000..57afcca --- /dev/null +++ b/rebar.lock @@ -0,0 +1 @@ +[]. diff --git a/src/erml_generator.erl b/src/erml_serializer.erl similarity index 99% rename from src/erml_generator.erl rename to src/erml_serializer.erl index cc8df39..4a06b24 100644 --- a/src/erml_generator.erl +++ b/src/erml_serializer.erl @@ -2,7 +2,7 @@ %%% @doc draft. %%% @end %%%=================================================================== --module(erml_generator). +-module(erml_serializer). -export([compile/3, compile/4]). -export([flatten/2]). diff --git a/src/erml_html_tag.erl b/src/erml_tag.erl similarity index 99% rename from src/erml_html_tag.erl rename to src/erml_tag.erl index 1e0200c..0cfd0ba 100644 --- a/src/erml_html_tag.erl +++ b/src/erml_tag.erl @@ -77,7 +77,7 @@ %%% %%% @end %%%=================================================================== --module(erml_html_tag). +-module(erml_tag). -export([create/1, create/2]). -export([init/1]). -export([tag/3]). @@ -97,7 +97,7 @@ %% %%-------------------------------------------------------------------- create(Data) -> create(Data, #{}). -create(Data, Opts) -> erml_generator:compile(?MODULE, Opts, Data). +create(Data, Opts) -> erml_serializer:compile(?MODULE, Opts, Data). %%-------------------------------------------------------------------- %% diff --git a/test/erml_SUITE.erl b/test/erml_SUITE.erl index b295c7c..49aedb0 100644 --- a/test/erml_SUITE.erl +++ b/test/erml_SUITE.erl @@ -99,14 +99,14 @@ groups() -> %% @end %%-------------------------------------------------------------------- all() -> - [my_test_case]. + [tag]. %%-------------------------------------------------------------------- %% @spec TestCase() -> Info %% Info = [tuple()] %% @end %%-------------------------------------------------------------------- -my_test_case() -> +tag() -> []. %%-------------------------------------------------------------------- @@ -118,5 +118,89 @@ my_test_case() -> %% Comment = term() %% @end %%-------------------------------------------------------------------- -my_test_case(_Config) -> +tag(_Config) -> + % empty document + {ok, <<>>} = erml_tag:create([]), + {ok, <<>>} = erml_tag:create(<<>>), + + % simple tag without attributes + {ok, <<"">>} = erml_tag:create({html, []}), + {ok, <<"">>} = erml_tag:create({<<"html">>, []}), + {ok, <<"">>} = erml_tag:create({"html", []}), + {ok, <<"
">>} + = erml_tag:create({html, {body, []}}), + + % simple tag with attributes + {ok, <<"">>} = erml_tag:create({html, #{}, []}), + {ok, <<"">>} = erml_tag:create({<<"html">>, #{}, []}), + {ok, <<"">>} = erml_tag:create({"html", #{}, []}), + {ok, <<"">>} + = erml_tag:create({html, #{}, {body, #{}, []}}), + + % simple tag with attributes support. + {ok, <<"">>} + = erml_tag:create({html, #{}, {body, #{class => "test"}, []}}), + {ok, <<"">>} + = erml_tag:create({html, #{}, {body, #{class => test}, []}}), + {ok, <<"">>} + = erml_tag:create({html, #{}, {body, #{class => <<"test">>}, []}}), + + % content and entities support + {ok, <<"test">>} + = erml_tag:create({html, {body, <<"test">>}}), + {ok, <<"test">>} + = erml_tag:create({html, {body, test}}), + {ok, <<"123">>} + = erml_tag:create({html, {body, 123}}), + {ok, <<"1.00000000000000000000e+00">>} + = erml_tag:create({html, {body, 1.0}}), + {ok, <<"that's a test!
">>} + = erml_tag:create([{html, {body, {p, [<<"that's a test!">>]}}}]), + + % dynamic template (gen_server call by default) + {ok, [ <<"">> + , {gen_server,call,server,paragraph,1000} + , <<"">> + ] + } = erml_tag:create({html, {body, {call, server, paragraph}}}), + + % dynamic template (gen_server call) + {ok, [ <<"">> + , {gen_server,call,server,paragraph,1000} + , <<"">> + ] + } = erml_tag:create({html, {body, {gen_server, call, server, paragraph}}}), + + % dynamic template (gen_statem call) + {ok, [ <<"">> + , {gen_statem,call,server,paragraph,1000} + , <<"">> + ] + } = erml_tag:create({html, {body, {gen_statem, call, server, paragraph}}}), + + % special tags + {ok, <<"">>} = erml_tag:create({pre, []}), + {ok, <<"test\ndata">>} + = erml_tag:create({pre, ["test", "data"]}), + {ok, <<"
test\ndata">>}
+ = erml_tag:create({pre, {code, ["test", "data"]}}),
+
+ % explicit content with some features
+ {ok, <<"test">>}
+ = erml_tag:create({content, "test"}),
+ {ok, <<"test&">>}
+ = erml_tag:create({content, "test&"}),
+ {ok, <<"test'">>}
+ = erml_tag:create({content, <<"test'">>}),
+ {ok,<<"test">>}
+ = erml_tag:create({content, test}),
+ {ok,<<"test&">>}
+ = erml_tag:create({content, <<"test&">>, #{entities => false}}),
+
ok.
+
+%%--------------------------------------------------------------------
+%%
+%%--------------------------------------------------------------------
+simple_generator() ->
+ {ok, <<"test">>}.