summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/third_party/uri/test/uri_reference_test.cpp
blob: 9eaedb8259d886ff92db239c430def34485fd559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Glyn Matthews 2012-2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <gtest/gtest.h>
#include <network/uri.hpp>


TEST(uri_make_relative_test, opaque_uri) {
  network::uri uri_1("mailto:glynos@example.com");
  network::uri uri_2("mailto:john.doe@example.com");
  ASSERT_EQ(uri_2, uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, simple_test) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/path/");
  ASSERT_EQ("/path/", uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, simple_test_with_different_authority) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.org/path/");
  ASSERT_EQ("http://www.example.org/path/", uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, simple_test_is_relative) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/path/");
  ASSERT_FALSE(uri_1.make_relative(uri_2).is_absolute());
}

TEST(uri_make_relative_test, simple_test_is_hierarchical) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/path/");
  ASSERT_FALSE(uri_1.make_relative(uri_2).is_opaque());
}

TEST(uri_make_relative_test, simple_test_with_query) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/path/?key=value");
  ASSERT_EQ("/path/?key=value", uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, simple_test_with_fragment) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/path/#fragment");
  ASSERT_EQ("/path/#fragment", uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, make_relative_with_percent_encoding_normalization) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/%7E%66%6F%6F%62%61%72%5F%36%39/");
  ASSERT_EQ("/~foobar_69/", uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, make_relative_with_percent_encoding_normalization_with_query) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/%7E%66%6F%6F%62%61%72%5F%36%39/?key=value");
  ASSERT_EQ("/~foobar_69/?key=value", uri_1.make_relative(uri_2));
}

TEST(uri_make_relative_test, make_relative_with_percent_encoding_normalization_with_fragment) {
  network::uri uri_1("http://www.example.com/");
  network::uri uri_2("http://www.example.com/%7E%66%6F%6F%62%61%72%5F%36%39/#fragment");
  ASSERT_EQ("/~foobar_69/#fragment", uri_1.make_relative(uri_2));
}