location_ut.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "location.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. Y_UNIT_TEST_SUITE(TResolveRedirectTests) {
  4. Y_UNIT_TEST(Absolute) {
  5. UNIT_ASSERT_EQUAL(
  6. NUri::ResolveRedirectLocation("http://example.com", "http://redir-example.com/sub"), "http://redir-example.com/sub");
  7. }
  8. Y_UNIT_TEST(AbsWithFragment) {
  9. UNIT_ASSERT_EQUAL(
  10. NUri::ResolveRedirectLocation("http://example.com", "http://redir-example.com/sub#Hello"), "http://redir-example.com/sub#Hello");
  11. UNIT_ASSERT_EQUAL(
  12. NUri::ResolveRedirectLocation("http://example.com/#Hello", "http://redir-example.com/sub"), "http://redir-example.com/sub#Hello");
  13. }
  14. Y_UNIT_TEST(Rel) {
  15. UNIT_ASSERT_EQUAL(
  16. NUri::ResolveRedirectLocation("http://example.com", "/sub"), "http://example.com/sub");
  17. }
  18. Y_UNIT_TEST(RelWithFragment) {
  19. UNIT_ASSERT_EQUAL(
  20. NUri::ResolveRedirectLocation("http://example.com", "/sub#Hello"), "http://example.com/sub#Hello");
  21. UNIT_ASSERT_EQUAL(
  22. NUri::ResolveRedirectLocation("http://example.com/#Hello", "/sub"), "http://example.com/sub#Hello");
  23. }
  24. Y_UNIT_TEST(WrongLocation) {
  25. UNIT_ASSERT_EQUAL(
  26. NUri::ResolveRedirectLocation("http://example.com", ""), "");
  27. }
  28. Y_UNIT_TEST(WrongBase) {
  29. UNIT_ASSERT_EQUAL(
  30. NUri::ResolveRedirectLocation("", "http://example.com"), "");
  31. }
  32. Y_UNIT_TEST(HashBangIsNothingSpecial) {
  33. UNIT_ASSERT_EQUAL(
  34. NUri::ResolveRedirectLocation("http://example.com", "http://redir-example.com/sub#!Hello"), "http://redir-example.com/sub#!Hello");
  35. UNIT_ASSERT_EQUAL(
  36. NUri::ResolveRedirectLocation("http://example.com/#!Hello", "http://redir-example.com/sub"), "http://redir-example.com/sub#!Hello");
  37. }
  38. }