-
Notifications
You must be signed in to change notification settings - Fork 1k
/
UrlEncodeTest.kt
110 lines (89 loc) · 2.7 KB
/
UrlEncodeTest.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
104
105
106
107
108
109
110
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.tests.http
import io.ktor.http.*
import kotlin.test.*
class UrlEncodeTest {
@Test
fun testUrlEncodePathKeepDigits() {
assertEquals("0123456789", "0123456789".encodeURLPath())
}
@Test
fun testUrlEncodeQueryComponentKeepDigits() {
assertEquals("0123456789", "0123456789".encodeURLQueryComponent())
}
@Test
fun testUrlKeepDigitsInPath() {
assertEquals("/0123456789/", Url("http://x.com/0123456789/").encodedPath)
}
@Test
fun testUrlEncodePathKeepLetters() {
assertEquals(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".encodeURLPath()
)
}
@Test
fun testUrlEncodeQueryComponentKeepLetters() {
assertEquals(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".encodeURLQueryComponent()
)
}
@Test
fun testUrlKeepLettersInPath() {
assertEquals(
"/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/",
Url("http://x.com/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/").encodedPath
)
}
@Test
fun testUrlEncodePathKeepHyphen() {
assertEquals("-", "-".encodeURLPath())
}
@Test
fun testUrlEncodeQueryComponentKeepHyphen() {
assertEquals("-", "-".encodeURLQueryComponent())
}
@Test
fun testUrlKeepHyphenInPath() {
assertEquals("/-/", Url("http://x.com/-/").encodedPath)
}
@Test
fun testUrlEncodePathKeepPeriod() {
assertEquals(".", ".".encodeURLPath())
}
@Test
fun testUrlEncodeQueryComponentKeepPeriod() {
assertEquals(".", ".".encodeURLQueryComponent())
}
@Test
fun testUrlKeepPeriodInPath() {
assertEquals("/./", Url("http://x.com/./").encodedPath)
}
@Test
fun testUrlEncodePathKeepUnderscore() {
assertEquals("_", "_".encodeURLPath())
}
@Test
fun testUrlEncodeQueryComponentKeepUnderscore() {
assertEquals("_", "_".encodeURLQueryComponent())
}
@Test
fun testUrlKeepUnderscoreInPath() {
assertEquals("/_/", Url("http://x.com/_/").encodedPath)
}
@Test
fun testUrlEncodePathKeepTilde() {
assertEquals("~", "~".encodeURLPath())
}
@Test
fun testUrlEncodeQueryComponentKeepTilde() {
assertEquals("~", "~".encodeURLQueryComponent())
}
@Test
fun testUrlKeepTildeInPath() {
assertEquals("/~/", Url("http://x.com/~/").encodedPath)
}
}