Syntax update.

Replace assigment attempt with object test.
This commit is contained in:
Conaclos
2014-06-30 18:28:13 +02:00
parent a74cda2f33
commit c5e1b1ee69
3 changed files with 192 additions and 175 deletions

View File

@@ -1,19 +1,28 @@
class TEST_JSON_CUSTOM_CLASSES
note
description: "Parsing and converter of book collection test."
date: "$Date$"
revision: "$Revision$"
class
TEST_JSON_CUSTOM_CLASSES
inherit
SHARED_EJSON
rename default_create as shared_default_create end
undefine
default_create
end
EQA_TEST_SET
select default_create end
feature -- Test
test_custom_classes
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
local
bc: detachable BOOK_COLLECTION
jbc: JSON_BOOK_CONVERTER
jbcc: JSON_BOOK_COLLECTION_CONVERTER
jac: JSON_AUTHOR_CONVERTER
jo: detachable JSON_OBJECT
parser: JSON_PARSER
jrep: STRING
do
@@ -25,18 +34,20 @@ feature -- Test
json.add_converter (jac)
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
create parser.make_parser (jrep)
jo := Void
jo ?= parser.parse
assert ("jo /= Void", jo /= Void)
bc := Void
bc ?= json.object (jo, "BOOK_COLLECTION")
assert ("bc /= Void", bc /= Void)
jo ?= json.value (bc)
assert ("jo /= Void", jo /= Void)
if attached jo as l_jo then
assert ("JSON representation is correct", l_jo.representation.same_string ("{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"))
end
if attached {JSON_OBJECT} parser.parse as l_json_object then
if attached {BOOK_COLLECTION} json.object (l_json_object, "BOOK_COLLECTION") as l_collection then
if attached {JSON_OBJECT} json.value (l_collection) as l_json_object_2 then
assert ("JSON representation is correct", l_json_object_2.representation.same_string (jrep))
else
assert ("BOOK_COLLECTION converted to JSON_OBJECT", False)
end
else
assert ("JSON_OBJECT converted to BOOK_COLLECTION", False)
end
else
assert ("JSON object representation to JSON_OBJECT", False)
end
end
end -- class TEST_JSON_CUSTOM_CLASS