|
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 |
2 | 9 |
|
3 | 10 | inherit |
4 | 11 | 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 |
8 | 15 |
|
| 16 | + EQA_TEST_SET |
9 | 17 |
|
10 | 18 | feature -- Test |
11 | 19 |
|
12 | 20 | test_linked_list_converter |
| 21 | + -- Convert a linked list to a json value and |
| 22 | + -- convert this one to a linked list. |
13 | 23 | local |
14 | | - jc: JSON_LINKED_LIST_CONVERTER |
15 | 24 | l: LINKED_LIST [STRING] |
16 | | - l2: detachable LINKED_LIST [detachable ANY] |
17 | 25 | s: STRING |
18 | | - jv: detachable JSON_VALUE |
19 | 26 | do |
20 | | - create jc.make |
21 | | - json.add_converter (jc) |
22 | 27 | 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) |
33 | 36 | end |
34 | 37 | end |
35 | 38 |
|
36 | 39 | test_hash_table_converter |
| 40 | + -- Convert a hash table to a json value and |
| 41 | + -- convert this one to a hash table. |
37 | 42 | local |
38 | | - tc: JSON_HASH_TABLE_CONVERTER |
39 | 43 | t: HASH_TABLE [STRING, STRING] |
40 | | - t2: detachable HASH_TABLE [ANY, HASHABLE] |
41 | 44 | s: STRING |
42 | | - ucs_key, ucs_value: detachable STRING_32 |
43 | | - jv: detachable JSON_VALUE |
| 45 | + l_ucs_key: detachable STRING_32 |
44 | 46 | do |
45 | | - create tc.make |
46 | | - json.add_converter (tc) |
47 | 47 | create t.make (2) |
48 | 48 | t.put ("foo", "1") |
49 | 49 | 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 |
70 | 50 |
|
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 |
72 | 74 | end |
73 | 75 |
|
74 | 76 | end -- class TEST_DS |
0 commit comments