-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertFrom-JsonFast.tests.ps1
102 lines (72 loc) · 3.18 KB
/
ConvertFrom-JsonFast.tests.ps1
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
import-module pester
import-module (Join-Path $PSSCriptRoot "ConvertFrom-JsonFast.psm1") -force
Describe "It Properly Deserializes small Json" {
it "Handles a simple integer case" {
$String = "{""tom"":5}"
$result = ConvertFrom-JsonFast -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -beoftype [int32]
$result["tom"] | should -be 5
convertto-json -InputObject $result -compress | should -be $string
}
it "Handles a simple large integer case" {
$String = "{""tom"":500000000000}"
$result = ConvertFrom-JsonFast -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -beoftype [int64]
$result["tom"] | should -be 500000000000
convertto-json -InputObject $result -compress | should -be $string
}
it "Handles a simple large double case" {
$String = "{""tom"":5000.05}"
$result = ConvertFrom-JsonFast -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -beoftype [double]
$result["tom"] | should -be 5000.05
convertto-json -InputObject $result -compress | should -be $string
}
it "Handles a simple string case" {
$String = "{""tom"":""5""}"
$result = ConvertFrom-JsonFast -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -beoftype [string]
$result["tom"] | should -be "5"
convertto-json -InputObject $result -compress | should -be $string
}
it "Handles a simple boolean case" {
$String = "{""tom"":false}"
$result = ConvertFrom-JsonFast -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -beoftype [bool]
$result["tom"] | should -be $false
convertto-json -InputObject $result -compress | should -be $string
}
it "Handles a simple null case" {
$String = "{""tom"":null}"
$result = ConvertFrom-JsonFast -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -be $null
convertto-json -InputObject $result -compress | should -be $string
}
it "Alias Also Works" {
$String = "{""tom"":null}"
$result = ConvertFrom-FastJson -InputObject $String
$result | Should -beoftype [hashtable]
$result.keys.count | should -be 1
$result.ContainsKey("tom") | should -be $true
$result["tom"] | should -be $null
convertto-json -InputObject $result -compress | should -be $string
}
}