1+ <#
2+ . SYNOPSIS
3+ Tests for UrlQueryStringParser
4+ #>
5+ [CmdletBinding ()]
6+ param ()
7+
8+ if ((ConvertTo-UrlQueryString @ {" foo" = $true } - ContinuationOfString ' ' ) -ne ' ?foo' ) {
9+ throw " Continuation of empty failed."
10+ }
11+
12+ if ((ConvertTo-UrlQueryString @ {" foo" = $true } - ContinuationOfString ' ?bar=baz' ) -ne ' ?bar=baz&foo' ) {
13+ throw " Continuation of non-empty failed."
14+ }
15+
16+ if ((ConvertTo-UrlQueryString @ {}) -ne " " ) {
17+ throw " Empty conversion to UrlQueryString failed."
18+ }
19+
20+ if ((ConvertTo-UrlQueryString @ {} - ContinuationOfString ' ?bar=baz' ) -ne " ?bar=baz" ) {
21+ throw " Continuation with empty failed."
22+ }
23+
24+ if ((ConvertTo-UrlQueryString @ {" foo" = ' bar baz quux' } - SkipEncodeSpaces) -ne " ?foo=bar baz quux" ) {
25+ throw " Skip encoding spaces failed."
26+ }
27+
28+ if ((ConvertTo-UrlQueryString @ {" foo" = ' bar baz quux' }) -ne " ?foo=bar%20baz%20quux" ) {
29+ throw " Encoding spaces failed."
30+ }
31+
32+ $exampleOrderedDict = [ordered ] @ {
33+ foo = " bar"
34+ oogy = $true
35+ array = ' one' , ' two' , ' three' , ' four'
36+ baz = " quux"
37+ boogy = $true
38+ empty = ' '
39+ donotshow = $false
40+ last = $true
41+ }
42+
43+ if ((ConvertTo-UrlQueryString $exampleOrderedDict ) -ne " ?foo=bar&oogy&array=one&array=two&array=three&array=four&baz=quux&boogy&empty=&last" ) {
44+ throw " Deluxe test failed."
45+ }
46+
47+ if ((ConvertFrom-UrlQueryString " " ).Keys.Count -gt 0 ) {
48+ throw " Conversion from empty querystring failed."
49+ }
50+
51+ if ((ConvertFrom-UrlQueryString " ?" ).Keys.Count -gt 0 ) {
52+ throw " Conversion from pseudo-empty querystring failed."
53+ }
54+
55+ if ((ConvertFrom-UrlQueryString " foo=bar" )[" foo" ] -ne " bar" ) {
56+ throw " Conversion from simple single-entry foo=bar failed."
57+ }
58+
59+ if ((ConvertFrom-UrlQueryString " ?foo=bar" )[" foo" ] -ne " bar" ) {
60+ throw " Conversion from simple single-entry foo=bar with '?' prefix failed."
61+ }
62+
63+ if ((ConvertFrom-UrlQueryString " foo" )[" foo" ] -ne $true ) {
64+ throw ' Valueless entries as $true failed.'
65+ }
66+
67+ if ((ConvertFrom-UrlQueryString " foo=" )[" foo" ].Length -ne 0 ) {
68+ throw ' Convert from empty-string-value querystring failed.'
69+ }
70+
71+ $exampleQueryString = " ?foo=bar&oogy&array=one&baz=quux&array=two&boogy&array=three&empty=&array=four&last"
72+ $result = ConvertFrom-UrlQueryString $exampleQueryString
73+ if (($result.Keys -join " ," ) -ne " foo,oogy,array,baz,boogy,empty,last" ) {
74+ throw " Order of keys not preserved converting to ordered dictionary."
75+ }
76+ if (($result [' array' ] -join " ," ) -ne " one,two,three,four" ) {
77+ throw " Order of array members not preserved converting to ordered dictionary."
78+ }
79+ if (-not $result [' ArRaY' ]) {
80+ throw " Case sensitivity!"
81+ }
0 commit comments