Add some unit test
This commit is contained in:
41
V2rayNG/app/src/test/java/com/v2ray/ang/HttpUtilTest.kt
Normal file
41
V2rayNG/app/src/test/java/com/v2ray/ang/HttpUtilTest.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.v2ray.ang
|
||||
|
||||
import com.v2ray.ang.util.HttpUtil
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class HttpUtilTest {
|
||||
|
||||
@Test
|
||||
fun testIdnToASCII() {
|
||||
// Regular URL remains unchanged
|
||||
val regularUrl = "https://example.com/path"
|
||||
assertEquals(regularUrl, HttpUtil.idnToASCII(regularUrl))
|
||||
|
||||
// Non-ASCII URL converts to ASCII (Punycode)
|
||||
val nonAsciiUrl = "https://例子.测试/path"
|
||||
val expectedNonAscii = "https://xn--fsqu00a.xn--0zwm56d/path"
|
||||
assertEquals(expectedNonAscii, HttpUtil.idnToASCII(nonAsciiUrl))
|
||||
|
||||
// Mixed URL only converts the host part
|
||||
val mixedUrl = "https://例子.com/测试"
|
||||
val expectedMixed = "https://xn--fsqu00a.com/测试"
|
||||
assertEquals(expectedMixed, HttpUtil.idnToASCII(mixedUrl))
|
||||
|
||||
// URL with Basic Authentication using regular domain
|
||||
val basicAuthUrl = "https://user:password@example.com/path"
|
||||
assertEquals(basicAuthUrl, HttpUtil.idnToASCII(basicAuthUrl))
|
||||
|
||||
// URL with Basic Authentication using non-ASCII domain
|
||||
val basicAuthNonAscii = "https://user:password@例子.测试/path"
|
||||
val expectedBasicAuthNonAscii = "https://user:password@xn--fsqu00a.xn--0zwm56d/path"
|
||||
assertEquals(expectedBasicAuthNonAscii, HttpUtil.idnToASCII(basicAuthNonAscii))
|
||||
|
||||
// URL with non-ASCII username and password
|
||||
val nonAsciiAuth = "https://用户:密码@example.com/path"
|
||||
// Basic auth credentials should remain unchanged as they're percent-encoded separately
|
||||
assertEquals(nonAsciiAuth, HttpUtil.idnToASCII(nonAsciiAuth))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.junit.Test
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class AngUnitTest {
|
||||
class UtilsTest {
|
||||
|
||||
@Test
|
||||
fun test_parseInt() {
|
||||
Reference in New Issue
Block a user