Merge pull request #8 from Conaclos/working
Tests - Update syntax and improve implementation
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
class AUTHOR
|
|
||||||
|
class
|
||||||
|
AUTHOR
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
@@ -6,19 +8,26 @@ create
|
|||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_name: STRING_32)
|
make (a_name: STRING_32)
|
||||||
|
-- Create an author with `a_name' as `name'.
|
||||||
do
|
do
|
||||||
set_name (a_name)
|
set_name (a_name)
|
||||||
|
ensure
|
||||||
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
name: STRING_32
|
name: STRING_32
|
||||||
|
-- Author name
|
||||||
|
|
||||||
feature -- Status setting
|
feature -- Change
|
||||||
|
|
||||||
set_name (a_name: STRING_32)
|
set_name (a_name: STRING_32)
|
||||||
|
-- Set `name' with `a_name'.
|
||||||
do
|
do
|
||||||
name := a_name
|
name := a_name
|
||||||
|
ensure
|
||||||
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class AUTHOR
|
end -- class AUTHOR
|
||||||
|
|||||||
@@ -1,40 +1,60 @@
|
|||||||
class BOOK
|
|
||||||
|
class
|
||||||
|
BOOK
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_title: STRING_32; an_author: AUTHOR; an_isbn: STRING_32)
|
make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32)
|
||||||
|
-- Create a book with `a_title' as `title',
|
||||||
|
-- `a_author' as `author', and `a_isbn' as `isbn',
|
||||||
do
|
do
|
||||||
set_title (a_title)
|
set_title (a_title)
|
||||||
set_author (an_author)
|
set_author (a_author)
|
||||||
set_isbn (an_isbn)
|
set_isbn (a_isbn)
|
||||||
|
ensure
|
||||||
|
title_set: title = a_title
|
||||||
|
author_set: author = a_author
|
||||||
|
isbn_set: isbn = a_isbn
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
title: STRING_32
|
title: STRING_32
|
||||||
|
-- Main title.
|
||||||
|
|
||||||
isbn: STRING_32
|
isbn: STRING_32
|
||||||
|
-- ISBN.
|
||||||
|
|
||||||
author: AUTHOR
|
author: AUTHOR
|
||||||
|
-- Author.
|
||||||
|
|
||||||
feature -- Status setting
|
feature -- Change
|
||||||
|
|
||||||
set_title (a_title: STRING_32)
|
set_title (a_title: STRING_32)
|
||||||
|
-- Set `title' with `a_title'.
|
||||||
do
|
do
|
||||||
title := a_title
|
title := a_title
|
||||||
|
ensure
|
||||||
|
title_set: title = a_title
|
||||||
end
|
end
|
||||||
|
|
||||||
set_author (an_author: AUTHOR)
|
set_author (a_author: AUTHOR)
|
||||||
|
-- Set `author' with `a_author'.
|
||||||
do
|
do
|
||||||
author := an_author
|
author := a_author
|
||||||
|
ensure
|
||||||
|
author_set: author = a_author
|
||||||
end
|
end
|
||||||
|
|
||||||
set_isbn (an_isbn: STRING_32)
|
set_isbn (a_isbn: STRING_32)
|
||||||
|
-- Set `isbn' with `a_isbn'.
|
||||||
do
|
do
|
||||||
isbn := an_isbn
|
isbn := a_isbn
|
||||||
|
ensure
|
||||||
|
isbn_set: isbn = a_isbn
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class BOOK
|
end -- class BOOK
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class BOOK_COLLECTION
|
class
|
||||||
|
BOOK_COLLECTION
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
@@ -6,75 +7,72 @@ create
|
|||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_name: STRING_32)
|
make (a_name: STRING_32)
|
||||||
|
-- Create a collection of book with `a_name' as `name'
|
||||||
do
|
do
|
||||||
set_name (a_name)
|
set_name (a_name)
|
||||||
create book_index.make (10)
|
create book_index.make (10)
|
||||||
|
ensure
|
||||||
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
name: STRING_32
|
name: STRING_32
|
||||||
|
-- Name.
|
||||||
|
|
||||||
books: LIST [BOOK]
|
books: LIST [BOOK]
|
||||||
|
-- collection of book.
|
||||||
do
|
do
|
||||||
from
|
create {LINKED_LIST [BOOK]} Result.make
|
||||||
create {LINKED_LIST [BOOK]} Result.make
|
across book_index as it loop
|
||||||
book_index.start
|
Result.append (it.item)
|
||||||
until
|
|
||||||
book_index.after
|
|
||||||
loop
|
|
||||||
Result.append (book_index.item_for_iteration)
|
|
||||||
book_index.forth
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
books_by_author (an_author: STRING_32): detachable LIST [BOOK]
|
books_by_author (a_author: STRING_32): LIST [BOOK]
|
||||||
|
-- Books wrote by `a_author' in this collection.
|
||||||
do
|
do
|
||||||
if book_index.has (an_author) then
|
if attached book_index [a_author] as l_result then
|
||||||
Result := book_index @ an_author
|
Result := l_result
|
||||||
else
|
else
|
||||||
create {LINKED_LIST [BOOK]} Result.make
|
create {LINKED_LIST [BOOK]} Result.make
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status setting
|
feature -- Change
|
||||||
|
|
||||||
set_name (a_name: STRING_32)
|
set_name (a_name: STRING_32)
|
||||||
|
-- Set `name' with `a_name'.
|
||||||
do
|
do
|
||||||
name := a_name
|
name := a_name
|
||||||
|
ensure
|
||||||
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
add_book (a_book: BOOK)
|
add_book (a_book: BOOK)
|
||||||
|
-- Extend collection with `a_book'.
|
||||||
local
|
local
|
||||||
l: detachable LIST [BOOK]
|
l: detachable LIST [BOOK]
|
||||||
do
|
do
|
||||||
if book_index.has (a_book.author.name) then
|
l := book_index.at (a_book.author.name )
|
||||||
l := book_index.at ( a_book.author.name )
|
if l = Void then
|
||||||
else
|
|
||||||
create {LINKED_LIST [BOOK]} l.make
|
create {LINKED_LIST [BOOK]} l.make
|
||||||
book_index.put (l, a_book.author.name)
|
book_index.put (l, a_book.author.name)
|
||||||
end
|
end
|
||||||
if attached l as la then
|
l.force (a_book)
|
||||||
la.force (a_book)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_books (book_list: like books)
|
add_books (book_list: like books)
|
||||||
|
-- Append collection with `book_list'.
|
||||||
do
|
do
|
||||||
from
|
across book_list as it loop
|
||||||
book_list.start
|
add_book (it.item)
|
||||||
until
|
|
||||||
book_list.after
|
|
||||||
loop
|
|
||||||
add_book (book_list.item)
|
|
||||||
book_list.forth
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
||||||
|
-- Association of author name and its books.
|
||||||
|
|
||||||
end -- class BOOK_COLLECTION
|
end -- class BOOK_COLLECTION
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ note
|
|||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class JSON_AUTHOR_CONVERTER
|
class
|
||||||
|
JSON_AUTHOR_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
JSON_CONVERTER
|
||||||
@@ -29,12 +30,10 @@ feature -- Access
|
|||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like to_json): detachable like object
|
from_json (j: like to_json): detachable like object
|
||||||
local
|
|
||||||
ucs: detachable STRING_32
|
|
||||||
do
|
do
|
||||||
ucs ?= json.object (j.item (name_key), Void)
|
if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then
|
||||||
check ucs /= Void end
|
create Result.make (l_name)
|
||||||
create Result.make (ucs)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): JSON_OBJECT
|
to_json (o: like object): JSON_OBJECT
|
||||||
@@ -43,9 +42,10 @@ feature -- Conversion
|
|||||||
Result.put (json.value (o.name), name_key)
|
Result.put (json.value (o.name), name_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
name_key: JSON_STRING
|
name_key: JSON_STRING
|
||||||
|
-- Author's name label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("name")
|
create Result.make_json ("name")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ note
|
|||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class JSON_BOOK_COLLECTION_CONVERTER
|
class
|
||||||
|
JSON_BOOK_COLLECTION_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
JSON_CONVERTER
|
||||||
@@ -30,30 +31,32 @@ feature -- Conversion
|
|||||||
|
|
||||||
from_json (j: like to_json): detachable like object
|
from_json (j: like to_json): detachable like object
|
||||||
local
|
local
|
||||||
ucs: detachable STRING_32
|
l_books: LINKED_LIST [BOOK]
|
||||||
ll: LINKED_LIST [BOOK]
|
|
||||||
b: detachable BOOK
|
|
||||||
ja: detachable JSON_ARRAY
|
|
||||||
i: INTEGER
|
|
||||||
do
|
do
|
||||||
ucs ?= json.object (j.item (name_key), Void)
|
if
|
||||||
check ucs /= Void end
|
attached {STRING_32} json.object (j.item (name_key), Void) as l_name and
|
||||||
create Result.make (ucs)
|
attached {JSON_ARRAY} j.item (books_key) as l_json_array
|
||||||
ja ?= j.item (books_key)
|
then
|
||||||
check ja /= Void end
|
create Result.make (l_name)
|
||||||
from
|
create l_books.make
|
||||||
i := 1
|
|
||||||
create ll.make
|
across
|
||||||
until
|
l_json_array as it
|
||||||
i > ja.count
|
until
|
||||||
loop
|
Result = Void
|
||||||
b ?= json.object (ja [i], "BOOK")
|
loop
|
||||||
check b /= Void end
|
if attached {BOOK} json.object (it.item, "BOOK") as l_book then
|
||||||
ll.force (b)
|
l_books.extend (l_book)
|
||||||
i := i + 1
|
else
|
||||||
|
Result := Void
|
||||||
|
-- Failed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if Result /= Void then
|
||||||
|
Result.add_books (l_books)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
check ll /= Void end
|
|
||||||
Result.add_books (ll)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): JSON_OBJECT
|
to_json (o: like object): JSON_OBJECT
|
||||||
@@ -66,11 +69,13 @@ feature -- Conversion
|
|||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
name_key: JSON_STRING
|
name_key: JSON_STRING
|
||||||
|
-- Collection's name label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("name")
|
create Result.make_json ("name")
|
||||||
end
|
end
|
||||||
|
|
||||||
books_key: JSON_STRING
|
books_key: JSON_STRING
|
||||||
|
-- Book list label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("books")
|
create Result.make_json ("books")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ note
|
|||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class JSON_BOOK_CONVERTER
|
class
|
||||||
|
JSON_BOOK_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
JSON_CONVERTER
|
||||||
@@ -31,17 +32,14 @@ feature -- Access
|
|||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like to_json): detachable like object
|
from_json (j: like to_json): detachable like object
|
||||||
local
|
|
||||||
ucs1, ucs2: detachable STRING_32
|
|
||||||
a: detachable AUTHOR
|
|
||||||
do
|
do
|
||||||
ucs1 ?= json.object (j.item (title_key), Void)
|
if
|
||||||
check ucs1 /= Void end
|
attached {STRING_32} json.object (j.item (title_key), Void) as l_title and
|
||||||
ucs2 ?= json.object (j.item (isbn_key), Void)
|
attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and
|
||||||
check ucs2 /= Void end
|
attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author
|
||||||
a ?= json.object (j.item (author_key), "AUTHOR")
|
then
|
||||||
check a /= Void end
|
create Result.make (l_title, l_author, l_isbn)
|
||||||
create Result.make (ucs1, a, ucs2)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): JSON_OBJECT
|
to_json (o: like object): JSON_OBJECT
|
||||||
@@ -52,19 +50,22 @@ feature -- Conversion
|
|||||||
Result.put (json.value (o.author), author_key)
|
Result.put (json.value (o.author), author_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
title_key: JSON_STRING
|
title_key: JSON_STRING
|
||||||
|
-- Book's title label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("title")
|
create Result.make_json ("title")
|
||||||
end
|
end
|
||||||
|
|
||||||
isbn_key: JSON_STRING
|
isbn_key: JSON_STRING
|
||||||
|
-- Book ISBN label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("isbn")
|
create Result.make_json ("isbn")
|
||||||
end
|
end
|
||||||
|
|
||||||
author_key: JSON_STRING
|
author_key: JSON_STRING
|
||||||
|
-- Author label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("author")
|
create Result.make_json ("author")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,74 +1,76 @@
|
|||||||
class TEST_DS
|
|
||||||
|
note
|
||||||
|
description: "Linked list and hash table converters test."
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
TEST_DS
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
SHARED_EJSON
|
SHARED_EJSON
|
||||||
rename default_create as shared_default_create end
|
undefine
|
||||||
EQA_TEST_SET
|
default_create
|
||||||
select default_create end
|
end
|
||||||
|
|
||||||
|
EQA_TEST_SET
|
||||||
|
|
||||||
feature -- Test
|
feature -- Test
|
||||||
|
|
||||||
test_linked_list_converter
|
test_linked_list_converter
|
||||||
|
-- Convert a linked list to a json value and
|
||||||
|
-- convert this one to a linked list.
|
||||||
local
|
local
|
||||||
jc: JSON_LINKED_LIST_CONVERTER
|
|
||||||
l: LINKED_LIST [STRING]
|
l: LINKED_LIST [STRING]
|
||||||
l2: detachable LINKED_LIST [detachable ANY]
|
|
||||||
s: STRING
|
s: STRING
|
||||||
jv: detachable JSON_VALUE
|
|
||||||
do
|
do
|
||||||
create jc.make
|
|
||||||
json.add_converter (jc)
|
|
||||||
create l.make
|
create l.make
|
||||||
s := "foo"
|
l.force ("foo")
|
||||||
l.force (s)
|
l.force ("bar")
|
||||||
s := "bar"
|
|
||||||
l.force (s)
|
if attached json.value (l) as l_value then
|
||||||
jv := json.value (l)
|
s := l_value.representation
|
||||||
assert ("jv /= Void", jv /= Void)
|
assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST"))
|
||||||
if attached jv as l_jv then
|
else
|
||||||
s := jv.representation
|
assert ("LINKED_LIST converted to a JSON value", False)
|
||||||
l2 ?= json.object (jv, "LINKED_LIST")
|
|
||||||
assert ("l2 /= Void", l2 /= Void)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_hash_table_converter
|
test_hash_table_converter
|
||||||
|
-- Convert a hash table to a json value and
|
||||||
|
-- convert this one to a hash table.
|
||||||
local
|
local
|
||||||
tc: JSON_HASH_TABLE_CONVERTER
|
|
||||||
t: HASH_TABLE [STRING, STRING]
|
t: HASH_TABLE [STRING, STRING]
|
||||||
t2: detachable HASH_TABLE [ANY, HASHABLE]
|
|
||||||
s: STRING
|
s: STRING
|
||||||
ucs_key, ucs_value: detachable STRING_32
|
l_ucs_key: detachable STRING_32
|
||||||
jv: detachable JSON_VALUE
|
|
||||||
do
|
do
|
||||||
create tc.make
|
|
||||||
json.add_converter (tc)
|
|
||||||
create t.make (2)
|
create t.make (2)
|
||||||
t.put ("foo", "1")
|
t.put ("foo", "1")
|
||||||
t.put ("bar", "2")
|
t.put ("bar", "2")
|
||||||
jv := json.value (t)
|
|
||||||
assert ("jv /= Void", jv /= Void)
|
|
||||||
if attached jv as l_jv then
|
|
||||||
s := l_jv.representation
|
|
||||||
t2 ?= json.object (l_jv, "HASH_TABLE")
|
|
||||||
assert ("t2 /= Void", t2 /= Void)
|
|
||||||
end
|
|
||||||
create ucs_key.make_from_string ("1")
|
|
||||||
if attached t2 as l_t2 then
|
|
||||||
ucs_value ?= t2 @ ucs_key
|
|
||||||
assert ("ucs_value /= Void", ucs_value /= Void)
|
|
||||||
if attached ucs_value as l_ucs_value then
|
|
||||||
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
|
|
||||||
end
|
|
||||||
create ucs_key.make_from_string ("2")
|
|
||||||
ucs_value ?= t2 @ ucs_key
|
|
||||||
assert ("ucs_value /= Void", ucs_value /= Void)
|
|
||||||
if attached ucs_value as l_ucs_value then
|
|
||||||
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
if attached json.value (t) as l_value then
|
||||||
|
s := l_value.representation
|
||||||
|
if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then
|
||||||
|
|
||||||
|
create l_ucs_key.make_from_string ("1")
|
||||||
|
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
|
||||||
|
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
|
||||||
|
else
|
||||||
|
assert ("ucs_value /= Void", False)
|
||||||
|
end
|
||||||
|
|
||||||
|
create l_ucs_key.make_from_string ("2")
|
||||||
|
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
|
||||||
|
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
|
||||||
|
else
|
||||||
|
assert ("ucs_value /= Void", False)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
assert ("JSON object converted to HASH_TABLE", False);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
assert ("HASH_TABLE converted to a JSON value", False)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class TEST_DS
|
end -- class TEST_DS
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
class TEST_JSON_CORE
|
class
|
||||||
|
TEST_JSON_CORE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
SHARED_EJSON
|
SHARED_EJSON
|
||||||
rename default_create as shared_default_create end
|
undefine
|
||||||
|
default_create
|
||||||
|
end
|
||||||
|
|
||||||
EQA_TEST_SET
|
EQA_TEST_SET
|
||||||
select default_create end
|
|
||||||
|
|
||||||
feature -- Test
|
feature -- Test
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ feature -- Test
|
|||||||
assert ("jn.representation.same_string (%"42%")", jn.representation.same_string ("42"))
|
assert ("jn.representation.same_string (%"42%")", jn.representation.same_string ("42"))
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
if attached {JSON_NUMBER} json.value (i) as l_jn then
|
if attached {JSON_NUMBER} json.value (i) as l_jn then
|
||||||
assert ("l_jn.representation.same_string (%"42%")", jn.representation.same_string ("42"))
|
assert ("l_jn.representation.same_string (%"42%")", jn.representation.same_string ("42"))
|
||||||
else
|
else
|
||||||
assert ("json.value (i) is a JSON_NUMBER", False)
|
assert ("json.value (i) is a JSON_NUMBER", False)
|
||||||
end
|
end
|
||||||
@@ -477,64 +480,60 @@ feature -- Test
|
|||||||
|
|
||||||
test_json_null
|
test_json_null
|
||||||
local
|
local
|
||||||
a: detachable ANY
|
|
||||||
dummy_object: STRING
|
|
||||||
jn: detachable JSON_NULL
|
|
||||||
jrep: STRING
|
jrep: STRING
|
||||||
|
jn: JSON_NULL
|
||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
do
|
do
|
||||||
-- Eiffel value -> JSON value -> JSON representation
|
-- Eiffel value -> JSON value -> JSON representation
|
||||||
create jn
|
create jn
|
||||||
assert ("jn /= Void", jn /= Void)
|
jrep := "null"
|
||||||
assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal ("null"))
|
|
||||||
|
assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal (jrep))
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
jn ?= json.value (Void)
|
if attached {JSON_NULL} json.value (Void) as l_json_null then
|
||||||
assert ("jn /= Void", jn /= Void)
|
assert ("jn.representation.is_equal (%"null%")", l_json_null.representation.is_equal ("null"))
|
||||||
if attached jn as l_jn then
|
else
|
||||||
assert ("jn.representation.is_equal (%"null%")", l_jn.representation.is_equal ("null"))
|
assert ("json.value (Void) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value
|
-- JSON representation -> JSON value -> Eiffel value
|
||||||
jrep := "null"
|
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
jn := Void
|
if attached parser.parse as l_json_null then
|
||||||
jn ?= parser.parse
|
assert ("a = Void", json.object (l_json_null, Void) = Void)
|
||||||
assert ("jn /= Void", jn /= Void)
|
else
|
||||||
create dummy_object.make_empty
|
assert ("parser.parse /= Void", False)
|
||||||
a := dummy_object
|
end
|
||||||
a ?= json.object (jn, Void)
|
|
||||||
assert ("a = Void", a = Void)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_string_and_character
|
test_json_string_and_character
|
||||||
local
|
local
|
||||||
c: CHARACTER
|
c: CHARACTER
|
||||||
js: detachable JSON_STRING
|
|
||||||
jrep: STRING
|
jrep: STRING
|
||||||
|
js: JSON_STRING
|
||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
do
|
do
|
||||||
c := 'a'
|
c := 'a'
|
||||||
-- Eiffel value -> JSON value -> JSON representation
|
-- Eiffel value -> JSON value -> JSON representation
|
||||||
create js.make_json (c.out)
|
create js.make_json (c.out)
|
||||||
assert ("js /= Void", js /= Void)
|
|
||||||
assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%""))
|
assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%""))
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
js ?= json.value (c)
|
if attached {JSON_STRING} json.value (c) as l_json_str then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("js.representation.is_equal (%"%"a%"%")", l_json_str.representation.is_equal ("%"a%""))
|
||||||
if attached js as l_js then
|
else
|
||||||
assert ("js.representation.is_equal (%"%"a%"%")", l_js.representation.is_equal ("%"a%""))
|
assert ("json.value (c) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value
|
-- JSON representation -> JSON value -> Eiffel value
|
||||||
jrep := "%"a%""
|
jrep := "%"a%""
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
js := Void
|
if attached {JSON_STRING} parser.parse as l_json_str then
|
||||||
js ?= parser.parse
|
if attached {STRING_32} json.object (l_json_str, Void) as ucs then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a"))
|
||||||
if attached {STRING_32} json.object (js, Void) as ucs then
|
end
|
||||||
assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a"))
|
else
|
||||||
end
|
assert ("parser.parse /= Void", False)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_string_and_string
|
test_json_string_and_string
|
||||||
@@ -545,94 +544,101 @@ feature -- Test
|
|||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
do
|
do
|
||||||
s := "foobar"
|
s := "foobar"
|
||||||
|
jrep := "%"foobar%""
|
||||||
|
|
||||||
-- Eiffel value -> JSON value -> JSON representation
|
-- Eiffel value -> JSON value -> JSON representation
|
||||||
create js.make_json (s)
|
create js.make_json (s)
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep))
|
||||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%""))
|
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
js ?= json.value (s)
|
if attached {JSON_STRING} json.value (s) as l_js then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep))
|
||||||
if attached js as l_js then
|
else
|
||||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%""))
|
assert ("json.value (s) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value
|
-- JSON representation -> JSON value -> Eiffel value
|
||||||
jrep := "%"foobar%""
|
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
js := Void
|
if attached {JSON_STRING} parser.parse as l_js then
|
||||||
js ?= parser.parse
|
if attached {STRING_32} json.object (l_js, Void) as l_ucs then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal (s))
|
||||||
if attached {STRING_32} json.object (js, Void) as l_ucs then
|
end
|
||||||
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal ("foobar"))
|
else
|
||||||
end
|
assert ("parser.parse /= Void", False)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_string_and_uc_string
|
test_json_string_and_uc_string
|
||||||
local
|
local
|
||||||
js: detachable JSON_STRING
|
js: detachable JSON_STRING
|
||||||
ucs: detachable STRING_32
|
ucs: detachable STRING_32
|
||||||
jrep: STRING
|
jrep, s: STRING
|
||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
do
|
do
|
||||||
create ucs.make_from_string ("foobar")
|
s := "foobar"
|
||||||
|
jrep := "%"foobar%""
|
||||||
|
create ucs.make_from_string (s)
|
||||||
|
|
||||||
-- Eiffel value -> JSON value -> JSON representation
|
-- Eiffel value -> JSON value -> JSON representation
|
||||||
create js.make_json (ucs)
|
create js.make_json (ucs)
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep))
|
||||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%""))
|
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
js ?= json.value (ucs)
|
if attached {JSON_STRING} json.value (ucs) as l_js then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.is_equal (jrep))
|
||||||
if attached js as l_js then
|
else
|
||||||
assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.is_equal ("%"foobar%""))
|
assert ("json.value (ucs) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value
|
-- JSON representation -> JSON value -> Eiffel value
|
||||||
jrep := "%"foobar%""
|
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
js := Void
|
if attached {JSON_STRING} parser.parse as l_js then
|
||||||
js ?= parser.parse
|
if attached {STRING_32} json.object (l_js, Void) as l_ucs then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal (s))
|
||||||
ucs := Void
|
else
|
||||||
ucs ?= json.object (js, Void)
|
assert ("json.object (js, Void) /= Void", False)
|
||||||
if attached ucs as l_ucs then
|
end
|
||||||
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal ("foobar"))
|
else
|
||||||
end
|
assert ("parser.parse /= Void", False)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_string_and_special_characters
|
test_json_string_and_special_characters
|
||||||
local
|
local
|
||||||
js: detachable JSON_STRING
|
js: detachable JSON_STRING
|
||||||
s: detachable STRING_8
|
s: detachable STRING_8
|
||||||
ucs: detachable STRING_32
|
|
||||||
jrep: STRING
|
jrep: STRING
|
||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
do
|
do
|
||||||
|
jrep := "%"foo\\bar%""
|
||||||
create s.make_from_string ("foo\bar")
|
create s.make_from_string ("foo\bar")
|
||||||
create js.make_json (s)
|
create js.make_json (s)
|
||||||
|
|
||||||
assert ("js.representation.same_string (%"%"foo\\bar%"%")", js.representation.same_string ("%"foo\\bar%""))
|
assert ("js.representation.same_string (%"%"foo\\bar%"%")", js.representation.same_string (jrep))
|
||||||
|
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
js ?= json.value (s)
|
if attached {JSON_STRING} json.value (s) as l_js then
|
||||||
assert ("js /= Void", js /= Void)
|
assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.same_string (jrep))
|
||||||
if js /= Void then
|
else
|
||||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.same_string ("%"foo\\bar%""))
|
assert ("json.value (s) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value
|
-- JSON representation -> JSON value -> Eiffel value
|
||||||
jrep := "%"foo\\bar%""
|
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
js ?= parser.parse
|
if attached {JSON_STRING} parser.parse as l_js then
|
||||||
assert ("js /= Void", js /= Void)
|
if attached {STRING_32} json.object (l_js, Void) as l_ucs then
|
||||||
ucs ?= json.object (js, Void)
|
assert ("ucs.same_string (%"foo\bar%")", l_ucs.same_string ("foo\bar"))
|
||||||
if ucs /= Void then
|
end
|
||||||
assert ("ucs.same_string (%"foo\bar%")", ucs.same_string ("foo\bar"))
|
else
|
||||||
end
|
assert ("parser.parse /= Void", False)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
jrep := "%"foo\\bar%""
|
jrep := "%"foo\\bar%""
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
if attached {JSON_STRING} parser.parse as jstring then
|
if attached {JSON_STRING} parser.parse as jstring then
|
||||||
assert ("unescaped string %"foo\\bar%" to %"foo\bar%"", jstring.unescaped_string_8.same_string ("foo\bar"))
|
assert ("unescaped string %"foo\\bar%" to %"foo\bar%"", jstring.unescaped_string_8.same_string ("foo\bar"))
|
||||||
|
else
|
||||||
|
assert ("parser.parse /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
create js.make_json_from_string_32 ({STRING_32}"%/20320/%/22909/")
|
create js.make_json_from_string_32 ({STRING_32}"%/20320/%/22909/")
|
||||||
@@ -642,13 +648,14 @@ feature -- Test
|
|||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
if attached {JSON_STRING} parser.parse as jstring then
|
if attached {JSON_STRING} parser.parse as jstring then
|
||||||
assert ("same unicode string32 %"%%/20320/%%/22909/%"", jstring.unescaped_string_32.same_string ({STRING_32}"%/20320/%/22909/"))
|
assert ("same unicode string32 %"%%/20320/%%/22909/%"", jstring.unescaped_string_32.same_string ({STRING_32}"%/20320/%/22909/"))
|
||||||
|
else
|
||||||
|
assert ("parser.parse /= Void", False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_array
|
test_json_array
|
||||||
local
|
local
|
||||||
ll: LINKED_LIST [INTEGER_8]
|
ll: LINKED_LIST [INTEGER_8]
|
||||||
ll2: detachable LINKED_LIST [detachable ANY]
|
|
||||||
ja: detachable JSON_ARRAY
|
ja: detachable JSON_ARRAY
|
||||||
jn: JSON_NUMBER
|
jn: JSON_NUMBER
|
||||||
jrep: STRING
|
jrep: STRING
|
||||||
@@ -677,11 +684,10 @@ feature -- Test
|
|||||||
assert ("ja /= Void", ja /= Void)
|
assert ("ja /= Void", ja /= Void)
|
||||||
assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", ja.representation.is_equal ("[0,1,1,2,3,5]"))
|
assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", ja.representation.is_equal ("[0,1,1,2,3,5]"))
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
ja := Void
|
if attached {JSON_ARRAY} json.value (ll) as l_ja then
|
||||||
ja ?= json.value (ll)
|
|
||||||
assert ("ja /= Void", ja /= Void)
|
|
||||||
if attached ja as l_ja then
|
|
||||||
assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", l_ja.representation.is_equal ("[0,1,1,2,3,5]"))
|
assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", l_ja.representation.is_equal ("[0,1,1,2,3,5]"))
|
||||||
|
else
|
||||||
|
assert ("json.value (ll) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value
|
-- JSON representation -> JSON value -> Eiffel value
|
||||||
@@ -691,22 +697,20 @@ feature -- Test
|
|||||||
-- values 0, 1, 1, 2, 3, 5
|
-- values 0, 1, 1, 2, 3, 5
|
||||||
jrep := "[0,1,1,2,3,5]"
|
jrep := "[0,1,1,2,3,5]"
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
ja := Void
|
if attached {JSON_ARRAY} parser.parse as l_ja then
|
||||||
ja ?= parser.parse
|
if attached {LINKED_LIST [detachable ANY]} json.object (ja, Void) as l_ll2 then
|
||||||
assert ("ja /= Void", ja /= Void)
|
assert ("ll2.is_equal (ll)", l_ll2.is_equal (ll))
|
||||||
ll2 ?= json.object (ja, Void)
|
else
|
||||||
assert ("ll2 /= Void", ll2 /= Void)
|
assert ("json.object (ja, Void) /= Void", False)
|
||||||
--ll.compare_objects
|
end
|
||||||
--ll2.compare_objects
|
else
|
||||||
if attached ll2 as l_ll2 then
|
assert ("parser.parse /= Void", False)
|
||||||
assert ("ll2.is_equal (ll)", l_ll2.is_equal (ll))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_object
|
test_json_object
|
||||||
local
|
local
|
||||||
t, t2: detachable HASH_TABLE [detachable ANY, STRING_GENERAL]
|
t: detachable HASH_TABLE [detachable ANY, STRING_GENERAL]
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
ucs_key, ucs: STRING_32
|
ucs_key, ucs: STRING_32
|
||||||
a: ARRAY [INTEGER]
|
a: ARRAY [INTEGER]
|
||||||
@@ -745,6 +749,7 @@ feature -- Test
|
|||||||
jo.put (ja, js_key)
|
jo.put (ja, js_key)
|
||||||
assert ("jo /= Void", jo /= Void)
|
assert ("jo /= Void", jo /= Void)
|
||||||
assert ("jo.representation.is_equal (%"{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}%")", jo.representation.is_equal ("{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"))
|
assert ("jo.representation.is_equal (%"{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}%")", jo.representation.is_equal ("{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"))
|
||||||
|
|
||||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||||
create t.make (3)
|
create t.make (3)
|
||||||
create ucs_key.make_from_string ("name")
|
create ucs_key.make_from_string ("name")
|
||||||
@@ -756,26 +761,28 @@ feature -- Test
|
|||||||
create ucs_key.make_from_string ("contents")
|
create ucs_key.make_from_string ("contents")
|
||||||
a := <<0, 1, 1, 2, 3, 5>>
|
a := <<0, 1, 1, 2, 3, 5>>
|
||||||
t.put (a, ucs_key)
|
t.put (a, ucs_key)
|
||||||
jo := Void
|
if attached {JSON_OBJECT} json.value (t) as l_jo then
|
||||||
jo ?= json.value (t)
|
|
||||||
assert ("jo /= Void", jo /= Void)
|
|
||||||
if attached jo as l_jo then
|
|
||||||
assert ("jo.representation.is_equal (%"{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}%")", l_jo.representation.is_equal ("{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"))
|
assert ("jo.representation.is_equal (%"{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}%")", l_jo.representation.is_equal ("{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"))
|
||||||
|
else
|
||||||
|
assert ("json.value (t) /= Void", False)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation
|
-- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation
|
||||||
jrep := "{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"
|
jrep := "{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
jo := Void
|
if attached {JSON_OBJECT} parser.parse as l_jo then
|
||||||
jo ?= parser.parse
|
if attached {HASH_TABLE [detachable ANY, STRING_GENERAL]} json.object (l_jo, Void) as l_t2 then
|
||||||
assert ("jo /= Void", jo /= Void)
|
if attached json.value (l_t2) as l_jo_2 then
|
||||||
t2 ?= json.object (jo, Void)
|
assert ("jrep.is_equal (jo.representation)", jrep.is_equal (l_jo_2.representation))
|
||||||
assert ("t2 /= Void", t2 /= Void)
|
else
|
||||||
jo ?= json.value (t2)
|
assert ("json.value (t2) /= Void", False)
|
||||||
assert ("jo /= Void", jo /= Void)
|
end
|
||||||
if attached jo as l_jo then
|
else
|
||||||
assert ("jrep.is_equal (jo.representation)", jrep.is_equal (jo.representation))
|
assert ("json.object (jo, Void) /= Void", False)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
assert ("parser.parse /= Void", jo /= Void)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_object_hash_code
|
test_json_object_hash_code
|
||||||
@@ -802,7 +809,6 @@ feature -- Test
|
|||||||
jv := json.value (gv)
|
jv := json.value (gv)
|
||||||
else
|
else
|
||||||
assert ("exceptions.is_developer_exception", json.is_developer_exception)
|
assert ("exceptions.is_developer_exception", json.is_developer_exception)
|
||||||
-- assert ("exceptions.is_developer_exception_of_name", json.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: OPERATING_ENVIRONMENT"))
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
exception := True
|
exception := True
|
||||||
@@ -813,17 +819,15 @@ feature -- Test
|
|||||||
-- Test converting from a JSON value to an Eiffel object based on a
|
-- Test converting from a JSON value to an Eiffel object based on a
|
||||||
-- class for which no JSON converter has been registered.
|
-- class for which no JSON converter has been registered.
|
||||||
local
|
local
|
||||||
gv : detachable OPERATING_ENVIRONMENT
|
gv : detachable ANY
|
||||||
jo: JSON_OBJECT
|
jo: JSON_OBJECT
|
||||||
exception: BOOLEAN
|
exception: BOOLEAN
|
||||||
do
|
do
|
||||||
if not exception then
|
if not exception then
|
||||||
create jo.make
|
create jo.make
|
||||||
gv ?= json.object (jo, "OPERATING_ENVIRONMENT")
|
gv := json.object (jo, "OPERATING_ENVIRONMENT")
|
||||||
else
|
else
|
||||||
assert ("exceptions.is_developer_exception", json.is_developer_exception)
|
assert ("exceptions.is_developer_exception", json.is_developer_exception)
|
||||||
-- assert ("exceptions.is_developer_exception_of_name", json.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> OPERATING_ENVIRONMENT"))
|
|
||||||
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
exception := True
|
exception := True
|
||||||
|
|||||||
@@ -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
|
inherit
|
||||||
SHARED_EJSON
|
SHARED_EJSON
|
||||||
rename default_create as shared_default_create end
|
undefine
|
||||||
|
default_create
|
||||||
|
end
|
||||||
|
|
||||||
EQA_TEST_SET
|
EQA_TEST_SET
|
||||||
select default_create end
|
|
||||||
feature -- Test
|
feature -- Test
|
||||||
|
|
||||||
test_custom_classes
|
test_custom_classes
|
||||||
|
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
|
||||||
local
|
local
|
||||||
bc: detachable BOOK_COLLECTION
|
|
||||||
jbc: JSON_BOOK_CONVERTER
|
jbc: JSON_BOOK_CONVERTER
|
||||||
jbcc: JSON_BOOK_COLLECTION_CONVERTER
|
jbcc: JSON_BOOK_COLLECTION_CONVERTER
|
||||||
jac: JSON_AUTHOR_CONVERTER
|
jac: JSON_AUTHOR_CONVERTER
|
||||||
jo: detachable JSON_OBJECT
|
|
||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
jrep: STRING
|
jrep: STRING
|
||||||
do
|
do
|
||||||
@@ -25,18 +34,20 @@ feature -- Test
|
|||||||
json.add_converter (jac)
|
json.add_converter (jac)
|
||||||
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
|
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
|
||||||
create parser.make_parser (jrep)
|
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
|
||||||
|
|
||||||
end -- class TEST_JSON_CUSTOM_CLASS
|
end -- class TEST_JSON_CUSTOM_CLASS
|
||||||
|
|||||||
Reference in New Issue
Block a user