Skip to content

Commit c5e1b1e

Browse files
ConaclosConaclos
authored andcommitted
Syntax update.
Replace assigment attempt with object test.
1 parent a74cda2 commit c5e1b1e

File tree

3 files changed

+192
-175
lines changed

3 files changed

+192
-175
lines changed

test/autotest/test_suite/test_ds.e

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,76 @@
1-
class TEST_DS
1+
2+
note
3+
description: "Linked list and hash table converters test."
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
TEST_DS
29

310
inherit
411
SHARED_EJSON
5-
rename default_create as shared_default_create end
6-
EQA_TEST_SET
7-
select default_create end
12+
undefine
13+
default_create
14+
end
815

16+
EQA_TEST_SET
917

1018
feature -- Test
1119

1220
test_linked_list_converter
21+
-- Convert a linked list to a json value and
22+
-- convert this one to a linked list.
1323
local
14-
jc: JSON_LINKED_LIST_CONVERTER
1524
l: LINKED_LIST [STRING]
16-
l2: detachable LINKED_LIST [detachable ANY]
1725
s: STRING
18-
jv: detachable JSON_VALUE
1926
do
20-
create jc.make
21-
json.add_converter (jc)
2227
create l.make
23-
s := "foo"
24-
l.force (s)
25-
s := "bar"
26-
l.force (s)
27-
jv := json.value (l)
28-
assert ("jv /= Void", jv /= Void)
29-
if attached jv as l_jv then
30-
s := jv.representation
31-
l2 ?= json.object (jv, "LINKED_LIST")
32-
assert ("l2 /= Void", l2 /= Void)
28+
l.force ("foo")
29+
l.force ("bar")
30+
31+
if attached json.value (l) as l_value then
32+
s := l_value.representation
33+
assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST"))
34+
else
35+
assert ("LINKED_LIST converted to a JSON value", False)
3336
end
3437
end
3538

3639
test_hash_table_converter
40+
-- Convert a hash table to a json value and
41+
-- convert this one to a hash table.
3742
local
38-
tc: JSON_HASH_TABLE_CONVERTER
3943
t: HASH_TABLE [STRING, STRING]
40-
t2: detachable HASH_TABLE [ANY, HASHABLE]
4144
s: STRING
42-
ucs_key, ucs_value: detachable STRING_32
43-
jv: detachable JSON_VALUE
45+
l_ucs_key: detachable STRING_32
4446
do
45-
create tc.make
46-
json.add_converter (tc)
4747
create t.make (2)
4848
t.put ("foo", "1")
4949
t.put ("bar", "2")
50-
jv := json.value (t)
51-
assert ("jv /= Void", jv /= Void)
52-
if attached jv as l_jv then
53-
s := l_jv.representation
54-
t2 ?= json.object (l_jv, "HASH_TABLE")
55-
assert ("t2 /= Void", t2 /= Void)
56-
end
57-
create ucs_key.make_from_string ("1")
58-
if attached t2 as l_t2 then
59-
ucs_value ?= t2 @ ucs_key
60-
assert ("ucs_value /= Void", ucs_value /= Void)
61-
if attached ucs_value as l_ucs_value then
62-
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
63-
end
64-
create ucs_key.make_from_string ("2")
65-
ucs_value ?= t2 @ ucs_key
66-
assert ("ucs_value /= Void", ucs_value /= Void)
67-
if attached ucs_value as l_ucs_value then
68-
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
69-
end
7050

71-
end
51+
if attached json.value (t) as l_value then
52+
s := l_value.representation
53+
if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then
54+
55+
create l_ucs_key.make_from_string ("1")
56+
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
57+
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
58+
else
59+
assert ("ucs_value /= Void", False)
60+
end
61+
62+
create l_ucs_key.make_from_string ("2")
63+
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
64+
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
65+
else
66+
assert ("ucs_value /= Void", False)
67+
end
68+
else
69+
assert ("JSON object converted to HASH_TABLE", False);
70+
end
71+
else
72+
assert ("HASH_TABLE converted to a JSON value", False)
73+
end
7274
end
7375

7476
end -- class TEST_DS

0 commit comments

Comments
 (0)