This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtest_usage.dpr
136 lines (107 loc) · 3.66 KB
/
test_usage.dpr
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
program test_usage;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
SysUtils,
superobject;
var
my_string, my_int, my_object, my_array: ISuperObject;
new_obj: ISuperObject;
j: integer;
ite: TSuperObjectIter;
begin
try
my_string := TSuperObject.Create(#9);
writeln('my_string=', my_string.AsString);
writeln('my_string.AsJSon=', my_string.AsJSon);
my_string := TSuperObject.Create('foo');
writeln('my_string=', my_string.AsString);
writeln('my_string.AsJson=', my_string.AsJson);
my_int := TSuperObject.Create(9);
writeln('my_int=', my_int.AsInteger);
writeln('my_int.AsJson=', my_int.AsJson);
my_array := TSuperObject.Create(stArray);
my_array.I[''] := 1; // append
my_array.I[''] := 2; // append
my_array.I[''] := 3; // append
my_array.I['4'] := 5;
writeln('my_array=');
with my_array.AsArray do
for j := 0 to Length - 1 do
if O[j] = nil then
writeln(#9'[', j,']=', 'null') else
writeln(#9'[', j,']=', O[j].AsJson);
writeln('my_array.AsJson=', my_array.AsJson);
my_object := TSuperObject.Create(stObject);
my_object.I['abc'] := 12;
// my_object.S['path.to.foo[5]'] := 'bar';
my_object.B['bool0'] := false;
my_object.B['bool1'] := true;
my_object.S['baz'] := 'bang';
my_object.S['baz'] := 'fark';
my_object.AsObject.Delete('baz');
my_object['arr'] := my_array;
writeln('my_object=');
if ObjectFindFirst(my_object, ite) then
repeat
writeln(#9,ite.key,': ', ite.val.AsJson);
until not ObjectFindNext(ite);
ObjectFindClose(ite);
writeln('my_object.AsJson=', my_object.AsJson);
new_obj := SO('"003"');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('/* hello */"foo"');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('// hello'#10'"foo"');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('"\u0041\u0042\u0043"');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('null');
if new_obj = nil then
writeln('new_obj.AsJson=', 'null');
new_obj := SO('true');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('12');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('12.3');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('["\n"]');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('["\nabc\n"]');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('[null]');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('[]');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('["abc",null,"def",12]');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('{}');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('{ "foo": "bar" }');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('{ "foo": "bar", "baz": null, "bool0": true }');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('{ "foo": [null, "foo"] }');
writeln('new_obj.AsJson=', new_obj.AsJson);
new_obj := SO('{ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "arr": [ 1, 2, 3, null, 5 ] }');
writeln('new_obj.AsJson=', new_obj.AsJson);
try
new_obj := SO('{ foo }');
except
writeln('got error as expected');
end;
my_string := nil;
my_int := nil;
my_object := nil;
my_array := nil;
new_obj := nil;
writeln(#10'press enter ...');
readln;
except
on E: Exception do
writeln(E.Message)
end;
end.