forked from PlanetCache/CacheJSON
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestJSON.cls
81 lines (68 loc) · 3.86 KB
/
TestJSON.cls
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
Class JSON.TestJSON Extends %UnitTest.TestCase
{
Method TestJSON()
{
#Dim tException As %Exception.AbstractException
Try {
Set tEscapeChars=##class(RSA.Data.DT.Simple.JSON).GetEscapeChars()
Set tEscapeChars=tEscapeChars_$LB($LB("[","["),$LB("]","]"),$LB("{","{"),$LB("}","}"),$LB(":",":"))
for tI=1:1:$LL(tEscapeChars){
For tJ=1:1:$LL(tEscapeChars){
for tK=1:1:$LL(tEscapeChars){
Set tChar1=$LG(tEscapeChars,tI)
Set tChar2=$LG(tEscapeChars,tJ)
Set tChar3=$LG(tEscapeChars,tK)
Set tJSON="{""name"":"""_$LG(tChar1,2)_$LG(tChar2,2)_$LG(tChar3,2)_" is char""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,$LG(tChar1,1)_$LG(tChar2,1)_$LG(tChar3,1)_" is char","Escaping for "_$LG(tChar1,2)_$LG(tChar2,2)_$LG(tChar3,2))
Set tJSON="{""name"":""the "_$LG(tChar1,2)_$LG(tChar2,2)_$LG(tChar3,2)_" is char""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,"the "_$LG(tChar1,1)_$LG(tChar2,1)_$LG(tChar3,1)_" is char","Escaping middle for "_$LG(tChar1,2)_$LG(tChar2,2)_$LG(tChar3,2))
Set tJSON="{""name"":""the "_$LG(tChar1,2)_$LG(tChar2,2)_$LG(tChar3,2)_"""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,"the "_$LG(tChar1,1)_$LG(tChar2,1)_$LG(tChar3,1),"Escaping end for "_$LG(tChar1,2)_$LG(tChar2,2)_$LG(tChar3,2))
if (tK=1){
if (tI=1){
Set tJSON="{""name"":"""_$LG(tChar1,2)_" is char""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,$LG(tChar1,1)_" is char","Escaping for "_$LG(tChar1,2))
Set tJSON="{""name"":""the "_$LG(tChar1,2)_" is char""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,"the "_$LG(tChar1,1)_" is char","Escaping middle for "_$LG(tChar1,2))
Set tJSON="{""name"":""the "_$LG(tChar1,2)_"""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,"the "_$LG(tChar1,1),"Escaping end for "_$LG(tChar1,2))
for tC=97:1:122{
Set tJSON="{""name"":"""_$LG(tChar1,2)_$C(tC)_"""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,$LG(tChar1,1)_$C(tC),"Escaping for "_$LG(tChar1,2)_$C(tC))
}
}
Set tJSON="{""name"":"""_$LG(tChar1,2)_$LG(tChar2,2)_" is char""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,$LG(tChar1,1)_$LG(tChar2,1)_" is char","Escaping for "_$LG(tChar1,2)_$LG(tChar2,2))
Set tJSON="{""name"":""the "_$LG(tChar1,2)_$LG(tChar2,2)_" is char""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,"the "_$LG(tChar1,1)_$LG(tChar2,1)_" is char","Escaping middle for "_$LG(tChar1,2)_$LG(tChar2,2))
Set tJSON="{""name"":""the "_$LG(tChar1,2)_$LG(tChar2,2)_"""}"
Set tObj=##class(RSA.Data.DT.Simple.JSON).Parse(tJSON)
Set tName=tObj.GetAt("name")
Do $$$AssertEquals(tName,"the "_$LG(tChar1,1)_$LG(tChar2,1),"Escaping end for "_$LG(tChar1,2)_$LG(tChar2,2))
}
}
}
}
} catch tException {
Do $$$AssertEquals(1,0,"Exception thrown - " _ tException.Code_ ": " _ tException.Name _ " " _ tException.Data _ " " _ tException.Location)
}
}
}