package Ġcom . so y wiz . kor io . net Ċ Ċ import Ġcom . so y wiz . kor io . lang .* Ċ import Ġkotlin . test .* Ċ Ċ class ĠURL Test Ġ{ Ċ ĉ data Ġclass ĠUrl Info ( val Ġurl : ĠString , Ġval Ġcomponent String : ĠString , Ġval Ġis Absolute : ĠBoolean , Ġval Ġis Opaque : ĠBoolean ) ĊĊ ĉ val ĠURL S Ġ= ĠlistOf ( Ċĉ ĉ Url Info ("", Ġcomponent String Ġ= Ġ" URL ( path = )", Ġis Absolute Ġ= Ġfalse , Ġis Opaque Ġ= Ġfalse ), Ċĉ ĉ Url Info (" hello ", Ġcomponent String Ġ= Ġ" URL ( path = hello )", Ġis Absolute Ġ= Ġfalse , Ġis Opaque Ġ= Ġfalse ), Ċĉ ĉ Url Info ("/ hello ", Ġcomponent String Ġ= Ġ" URL ( path =/ hello )", Ġis Absolute Ġ= Ġfalse , Ġis Opaque Ġ= Ġfalse ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ "/ hello ? world ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( path =/ hello , Ġquery = world )", Ċĉĉ ĉ is Absolute Ġ= Ġfalse , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ "/ hello ? world ? world ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( path =/ hello , Ġquery = world ? world )", Ċĉĉ ĉ is Absolute Ġ= Ġfalse , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info (" http :// ", Ġcomponent String Ġ= Ġ" URL ( scheme = http , Ġpath = )", Ġis Absolute Ġ= Ġtrue , Ġis Opaque Ġ= Ġfalse ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// hello ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , Ġhost = hello , Ġpath = )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// hello /", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , Ġhost = hello , Ġpath = /) ", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// user : pass @ hello ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , ĠuserInfo = user : pass , Ġhost = hello , Ġpath = )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// user : pass @ hello / path ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , ĠuserInfo = user : pass , Ġhost = hello , Ġpath =/ path )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// user : pass @ hello / path ? query ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , ĠuserInfo = user : pass , Ġhost = hello , Ġpath =/ path , Ġquery = query )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// hello / path ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , Ġhost = hello , Ġpath =/ path )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// hello ? query ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , Ġhost = hello , Ġpath = , Ġquery = query )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " mailto : demo @ host . com ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = mailto , ĠuserInfo = demo , Ġhost = host . com , Ġpath = )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġtrue Ċĉ ĉ ), Ċĉ ĉ Url Info ( Ċĉĉ ĉ " http :// hello ? query # hash ", Ċĉĉ ĉ component String Ġ= Ġ" URL ( scheme = http , Ġhost = hello , Ġpath = , Ġquery = query , Ġfragment = hash )", Ċĉĉ ĉ is Absolute Ġ= Ġtrue , Ċĉĉ ĉ is Opaque Ġ= Ġfalse Ċĉ ĉ ) Ċ ĉ ) ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Parsing () Ġ{ Ċĉ ĉ for Ġ( url Ġin ĠURL S ) ĠassertEquals ( url . component String , ĠURL ( url . url ). to Component String (), Ġurl . url ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Full Url () Ġ{ Ċĉ ĉ for Ġ( url Ġin ĠURL S ) ĠassertEquals ( url . url , ĠURL ( url . url ). full Url , Ġurl . url ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Is Absolute () Ġ{ Ċĉ ĉ for Ġ( url Ġin ĠURL S ) ĠassertEquals ( url . is Absolute , ĠURL ( url . url ). is Absolute , Ġurl . url ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Is Opaque () Ġ{ Ċĉ ĉ for Ġ( url Ġin ĠURL S ) ĠassertEquals ( url . is Opaque , ĠURL ( url . url ). is Opaque , Ġurl . url ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Resolve () Ġ{ Ċĉ ĉ assertEquals (" https :// www . google . es /", ĠURL . resolve (" https :// google . es /", Ġ" https :// www . google . es / ")) Ċĉ ĉ assertEquals (" https :// google . es / demo ", ĠURL . resolve (" https :// google . es / path ", Ġ" demo ")) Ċĉ ĉ assertEquals (" https :// google . es / path / demo ", ĠURL . resolve (" https :// google . es / path /", Ġ" demo ")) Ċĉ ĉ assertEquals (" https :// google . es / demo ", ĠURL . resolve (" https :// google . es / path /", Ġ"/ demo ")) Ċĉ ĉ assertEquals (" https :// google . es / test ", ĠURL . resolve (" https :// google . es / path / path 2 ", Ġ"../ test ")) Ċĉ ĉ assertEquals (" https :// google . es / path / test ", ĠURL . resolve (" https :// google . es / path / path 2 /", Ġ"../ test ")) Ċĉ ĉ assertEquals (" https :// google . es / test ", ĠURL . resolve (" https :// google . es / path / path 2 /", Ġ"../../../ test ")) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Encode () Ġ{ Ċĉ ĉ assertEquals (" hello % 2 0 world ", ĠURL . encode Component (" hello Ġworld ")) Ċĉ ĉ assertEquals (" hello + world ", ĠURL . encode Component (" hello Ġworld ", Ġform Url Encoded Ġ= Ġtrue )) ĊĊĉ ĉ assertEquals (" hello % 2 B world ", ĠURL . encode Component (" hello + world ")) Ċĉ ĉ assertEquals (" hello % 2 B world ", ĠURL . encode Component (" hello + world ", Ġform Url Encoded Ġ= Ġtrue )) ĊĊĉ ĉ assertEquals (" abcdefgh ijkl mnopqrst uvw xyz ABCDEF GH IJ KL MN OP Q RST UV WZ 0 1 2 3 4 5 6 7 8 9 % 2 0 - _. *", ĠURL . encode Component (" abcdefgh ijkl mnopqrst uvw xyz ABCDEF GH IJ KL MN OP Q RST UV WZ 0 1 2 3 4 5 6 7 8 9 Ġ- _. * ")) Ċĉ ĉ assertEquals ("% C 3 % A 1 % C 3 % A 9 % C 3 % AD % C 3 % B 3 % C 3 % BA ", ĠURL . encode Component (" Ã¡ Ã© ÃŃ Ã³ Ãº ")) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Decode () Ġ{ Ċĉ ĉ assertEquals (" hello Ġworld ", ĠURL . decode Component (" hello % 2 0 world ")) Ċĉ ĉ assertEquals (" hello + world +", ĠURL . decode Component (" hello + world % 2 B ")) Ċĉ ĉ assertEquals (" hello Ġworld +", ĠURL . decode Component (" hello + world % 2 B ", Ġform Url Encoded Ġ= Ġtrue )) Ċĉ ĉ assertEquals (" abcdefgh ijkl mnopqrst uvw xyz ABCDEF GH IJ KL MN OP Q RST UV WZ 0 1 2 3 4 5 6 7 8 9 Ġ- _. *", ĠURL . decode Component (" abcdefgh ijkl mnopqrst uvw xyz ABCDEF GH IJ KL MN OP Q RST UV WZ 0 1 2 3 4 5 6 7 8 9 % 2 0 - _. * ")) Ċĉ ĉ assertEquals (" Ã¡ Ã© ÃŃ Ã³ Ãº ", ĠURL . decode Component ("% C 3 % A 1 % C 3 % A 9 % C 3 % AD % C 3 % B 3 % C 3 % BA ")) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest () Ġ{ Ċĉ ĉ assertEquals (" data : text / plain ; base 6 4 , a GV sb G 8 td 2 9 yb GQ =", Ġcreate Base 6 4 URL For Data (" hello - world ". toByteArray (), Ġ" text / plain ")) Ċ ĉ } ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Custom Ws Port () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= ĠURL (" ws :// websocket . domain . com : 8 0 8 0 ") ĊĠĠĠĠĠĠĠ ĠassertEquals (" ws ", Ġuri . scheme ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( false , Ġuri . is Secure Scheme ) ĊĠĠĠĠĠĠĠ ĠassertEquals (" websocket . domain . com ", Ġuri . host ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 8 0 8 0 , Ġuri . port ) ĊĠĠĠ Ġ} Ċ } Ċ