-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUrlsomeTest.kt
103 lines (89 loc) · 3.64 KB
/
UrlsomeTest.kt
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import com.github.mobiletoly.urlsome.Urlsome
import kotlin.test.Test
import kotlin.test.assertEquals
class UrlsomeTest {
@Test fun `base URL`() {
val url = Urlsome("http://localhost:8081")
assertEquals("http://localhost:8081", url.toString())
}
@Test fun `path components`() {
val url = Urlsome("http://localhost:8081")/"root"/"user"
assertEquals("http://localhost:8081/root/user", url.toString())
}
@Test fun `nonstring path components`() {
val url = Urlsome("http://localhost:8081")/"root"/"user"/12
assertEquals("http://localhost:8081/root/user/12", url.toString())
}
@Test fun `base URL with trailing slash`() {
val url = Urlsome("http://localhost:8081/")/"root"/"user"
assertEquals("http://localhost:8081/root/user", url.toString())
}
@Test fun `path encoding`() {
val url = Urlsome("http://localhost:8081/")/"root"/"some/path"/"user"
assertEquals("http://localhost:8081/root/some%2Fpath/user", url.toString())
}
@Test fun `path without encoding`() {
val url = Urlsome("http://localhost:8081/")/"root"*"some/path"/"user"
assertEquals("http://localhost:8081/root/some/path/user", url.toString())
}
@Test fun `query components`() {
val url = (Urlsome("http://localhost:8081/")/"root") [
"param1" to "value1",
"param2" to "value2"
]
assertEquals("http://localhost:8081/root?param1=value1¶m2=value2", url.toString())
}
@Test fun `query with null value on default options`() {
val url = (Urlsome("http://localhost:8081/")/"root") [
"param1" to null,
"param2" to "value2"
]
assertEquals("http://localhost:8081/root?param2=value2", url.toString())
}
@Test fun `query with null value on excludeNullQueryValues=false option`() {
val url = (Urlsome(
baseUrl = "http://localhost:8081/",
options = Urlsome.Options(excludeNullQueryValues = false)
) / "root") [
"param1" to null,
"param2" to "value2"
]
assertEquals("http://localhost:8081/root?param1¶m2=value2", url.toString())
}
@Test fun `query shorthand syntax`() {
val url = ((Urlsome("http://localhost:8081/")/"root")
`?` ("param1" to "value1")
`?` ("param2" to "value2")
)
assertEquals("http://localhost:8081/root?param1=value1¶m2=value2", url.toString())
}
@Test fun `fragment components`() {
val url = ((Urlsome("http://localhost:8081/")/"root")
`?` ("param1" to "value1")
`?` ("param2" to "value2")
`#` ("x" to 1)
`#` ("y" to 2)
)
assertEquals("http://localhost:8081/root?param1=value1¶m2=value2#x=1&y=2", url.toString())
}
@Test fun `fragment with null value on default option`() {
val url = ((Urlsome("http://localhost:8081/")/"root")
`?` ("param1" to "value1")
`?` ("param2" to "value2")
`#` ("main" to null)
)
assertEquals("http://localhost:8081/root?param1=value1¶m2=value2#main", url.toString())
}
@Test fun `fragment with null value on excludeNullFragmentValues=true`() {
val url = ((
Urlsome(
baseUrl = "http://localhost:8081/",
options = Urlsome.Options(excludeNullFragmentValues = true))/"root"
)
`?` ("param1" to "value1")
`?` ("param2" to "value2")
`#` ("main" to null)
)
assertEquals("http://localhost:8081/root?param1=value1¶m2=value2", url.toString())
}
}