diff options
author | James M Snell <jasnell@gmail.com> | 2017-03-25 10:33:29 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-03-27 10:12:44 -0700 |
commit | 51b007aaa7e9d37421b1f439cf3fed8bccb15307 (patch) | |
tree | d19d6e68a5f1c6b9d4026fbc66a9ea764af97724 /test/cctest | |
parent | 1005b1dc747b1d32c27743a1d735585e4aee9bbc (diff) | |
download | android-node-v8-51b007aaa7e9d37421b1f439cf3fed8bccb15307.tar.gz android-node-v8-51b007aaa7e9d37421b1f439cf3fed8bccb15307.tar.bz2 android-node-v8-51b007aaa7e9d37421b1f439cf3fed8bccb15307.zip |
test: add cctest for native URL class
PR-URL: https://github.com/nodejs/node/pull/12042
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/test_url.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/cctest/test_url.cc b/test/cctest/test_url.cc new file mode 100644 index 0000000000..1b17ddf78c --- /dev/null +++ b/test/cctest/test_url.cc @@ -0,0 +1,69 @@ +#include "node_url.h" +#include "node_i18n.h" + +#include "gtest/gtest.h" + +using node::url::URL; + +class URLTest : public ::testing::Test { + protected: + void SetUp() override { +#if defined(NODE_HAVE_I18N_SUPPORT) + std::string icu_data_dir; + node::i18n::InitializeICUDirectory(icu_data_dir); +#endif + } + + void TearDown() override {} +}; + +TEST_F(URLTest, Simple) { + URL simple("https://example.org:81/a/b/c?query#fragment"); + + EXPECT_EQ(simple.protocol(), "https:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.port(), 81); + EXPECT_EQ(simple.path(), "/a/b/c"); + EXPECT_EQ(simple.query(), "query"); + EXPECT_EQ(simple.fragment(), "fragment"); +} + +TEST_F(URLTest, Simple2) { + const char* input = "https://example.org:81/a/b/c?query#fragment"; + URL simple(input, strlen(input)); + + EXPECT_EQ(simple.protocol(), "https:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.port(), 81); + EXPECT_EQ(simple.path(), "/a/b/c"); + EXPECT_EQ(simple.query(), "query"); + EXPECT_EQ(simple.fragment(), "fragment"); +} + +TEST_F(URLTest, Base1) { + URL base("http://example.org/foo/bar"); + URL simple("../baz", &base); + + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.path(), "/baz"); +} + +TEST_F(URLTest, Base2) { + URL simple("../baz", "http://example.org/foo/bar"); + + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.path(), "/baz"); +} + +TEST_F(URLTest, Base3) { + const char* input = "../baz"; + const char* base = "http://example.org/foo/bar"; + + URL simple(input, strlen(input), base, strlen(base)); + + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.path(), "/baz"); +} |