Merge branch 'master' of https://github.com/eiffelhub/json
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
note
|
||||
description : "test_suite application root class"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
description: "test_suite application root class"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
|
||||
ARGUMENTS
|
||||
|
||||
create
|
||||
@@ -17,7 +18,7 @@ feature {NONE} -- Initialization
|
||||
make
|
||||
-- Run application.
|
||||
do
|
||||
--| Add your code here
|
||||
--| Add your code here
|
||||
print ("Hello Eiffel World!%N")
|
||||
end
|
||||
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
class AUTHOR
|
||||
class
|
||||
AUTHOR
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: STRING_32)
|
||||
do
|
||||
set_name (a_name)
|
||||
end
|
||||
make (a_name: STRING_32)
|
||||
-- Create an author with `a_name' as `name'.
|
||||
do
|
||||
set_name (a_name)
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_32
|
||||
name: STRING_32
|
||||
-- Author name
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
set_name (a_name: STRING_32)
|
||||
do
|
||||
name := a_name
|
||||
end
|
||||
set_name (a_name: STRING_32)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
end -- class AUTHOR
|
||||
|
||||
@@ -1,40 +1,59 @@
|
||||
class BOOK
|
||||
class
|
||||
BOOK
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_title: STRING_32; an_author: AUTHOR; an_isbn: STRING_32)
|
||||
do
|
||||
set_title (a_title)
|
||||
set_author (an_author)
|
||||
set_isbn (an_isbn)
|
||||
end
|
||||
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
|
||||
set_title (a_title)
|
||||
set_author (a_author)
|
||||
set_isbn (a_isbn)
|
||||
ensure
|
||||
title_set: title = a_title
|
||||
author_set: author = a_author
|
||||
isbn_set: isbn = a_isbn
|
||||
end
|
||||
|
||||
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)
|
||||
do
|
||||
title := a_title
|
||||
end
|
||||
set_title (a_title: STRING_32)
|
||||
-- Set `title' with `a_title'.
|
||||
do
|
||||
title := a_title
|
||||
ensure
|
||||
title_set: title = a_title
|
||||
end
|
||||
|
||||
set_author (an_author: AUTHOR)
|
||||
do
|
||||
author := an_author
|
||||
end
|
||||
set_author (a_author: AUTHOR)
|
||||
-- Set `author' with `a_author'.
|
||||
do
|
||||
author := a_author
|
||||
ensure
|
||||
author_set: author = a_author
|
||||
end
|
||||
|
||||
set_isbn (an_isbn: STRING_32)
|
||||
do
|
||||
isbn := an_isbn
|
||||
end
|
||||
set_isbn (a_isbn: STRING_32)
|
||||
-- Set `isbn' with `a_isbn'.
|
||||
do
|
||||
isbn := a_isbn
|
||||
ensure
|
||||
isbn_set: isbn = a_isbn
|
||||
end
|
||||
|
||||
end -- class BOOK
|
||||
|
||||
@@ -1,80 +1,82 @@
|
||||
class BOOK_COLLECTION
|
||||
class
|
||||
BOOK_COLLECTION
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: STRING_32)
|
||||
do
|
||||
set_name (a_name)
|
||||
create book_index.make (10)
|
||||
end
|
||||
make (a_name: STRING_32)
|
||||
-- Create a book collection with `a_name' as `name'.
|
||||
do
|
||||
set_name (a_name)
|
||||
create book_index.make (10)
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_32
|
||||
name: STRING_32
|
||||
-- Name.
|
||||
|
||||
books: LIST [BOOK]
|
||||
do
|
||||
from
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
book_index.start
|
||||
until
|
||||
book_index.after
|
||||
loop
|
||||
Result.append (book_index.item_for_iteration)
|
||||
book_index.forth
|
||||
end
|
||||
end
|
||||
books: LIST [BOOK]
|
||||
-- collection of book.
|
||||
do
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
across
|
||||
book_index as it
|
||||
loop
|
||||
Result.append (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
books_by_author (an_author: STRING_32): detachable LIST [BOOK]
|
||||
do
|
||||
if book_index.has (an_author) then
|
||||
Result := book_index @ an_author
|
||||
else
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
end
|
||||
end
|
||||
books_by_author (a_author: STRING_32): LIST [BOOK]
|
||||
-- Books wrote by `a_author' in this collection.
|
||||
do
|
||||
if attached book_index [a_author] as l_result then
|
||||
Result := l_result
|
||||
else
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
set_name (a_name: STRING_32)
|
||||
do
|
||||
name := a_name
|
||||
end
|
||||
set_name (a_name: STRING_32)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
add_book (a_book: BOOK)
|
||||
local
|
||||
l: detachable LIST [BOOK]
|
||||
do
|
||||
if book_index.has (a_book.author.name) then
|
||||
l := book_index.at ( a_book.author.name )
|
||||
else
|
||||
create {LINKED_LIST [BOOK]} l.make
|
||||
book_index.put (l, a_book.author.name)
|
||||
end
|
||||
if attached l as la then
|
||||
la.force (a_book)
|
||||
end
|
||||
add_book (a_book: BOOK)
|
||||
-- Extend collection with `a_book'.
|
||||
local
|
||||
l: detachable LIST [BOOK]
|
||||
do
|
||||
l := book_index.at (a_book.author.name)
|
||||
if l = Void then
|
||||
create {LINKED_LIST [BOOK]} l.make
|
||||
book_index.put (l, a_book.author.name)
|
||||
end
|
||||
l.force (a_book)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
add_books (book_list: like books)
|
||||
|
||||
do
|
||||
from
|
||||
book_list.start
|
||||
until
|
||||
book_list.after
|
||||
loop
|
||||
add_book (book_list.item)
|
||||
book_list.forth
|
||||
end
|
||||
end
|
||||
add_books (book_list: like books)
|
||||
-- Append collection with `book_list'.
|
||||
do
|
||||
across
|
||||
book_list as it
|
||||
loop
|
||||
add_book (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@@ -1,53 +1,54 @@
|
||||
note
|
||||
description: "A JSON converter for AUTHOR"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
description: "A JSON converter for AUTHOR"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_AUTHOR_CONVERTER
|
||||
class
|
||||
JSON_AUTHOR_CONVERTER
|
||||
|
||||
inherit
|
||||
JSON_CONVERTER
|
||||
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
local
|
||||
ucs: STRING_32
|
||||
do
|
||||
create ucs.make_from_string ("")
|
||||
create object.make (ucs)
|
||||
end
|
||||
make
|
||||
local
|
||||
ucs: STRING_32
|
||||
do
|
||||
create ucs.make_from_string ("")
|
||||
create object.make (ucs)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
object: AUTHOR
|
||||
object: AUTHOR
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
from_json (j: like to_json): detachable like object
|
||||
local
|
||||
ucs: detachable STRING_32
|
||||
do
|
||||
ucs ?= json.object (j.item (name_key), Void)
|
||||
check ucs /= Void end
|
||||
create Result.make (ucs)
|
||||
end
|
||||
from_json (j: like to_json): detachable like object
|
||||
do
|
||||
if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then
|
||||
create Result.make (l_name)
|
||||
end
|
||||
end
|
||||
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (json.value (o.name), name_key)
|
||||
end
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (json.value (o.name), name_key)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
name_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("name")
|
||||
end
|
||||
name_key: JSON_STRING
|
||||
-- Author's name label.
|
||||
once
|
||||
create Result.make_from_string ("name")
|
||||
end
|
||||
|
||||
end -- class JSON_AUTHOR_CONVERTER
|
||||
|
||||
@@ -1,78 +1,82 @@
|
||||
note
|
||||
description: "A JSON converter for BOOK_COLLECTION"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
description: "A JSON converter for BOOK_COLLECTION"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_BOOK_COLLECTION_CONVERTER
|
||||
class
|
||||
JSON_BOOK_COLLECTION_CONVERTER
|
||||
|
||||
inherit
|
||||
JSON_CONVERTER
|
||||
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
local
|
||||
ucs: STRING_32
|
||||
do
|
||||
create ucs.make_from_string ("")
|
||||
create object.make (ucs)
|
||||
end
|
||||
make
|
||||
local
|
||||
ucs: STRING_32
|
||||
do
|
||||
create ucs.make_from_string ("")
|
||||
create object.make (ucs)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
object: BOOK_COLLECTION
|
||||
object: BOOK_COLLECTION
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
from_json (j: like to_json): detachable like object
|
||||
local
|
||||
ucs: detachable STRING_32
|
||||
ll: LINKED_LIST [BOOK]
|
||||
b: detachable BOOK
|
||||
ja: detachable JSON_ARRAY
|
||||
i: INTEGER
|
||||
do
|
||||
ucs ?= json.object (j.item (name_key), Void)
|
||||
check ucs /= Void end
|
||||
create Result.make (ucs)
|
||||
ja ?= j.item (books_key)
|
||||
check ja /= Void end
|
||||
from
|
||||
i := 1
|
||||
create ll.make
|
||||
until
|
||||
i > ja.count
|
||||
loop
|
||||
b ?= json.object (ja [i], "BOOK")
|
||||
check b /= Void end
|
||||
ll.force (b)
|
||||
i := i + 1
|
||||
end
|
||||
check ll /= Void end
|
||||
Result.add_books (ll)
|
||||
end
|
||||
from_json (j: like to_json): detachable like object
|
||||
local
|
||||
l_books: LINKED_LIST [BOOK]
|
||||
do
|
||||
if
|
||||
attached {STRING_32} json.object (j.item (name_key), Void) as l_name and
|
||||
attached {JSON_ARRAY} j.item (books_key) as l_json_array
|
||||
then
|
||||
create Result.make (l_name)
|
||||
create l_books.make
|
||||
across
|
||||
l_json_array as it
|
||||
until
|
||||
Result = Void
|
||||
loop
|
||||
if attached {BOOK} json.object (it.item, "BOOK") as l_book then
|
||||
l_books.extend (l_book)
|
||||
else
|
||||
Result := Void
|
||||
-- Failed
|
||||
end
|
||||
end
|
||||
if Result /= Void then
|
||||
Result.add_books (l_books)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (json.value (o.name), name_key)
|
||||
Result.put (json.value (o.books), books_key)
|
||||
end
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make_with_capacity (2)
|
||||
Result.put (json.value (o.name), name_key)
|
||||
Result.put (json.value (o.books), books_key)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
name_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("name")
|
||||
end
|
||||
name_key: JSON_STRING
|
||||
-- Collection's name label.
|
||||
once
|
||||
create Result.make_from_string ("name")
|
||||
end
|
||||
|
||||
books_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("books")
|
||||
end
|
||||
books_key: JSON_STRING
|
||||
-- Book list label.
|
||||
once
|
||||
create Result.make_from_string ("books")
|
||||
end
|
||||
|
||||
end -- class JSON_BOOK_COLLECTION_CONVERTER
|
||||
|
||||
@@ -1,72 +1,74 @@
|
||||
note
|
||||
description: "A JSON converter for BOOK"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
description: "A JSON converter for BOOK"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_BOOK_CONVERTER
|
||||
class
|
||||
JSON_BOOK_CONVERTER
|
||||
|
||||
inherit
|
||||
JSON_CONVERTER
|
||||
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
local
|
||||
ucs: STRING_32
|
||||
a: AUTHOR
|
||||
do
|
||||
create ucs.make_from_string ("")
|
||||
create a.make (ucs)
|
||||
create object.make (ucs, a, ucs)
|
||||
end
|
||||
make
|
||||
local
|
||||
ucs: STRING_32
|
||||
a: AUTHOR
|
||||
do
|
||||
create ucs.make_from_string ("")
|
||||
create a.make (ucs)
|
||||
create object.make (ucs, a, ucs)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
object: BOOK
|
||||
object: BOOK
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
from_json (j: like to_json): detachable like object
|
||||
local
|
||||
ucs1, ucs2: detachable STRING_32
|
||||
a: detachable AUTHOR
|
||||
do
|
||||
ucs1 ?= json.object (j.item (title_key), Void)
|
||||
check ucs1 /= Void end
|
||||
ucs2 ?= json.object (j.item (isbn_key), Void)
|
||||
check ucs2 /= Void end
|
||||
a ?= json.object (j.item (author_key), "AUTHOR")
|
||||
check a /= Void end
|
||||
create Result.make (ucs1, a, ucs2)
|
||||
end
|
||||
from_json (j: like to_json): detachable like object
|
||||
do
|
||||
if
|
||||
attached {STRING_32} json.object (j.item (title_key), Void) as l_title and
|
||||
attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and
|
||||
attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author
|
||||
then
|
||||
create Result.make (l_title, l_author, l_isbn)
|
||||
end
|
||||
end
|
||||
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (json.value (o.title), title_key)
|
||||
Result.put (json.value (o.isbn), isbn_key)
|
||||
Result.put (json.value (o.author), author_key)
|
||||
end
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make_with_capacity (3)
|
||||
Result.put (json.value (o.title), title_key)
|
||||
Result.put (json.value (o.isbn), isbn_key)
|
||||
Result.put (json.value (o.author), author_key)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
title_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("title")
|
||||
end
|
||||
title_key: JSON_STRING
|
||||
-- Book's title label.
|
||||
once
|
||||
create Result.make_from_string ("title")
|
||||
end
|
||||
|
||||
isbn_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("isbn")
|
||||
end
|
||||
isbn_key: JSON_STRING
|
||||
-- Book ISBN label.
|
||||
once
|
||||
create Result.make_from_string ("isbn")
|
||||
end
|
||||
|
||||
author_key: JSON_STRING
|
||||
once
|
||||
create Result.make_json ("author")
|
||||
end
|
||||
author_key: JSON_STRING
|
||||
-- Author label.
|
||||
once
|
||||
create Result.make_from_string ("author")
|
||||
end
|
||||
|
||||
end -- class JSON_BOOK_CONVERTER
|
||||
|
||||
@@ -1,74 +1,72 @@
|
||||
class TEST_DS
|
||||
note
|
||||
description: "Linked list and hash table converters test."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
TEST_DS
|
||||
|
||||
inherit
|
||||
SHARED_EJSON
|
||||
rename default_create as shared_default_create end
|
||||
EQA_TEST_SET
|
||||
select default_create end
|
||||
|
||||
SHARED_EJSON
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
EQA_TEST_SET
|
||||
|
||||
feature -- Test
|
||||
|
||||
test_linked_list_converter
|
||||
local
|
||||
jc: JSON_LINKED_LIST_CONVERTER
|
||||
l: LINKED_LIST [STRING]
|
||||
l2: detachable LINKED_LIST [detachable ANY]
|
||||
s: STRING
|
||||
jv: detachable JSON_VALUE
|
||||
do
|
||||
create jc.make
|
||||
json.add_converter (jc)
|
||||
create l.make
|
||||
s := "foo"
|
||||
l.force (s)
|
||||
s := "bar"
|
||||
l.force (s)
|
||||
jv := json.value (l)
|
||||
assert ("jv /= Void", jv /= Void)
|
||||
if attached jv as l_jv then
|
||||
s := jv.representation
|
||||
l2 ?= json.object (jv, "LINKED_LIST")
|
||||
assert ("l2 /= Void", l2 /= Void)
|
||||
end
|
||||
end
|
||||
test_linked_list_converter
|
||||
-- Convert a linked list to a json value and
|
||||
-- convert this one to a linked list.
|
||||
local
|
||||
l: LINKED_LIST [STRING]
|
||||
s: STRING
|
||||
do
|
||||
create l.make
|
||||
l.force ("foo")
|
||||
l.force ("bar")
|
||||
if attached json.value (l) as l_value then
|
||||
s := l_value.representation
|
||||
assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST"))
|
||||
else
|
||||
assert ("LINKED_LIST converted to a JSON value", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_hash_table_converter
|
||||
local
|
||||
tc: JSON_HASH_TABLE_CONVERTER
|
||||
t: HASH_TABLE [STRING, STRING]
|
||||
t2: detachable HASH_TABLE [ANY, HASHABLE]
|
||||
s: STRING
|
||||
ucs_key, ucs_value: detachable STRING_32
|
||||
jv: detachable JSON_VALUE
|
||||
do
|
||||
create tc.make
|
||||
json.add_converter (tc)
|
||||
create t.make (2)
|
||||
t.put ("foo", "1")
|
||||
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
|
||||
end
|
||||
test_hash_table_converter
|
||||
-- Convert a hash table to a json value and
|
||||
-- convert this one to a hash table.
|
||||
local
|
||||
t: HASH_TABLE [STRING, STRING]
|
||||
s: STRING
|
||||
l_ucs_key: detachable STRING_32
|
||||
do
|
||||
create t.make (2)
|
||||
t.put ("foo", "1")
|
||||
t.put ("bar", "2")
|
||||
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.same_string_general ("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.same_string_general ("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 -- class TEST_DS
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,52 @@
|
||||
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
|
||||
|
||||
SHARED_EJSON
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
EQA_TEST_SET
|
||||
select default_create end
|
||||
|
||||
feature -- Test
|
||||
|
||||
test_custom_classes
|
||||
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
|
||||
create jbc.make
|
||||
json.add_converter (jbc)
|
||||
create jbcc.make
|
||||
json.add_converter (jbcc)
|
||||
create jac.make
|
||||
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
|
||||
|
||||
end
|
||||
test_custom_classes
|
||||
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
|
||||
local
|
||||
jbc: JSON_BOOK_CONVERTER
|
||||
jbcc: JSON_BOOK_COLLECTION_CONVERTER
|
||||
jac: JSON_AUTHOR_CONVERTER
|
||||
parser: JSON_PARSER
|
||||
jrep: STRING
|
||||
do
|
||||
create jbc.make
|
||||
json.add_converter (jbc)
|
||||
create jbcc.make
|
||||
json.add_converter (jbcc)
|
||||
create jac.make
|
||||
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)
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
note
|
||||
note
|
||||
description: "[
|
||||
Eiffel tests that can be executed by testing tool.
|
||||
]"
|
||||
@@ -33,8 +33,8 @@ feature -- Tests Pass
|
||||
do
|
||||
if attached json_file_from ("pass1.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("pass1.json",parse_json.is_parsed = True)
|
||||
parse_json.parse_content
|
||||
assert ("pass1.json", parse_json.is_valid)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,8 +45,8 @@ feature -- Tests Pass
|
||||
do
|
||||
if attached json_file_from ("pass2.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("pass2.json",parse_json.is_parsed = True)
|
||||
parse_json.parse_content
|
||||
assert ("pass2.json",parse_json.is_valid)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -57,8 +57,8 @@ feature -- Tests Pass
|
||||
do
|
||||
if attached json_file_from ("pass3.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("pass3.json",parse_json.is_parsed = True)
|
||||
parse_json.parse_content
|
||||
assert ("pass3.json",parse_json.is_valid)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,20 +68,16 @@ feature -- Tests Pass
|
||||
utf: UTF_CONVERTER
|
||||
s: READABLE_STRING_32
|
||||
do
|
||||
s := {STRING_32} "{ %"nihaoma%": %"你好吗\t?%" }"
|
||||
|
||||
s := {STRING_32} "{ %"nihaoma%": %"ä½ å¥½å—\t?%" }"
|
||||
parse_json := new_json_parser (utf.string_32_to_utf_8_string_8 (s))
|
||||
json_value := parse_json.parse_json
|
||||
assert ("utf8.pass1.json", parse_json.is_parsed = True)
|
||||
if
|
||||
attached {JSON_OBJECT} json_value as jo and then
|
||||
attached {JSON_STRING} jo.item ("nihaoma") as js
|
||||
then
|
||||
assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "你好吗%T?"))
|
||||
parse_json.parse_content
|
||||
assert ("utf8.pass1.json", parse_json.is_valid)
|
||||
if attached {JSON_OBJECT} parse_json.parsed_json_value as jo and then attached {JSON_STRING} jo.item ("nihaoma") as js then
|
||||
assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "ä½ å¥½å—%T?"))
|
||||
else
|
||||
assert ("utf8.nihaoma", False)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Tests Failures
|
||||
test_json_fail1
|
||||
@@ -91,8 +87,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail1.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail1.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail1.json", parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,8 +99,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail2.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail2.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail2.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -115,8 +111,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail3.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail3.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail3.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,8 +123,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail4.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail4.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail4.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -139,8 +135,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail5.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail5.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail5.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -152,8 +148,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail6.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail6.json",parse_json.is_parsed = False )
|
||||
parse_json.parse_content
|
||||
assert ("fail6.json",parse_json.is_valid = False )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -164,8 +160,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail7.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail7.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail7.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -176,8 +172,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail8.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail8.json",parse_json.is_parsed = False )
|
||||
parse_json.parse_content
|
||||
assert ("fail8.json",parse_json.is_valid = False )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -189,8 +185,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail9.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail9.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail9.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -202,8 +198,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail10.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail10.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail10.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -214,8 +210,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail11.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail11.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail11.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -226,8 +222,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail12.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail12.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail12.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -238,8 +234,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail13.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail13.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail13.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -250,8 +246,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail14.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail14.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail14.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -262,8 +258,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail15.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail15.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail15.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -274,8 +270,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail16.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail16.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail16.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -286,8 +282,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail17.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail17.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail17.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -298,8 +294,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail18.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail18.json",parse_json.is_parsed = True)
|
||||
parse_json.parse_content
|
||||
assert ("fail18.json",parse_json.is_valid = True)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -310,8 +306,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail19.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail19.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail19.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -322,8 +318,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail20.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail20.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail20.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -334,8 +330,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail21.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail21.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail21.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -347,8 +343,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail22.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail22.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail22.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -359,8 +355,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail23.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail23.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail23.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -371,8 +367,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail24.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail24.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail24.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -383,8 +379,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail25.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail25.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail25.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -396,8 +392,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail26.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail26.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail26.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -409,8 +405,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail27.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail27.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail27.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -422,8 +418,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail28.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail28.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail28.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -435,8 +431,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail29.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail29.json",parse_json.is_parsed = False )
|
||||
parse_json.parse_content
|
||||
assert ("fail29.json",parse_json.is_valid = False )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -448,8 +444,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail30.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail30.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail30.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -460,8 +456,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail31.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail31.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail31.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -472,8 +468,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail32.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail32.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail32.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -484,8 +480,8 @@ feature -- Tests Failures
|
||||
do
|
||||
if attached json_file_from ("fail33.json") as json_file then
|
||||
parse_json := new_json_parser (json_file)
|
||||
json_value := parse_json.parse_json
|
||||
assert ("fail33.json",parse_json.is_parsed = False)
|
||||
parse_json.parse_content
|
||||
assert ("fail33.json",parse_json.is_valid = False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -493,52 +489,47 @@ feature -- JSON_FROM_FILE
|
||||
|
||||
file_reader: JSON_FILE_READER
|
||||
|
||||
json_value: detachable JSON_VALUE
|
||||
|
||||
json_file_from (fn: STRING): detachable STRING
|
||||
local
|
||||
f: RAW_FILE
|
||||
l_path: STRING
|
||||
test_dir: STRING
|
||||
json_file_from (fn: READABLE_STRING_GENERAL): detachable STRING
|
||||
local
|
||||
f: RAW_FILE
|
||||
l_path: PATH
|
||||
test_dir: PATH
|
||||
i: INTEGER
|
||||
do
|
||||
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_directory
|
||||
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||
|
||||
l_path := test_dir + fn
|
||||
create f.make_with_name (l_path)
|
||||
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_path
|
||||
l_path := test_dir.extended (fn)
|
||||
create f.make_with_path (l_path)
|
||||
if f.exists then
|
||||
-- Found json file
|
||||
else
|
||||
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
|
||||
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
|
||||
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
|
||||
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
|
||||
from
|
||||
i := 5
|
||||
until
|
||||
i = 0
|
||||
loop
|
||||
test_dir.append_character ('.')
|
||||
test_dir.append_character ('.')
|
||||
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||
test_dir := test_dir.extended ("..")
|
||||
i := i - 1
|
||||
end
|
||||
l_path := test_dir + fn
|
||||
l_path := test_dir.extended (fn)
|
||||
end
|
||||
create f.make_with_name (l_path)
|
||||
create f.make_with_path (l_path)
|
||||
if f.exists then
|
||||
Result := file_reader.read_json_from (l_path)
|
||||
Result := file_reader.read_json_from (l_path.name)
|
||||
end
|
||||
assert ("File contains json data", Result /= Void)
|
||||
end
|
||||
assert ("File contains json data", Result /= Void)
|
||||
end
|
||||
|
||||
|
||||
new_json_parser (a_string: STRING): JSON_PARSER
|
||||
do
|
||||
create Result.make_parser (a_string)
|
||||
create Result.make_with_string (a_string)
|
||||
end
|
||||
|
||||
|
||||
invariant
|
||||
file_reader /= Void
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
|
||||
<target name="test_suite">
|
||||
<root cluster="test_suite" class="APPLICATION" feature="make"/>
|
||||
<file_rule>
|
||||
@@ -7,11 +7,11 @@
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="standard">
|
||||
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="transitional" syntax="standard">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="json" location="..\..\..\library\json-safe.ecf"/>
|
||||
<library name="json" location="..\..\..\library\json-safe.ecf" readonly="false"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<cluster name="test_suite" location=".\" recursive="true"/>
|
||||
</target>
|
||||
|
||||
Reference in New Issue
Block a user