@@ -90,6 +90,64 @@ def test_uri_parse_http_with_query_string():
9090 testing.assert_equal(uri._original_path, " /job" )
9191 testing.assert_equal(uri.request_uri, " /job?title=engineer" )
9292 testing.assert_equal(uri.query_string, " title=engineer" )
93+ testing.assert_equal(uri.queries[" title" ], " engineer" )
94+
95+
96+ def test_uri_parse_multiple_query_parameters ():
97+ var uri = URI .parse(" http://example.com/search?q=python&page=1&limit=20" )
98+ testing.assert_equal(uri.scheme, " http" )
99+ testing.assert_equal(uri.host, " example.com" )
100+ testing.assert_equal(uri.path, " /search" )
101+ testing.assert_equal(uri.query_string, " q=python&page=1&limit=20" )
102+ testing.assert_equal(uri.queries[" q" ], " python" )
103+ testing.assert_equal(uri.queries[" page" ], " 1" )
104+ testing.assert_equal(uri.queries[" limit" ], " 20" )
105+ testing.assert_equal(uri.request_uri, " /search?q=python&page=1&limit=20" )
106+
107+
108+ def test_uri_parse_query_with_special_characters ():
109+ var uri = URI .parse(" https://example.com/path?name=John+Doe&email=john%40e xample.com" )
110+ testing.assert_equal(uri.scheme, " https" )
111+ testing.assert_equal(uri.host, " example.com" )
112+ testing.assert_equal(uri.path, " /path" )
113+ testing.assert_equal(uri.query_string, " name=John+Doe&email=john%40e xample.com" )
114+ # testing.assert_equal(uri.queries["name"], "John Doe") - fails, contains John+Doe
115+ # testing.assert_equal(uri.queries["email"], "john@example.com") - fails, contains john%40example.com
116+
117+
118+ def test_uri_parse_empty_query_values ():
119+ var uri = URI .parse(" http://example.com/api?key=&token=&empty" )
120+ testing.assert_equal(uri.query_string, " key=&token=&empty" )
121+ testing.assert_equal(uri.queries[" key" ], " " )
122+ testing.assert_equal(uri.queries[" token" ], " " )
123+ testing.assert_equal(uri.queries[" empty" ], " " )
124+
125+
126+ def test_uri_parse_complex_query ():
127+ var uri = URI .parse(" https://example.com/search?q=test&filter[category]=books&filter[price]=10-20&sort=desc&page=1" )
128+ testing.assert_equal(uri.scheme, " https" )
129+ testing.assert_equal(uri.host, " example.com" )
130+ testing.assert_equal(uri.path, " /search" )
131+ testing.assert_equal(uri.query_string, " q=test&filter[category]=books&filter[price]=10-20&sort=desc&page=1" )
132+ testing.assert_equal(uri.queries[" q" ], " test" )
133+ testing.assert_equal(uri.queries[" filter[category]" ], " books" )
134+ testing.assert_equal(uri.queries[" filter[price]" ], " 10-20" )
135+ testing.assert_equal(uri.queries[" sort" ], " desc" )
136+ testing.assert_equal(uri.queries[" page" ], " 1" )
137+
138+
139+ def test_uri_parse_query_with_unicode ():
140+ var uri = URI .parse(" http://example.com/search?q=%E 2%82% AC&lang=%F 0%9F%87% A9%F 0%9F%87% AA" )
141+ testing.assert_equal(uri.query_string, " q=%E 2%82% AC&lang=%F 0%9F%87% A9%F 0%9F%87% AA" )
142+ # testing.assert_equal(uri.queries["q"], "€") - fails, contains %E2%82%AC
143+ # testing.assert_equal(uri.queries["lang"], "🇩🇪") - fails, contains %F0%9F%87%A9%F0%9F%87%AA
144+
145+
146+ # def test_uri_parse_query_with_fragments():
147+ # var uri = URI.parse("http://example.com/page?id=123#section1")
148+ # testing.assert_equal(uri.query_string, "id=123")
149+ # testing.assert_equal(uri.queries["id"], "123")
150+ # testing.assert_equal(...) - how do we treat fragments?
93151
94152
95153def test_uri_parse_no_scheme ():
0 commit comments