Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

63 wiersze
2.0 KiB

  1. %% coding:utf-8
  2. -module(rebar_templater_SUITE).
  3. -compile(export_all).
  4. -include_lib("common_test/include/ct.hrl").
  5. -include_lib("eunit/include/eunit.hrl").
  6. all() ->
  7. [
  8. consult_template_latin1_test,
  9. consult_template_utf8_test
  10. ].
  11. init_per_suite(Config) -> Config.
  12. end_per_suite(_Config) -> ok.
  13. init_per_testcase(Case, Config)
  14. when Case =:= consult_template_latin1_test;
  15. Case =:= consult_template_utf8_test ->
  16. %% Generate UCS string containing all printable characters of latin-1 area.
  17. Description = lists:seq(16#A1, 16#AC) ++ lists:seq(16#AE, 16#FE),
  18. Expected = [{description, Description}],
  19. SampleTemplate = "{description, \"" ++ Description ++ "\"}.\n",
  20. Path = generate_sample_template_file(Case, SampleTemplate, Config),
  21. [{template_file_path, Path}, {expected, Expected} | Config];
  22. init_per_testcase(_Case, Config) -> Config.
  23. end_per_testcase(_Case, _Config) -> ok.
  24. generate_sample_template_file(Case, Content, Config) ->
  25. CaseName = atom_to_list(Case),
  26. {Encoding, EncodingName} =
  27. case string:str(CaseName, "latin1") of
  28. 0 -> {utf8, "utf-8"};
  29. _ -> {latin1, "latin-1"}
  30. end,
  31. PrivDir = ?config(priv_dir, Config),
  32. Path = filename:join([PrivDir, CaseName ++ ".template"]),
  33. {ok, FH} = file:open(Path, [write, {encoding, Encoding}]),
  34. try
  35. io:format(FH, "%% coding:~s~n~s", [EncodingName, Content])
  36. after
  37. file:close(FH)
  38. end,
  39. Path.
  40. consult_template_test_common(Config) ->
  41. Expected = ?config(expected, Config),
  42. Path = ?config(template_file_path, Config),
  43. Result = rebar_templater:consult_template([], file, Path),
  44. ?assertEqual(Expected, Result),
  45. ok.
  46. consult_template_latin1_test() ->
  47. [{doc, "parse test for latin1 template file"}].
  48. consult_template_latin1_test(Config) ->
  49. consult_template_test_common(Config).
  50. consult_template_utf8_test() ->
  51. [{doc, "parse test for utf8 template file"}].
  52. consult_template_utf8_test(Config) ->
  53. consult_template_test_common(Config).