Software / code / prosody
Comparison
tests/test_util_jid.lua @ 7299:b7dea8fd09c7
Merge
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 18 Mar 2016 11:55:40 +0100 |
| parent | 7296:1859e07ae082 |
| child | 7473:a558fef9d018 |
comparison
equal
deleted
inserted
replaced
| 7298:7056bbaf81ee | 7299:b7dea8fd09c7 |
|---|---|
| 69 assert_equal(compare("user@host/resource", "host"), true, "host should match"); | 69 assert_equal(compare("user@host/resource", "host"), true, "host should match"); |
| 70 assert_equal(compare("user@host/resource", "user@host"), true, "user and host should match"); | 70 assert_equal(compare("user@host/resource", "user@host"), true, "user and host should match"); |
| 71 assert_equal(compare("user@other-host", "host"), false, "host should not match"); | 71 assert_equal(compare("user@other-host", "host"), false, "host should not match"); |
| 72 assert_equal(compare("user@other-host", "user@host"), false, "host should not match"); | 72 assert_equal(compare("user@other-host", "user@host"), false, "host should not match"); |
| 73 end | 73 end |
| 74 | |
| 75 function node(node) | |
| 76 local function test(jid, expected_node) | |
| 77 assert_equal(node(jid), expected_node, "Unexpected node for "..tostring(jid)); | |
| 78 end | |
| 79 | |
| 80 test("example.com", nil); | |
| 81 test("foo.example.com", nil); | |
| 82 test("foo.example.com/resource", nil); | |
| 83 test("foo.example.com/some resource", nil); | |
| 84 test("foo.example.com/some@resource", nil); | |
| 85 | |
| 86 test("foo@foo.example.com/some@resource", "foo"); | |
| 87 test("foo@example/some@resource", "foo"); | |
| 88 | |
| 89 test("foo@example/@resource", "foo"); | |
| 90 test("foo@example@resource", nil); | |
| 91 test("foo@example", "foo"); | |
| 92 test("foo", nil); | |
| 93 | |
| 94 test(nil, nil); | |
| 95 end | |
| 96 | |
| 97 function host(host) | |
| 98 local function test(jid, expected_host) | |
| 99 assert_equal(host(jid), expected_host, "Unexpected host for "..tostring(jid)); | |
| 100 end | |
| 101 | |
| 102 test("example.com", "example.com"); | |
| 103 test("foo.example.com", "foo.example.com"); | |
| 104 test("foo.example.com/resource", "foo.example.com"); | |
| 105 test("foo.example.com/some resource", "foo.example.com"); | |
| 106 test("foo.example.com/some@resource", "foo.example.com"); | |
| 107 | |
| 108 test("foo@foo.example.com/some@resource", "foo.example.com"); | |
| 109 test("foo@example/some@resource", "example"); | |
| 110 | |
| 111 test("foo@example/@resource", "example"); | |
| 112 test("foo@example@resource", nil); | |
| 113 test("foo@example", "example"); | |
| 114 test("foo", "foo"); | |
| 115 | |
| 116 test(nil, nil); | |
| 117 end | |
| 118 | |
| 119 function resource(resource) | |
| 120 local function test(jid, expected_resource) | |
| 121 assert_equal(resource(jid), expected_resource, "Unexpected resource for "..tostring(jid)); | |
| 122 end | |
| 123 | |
| 124 test("example.com", nil); | |
| 125 test("foo.example.com", nil); | |
| 126 test("foo.example.com/resource", "resource"); | |
| 127 test("foo.example.com/some resource", "some resource"); | |
| 128 test("foo.example.com/some@resource", "some@resource"); | |
| 129 | |
| 130 test("foo@foo.example.com/some@resource", "some@resource"); | |
| 131 test("foo@example/some@resource", "some@resource"); | |
| 132 | |
| 133 test("foo@example/@resource", "@resource"); | |
| 134 test("foo@example@resource", nil); | |
| 135 test("foo@example", nil); | |
| 136 test("foo", nil); | |
| 137 test("/foo", nil); | |
| 138 test("@x/foo", nil); | |
| 139 test("@/foo", nil); | |
| 140 | |
| 141 test(nil, nil); | |
| 142 end | |
| 143 |