Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

48 Zeilen
1.7 KiB

  1. -module(rebar_uri_SUITE).
  2. -export([all/0,
  3. parse/1,
  4. append_path/1]).
  5. -include_lib("common_test/include/ct.hrl").
  6. -include_lib("eunit/include/eunit.hrl").
  7. -include_lib("kernel/include/file.hrl").
  8. all() ->
  9. [parse].
  10. parse(_Config) ->
  11. #{scheme := Scheme, host := Host, path := Path} = rebar_uri:parse("https://repo.hex.pm"),
  12. ?assertEqual("https", Scheme),
  13. ?assertEqual("repo.hex.pm", Host),
  14. ?assert(lists:member(Path, ["", "/"])),
  15. #{scheme := Scheme2, host := Host2, port := Port2, path := Path2, query := Query2} =
  16. rebar_uri:parse("https://repo.hex.pm:443?foo=bar"),
  17. ?assertEqual("https", Scheme2),
  18. ?assertEqual("repo.hex.pm", Host2),
  19. ?assertEqual(443, Port2),
  20. ?assert(lists:member(Path2, ["", "/"])),
  21. ?assertEqual("foo=bar", Query2),
  22. #{scheme := Scheme3, host := Host3, path := Path3, query := Query3} =
  23. rebar_uri:parse("https://repo.hex.pm/over/here?foo=bar"),
  24. ?assertEqual("https", Scheme3),
  25. ?assertEqual("repo.hex.pm", Host3),
  26. ?assertEqual("/over/here", Path3),
  27. ?assertEqual("foo=bar", Query3).
  28. append_path(_Config) ->
  29. %% OTP version differences
  30. {ok, Val1} = rebar_utils:append_path("https://repo.hex.pm", "/repos/org"),
  31. ?assert(lists:member(Val1, [
  32. "https://repo.hex.pm/repos/org",
  33. "https://repo.hex.pm:443/repos/org"
  34. ])),
  35. {ok, Val2} = rebar_utils:append_path("https://repo.hex.pm?foo=bar", "/repos/org"),
  36. ?assert(lists:member(Val2, [
  37. "https://repo.hex.pm/repos/org?foo=bar",
  38. "https://repo.hex.pm:443/repos/org?foo=bar"
  39. ])),
  40. ?assertEqual({ok, "https://repo.hex.pm:443/repos/org?foo=bar"},
  41. rebar_utils:append_path("https://repo.hex.pm:443?foo=bar", "/repos/org")).