From b69cbaedb02e68bc64b014c66fe9db8940710c5c Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Fri, 8 Feb 2013 10:39:16 +0100 Subject: [PATCH 1/8] Use Gobo FreeELKS version when GOBO_EIFFEL is ge --- library/json-safe.ecf | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/json-safe.ecf b/library/json-safe.ecf index b957513..8ec0685 100644 --- a/library/json-safe.ecf +++ b/library/json-safe.ecf @@ -14,15 +14,20 @@ - + + + + + + + + + + ^/gobo$ - ^/kernel$ - ^/extras$ - - From 6d0b8f28b1c0d125089fb32f99727f7db58b8611 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Fri, 8 Feb 2013 10:39:45 +0100 Subject: [PATCH 2/8] Fix gec compilation --- library/kernel/converters/json_hash_table_converter.e | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/kernel/converters/json_hash_table_converter.e b/library/kernel/converters/json_hash_table_converter.e index cf3f9cf..7b513b3 100644 --- a/library/kernel/converters/json_hash_table_converter.e +++ b/library/kernel/converters/json_hash_table_converter.e @@ -46,7 +46,7 @@ feature -- Conversion jv := j.item (keys [i]) if jv /= Void then a := json.object (jv, Void) - if a /= Void then + if a /= Void and h /= Void then Result.put (a, h) else check a_attached: a /= Void end From 0eeef65968a582984c0f8cf5bcb40eb5cd0ee2da Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Fri, 8 Feb 2013 10:40:13 +0100 Subject: [PATCH 3/8] Don't use TABLE_ITERABLE as it is not available in Gobo FreeELKS version --- library/kernel/json_object.e | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index e4a1619..c782052 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -22,8 +22,6 @@ class inherit JSON_VALUE - TABLE_ITERABLE [JSON_VALUE, JSON_STRING] - create make @@ -121,14 +119,6 @@ feature -- Mesurement Result := object.count end -feature -- Access - - new_cursor: TABLE_ITERATION_CURSOR [JSON_VALUE, JSON_STRING] - -- Fresh cursor associated with current structure - do - Result := object.new_cursor - end - feature -- Status report is_empty: BOOLEAN From 26ac74f27da48f15a4f4700ccb0112820260c072 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Sun, 21 Apr 2013 12:20:35 +0200 Subject: [PATCH 4/8] Reuse TABLE_ITERABLE as it is now available in Gobo FreeELKS version This reverts commit 0eeef65968a582984c0f8cf5bcb40eb5cd0ee2da. --- library/kernel/json_object.e | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index c782052..e4a1619 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -22,6 +22,8 @@ class inherit JSON_VALUE + TABLE_ITERABLE [JSON_VALUE, JSON_STRING] + create make @@ -119,6 +121,14 @@ feature -- Mesurement Result := object.count end +feature -- Access + + new_cursor: TABLE_ITERATION_CURSOR [JSON_VALUE, JSON_STRING] + -- Fresh cursor associated with current structure + do + Result := object.new_cursor + end + feature -- Status report is_empty: BOOLEAN From 83cfdcf94f01b0d7da97ba2db41793eb4176bd90 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Wed, 8 May 2013 08:56:27 +0200 Subject: [PATCH 5/8] Revert "removed "getest" since it is duplication with autotest (and we use mainly the later for regression testing)" This reverts commit b6464cf5e7dbbd82322de59a3c1f87b9bfd2913a. --- test/getest/author.e | 24 + test/getest/book.e | 40 ++ test/getest/book_collection.e | 82 +++ test/getest/ec_compile.bat | 11 + test/getest/ec_compile.sh | 5 + test/getest/ejson_test-win.cfg | 17 + test/getest/ejson_test.cfg | 17 + test/getest/ejson_test.ecf | 21 + test/getest/json_author_converter.e | 55 ++ test/getest/json_book_collection_converter.e | 80 +++ test/getest/json_book_converter.e | 74 ++ test/getest/readme.txt | 10 + test/getest/test_ds.e | 71 ++ test/getest/test_json_core.e | 703 +++++++++++++++++++ test/getest/test_json_custom_classes.e | 49 ++ 15 files changed, 1259 insertions(+) create mode 100644 test/getest/author.e create mode 100644 test/getest/book.e create mode 100644 test/getest/book_collection.e create mode 100644 test/getest/ec_compile.bat create mode 100755 test/getest/ec_compile.sh create mode 100644 test/getest/ejson_test-win.cfg create mode 100644 test/getest/ejson_test.cfg create mode 100644 test/getest/ejson_test.ecf create mode 100644 test/getest/json_author_converter.e create mode 100644 test/getest/json_book_collection_converter.e create mode 100644 test/getest/json_book_converter.e create mode 100644 test/getest/readme.txt create mode 100644 test/getest/test_ds.e create mode 100644 test/getest/test_json_core.e create mode 100644 test/getest/test_json_custom_classes.e diff --git a/test/getest/author.e b/test/getest/author.e new file mode 100644 index 0000000..ee78d24 --- /dev/null +++ b/test/getest/author.e @@ -0,0 +1,24 @@ +class AUTHOR + +create + make + +feature {NONE} -- Initialization + + make (a_name: UC_STRING) is + do + set_name (a_name) + end + +feature -- Access + + name: UC_STRING + +feature -- Status setting + + set_name (a_name: UC_STRING) is + do + name := a_name + end + +end -- class AUTHOR diff --git a/test/getest/book.e b/test/getest/book.e new file mode 100644 index 0000000..6ea5774 --- /dev/null +++ b/test/getest/book.e @@ -0,0 +1,40 @@ +class BOOK + +create + make + +feature {NONE} -- Initialization + + make (a_title: UC_STRING; an_author: AUTHOR; an_isbn: UC_STRING) is + do + set_title (a_title) + set_author (an_author) + set_isbn (an_isbn) + end + +feature -- Access + + title: UC_STRING + + isbn: UC_STRING + + author: AUTHOR + +feature -- Status setting + + set_title (a_title: UC_STRING) is + do + title := a_title + end + + set_author (an_author: AUTHOR) is + do + author := an_author + end + + set_isbn (an_isbn: UC_STRING) is + do + isbn := an_isbn + end + +end -- class BOOK diff --git a/test/getest/book_collection.e b/test/getest/book_collection.e new file mode 100644 index 0000000..be75869 --- /dev/null +++ b/test/getest/book_collection.e @@ -0,0 +1,82 @@ +class BOOK_COLLECTION + +create + make + +feature {NONE} -- Initialization + + make (a_name: UC_STRING) is + do + set_name (a_name) + create book_index.make (10) + end + +feature -- Access + + name: UC_STRING + + books: DS_LIST [BOOK] is + local + c: DS_HASH_TABLE_CURSOR [DS_LIST [BOOK], UC_STRING] + do + from + create {DS_LINKED_LIST [BOOK]} Result.make + c := book_index.new_cursor + c.start + until + c.after + loop + Result.append_last (c.item) + c.forth + end + end + + books_by_author (an_author: UC_STRING): DS_LIST [BOOK] is + do + if book_index.has (an_author) then + Result := book_index @ an_author + else + create {DS_LINKED_LIST [BOOK]} Result.make + end + end + +feature -- Status setting + + set_name (a_name: UC_STRING) is + do + name := a_name + end + + add_book (a_book: BOOK) is + local + l: DS_LIST [BOOK] + do + if book_index.has (a_book.author.name) then + l := book_index @ a_book.author.name + else + create {DS_LINKED_LIST [BOOK]} l.make + book_index.put (l, a_book.author.name) + end + l.put_last (a_book) + end + + add_books (book_list: like books) is + local + c: DS_LIST_CURSOR [BOOK] + do + from + c := book_list.new_cursor + c.start + until + c.after + loop + add_book (c.item) + c.forth + end + end + +feature {NONE} -- Implementation + + book_index: DS_HASH_TABLE [DS_LIST [BOOK], UC_STRING] + +end -- class BOOK_COLLECTION diff --git a/test/getest/ec_compile.bat b/test/getest/ec_compile.bat new file mode 100644 index 0000000..1d90e40 --- /dev/null +++ b/test/getest/ec_compile.bat @@ -0,0 +1,11 @@ +echo Compiling ejson_test (finalized) +ecb -finalize -c_compile -config ejson_test.ecf -batch -clean > NUL 2>&1 +IF %ERRORLEVEL% EQU -1 goto ERROR +copy EIFGENs\ejson_test\F_code\ejson_test.exe ejson_test.exe +goto EOF + +:ERROR +echo Error occurred during ejson_test compilation +goto EOF + +:EOF diff --git a/test/getest/ec_compile.sh b/test/getest/ec_compile.sh new file mode 100755 index 0000000..08dcd61 --- /dev/null +++ b/test/getest/ec_compile.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "ec -finalize -c_compile -config ejson_test.ecf > /dev/null 2>&1" +ec -finalize -c_compile -config ejson_test.ecf > /dev/null 2>&1 +cp EIFGENs/ejson_test/F_code/ejson_test . diff --git a/test/getest/ejson_test-win.cfg b/test/getest/ejson_test-win.cfg new file mode 100644 index 0000000..9c905c2 --- /dev/null +++ b/test/getest/ejson_test-win.cfg @@ -0,0 +1,17 @@ +-- Gobo test (getest) configuration file for eJSON + +test + ejson_test + +default + class ("TEST_[A-Z0-9_]*") + feature ("test_[a-z0-9_]*") + prefix ("X") + testgen ("TESTGEN") + compile ("ec_compile.bat") + execute ("ejson_test.exe") + +cluster + test_dir: "." + +end diff --git a/test/getest/ejson_test.cfg b/test/getest/ejson_test.cfg new file mode 100644 index 0000000..078526a --- /dev/null +++ b/test/getest/ejson_test.cfg @@ -0,0 +1,17 @@ +-- Gobo test (getest) configuration file for eJSON + +test + ejson_test + +default + class ("TEST_[A-Z0-9_]*") + feature ("test_[a-z0-9_]*") + prefix ("X") + testgen ("TESTGEN") + compile ("./ec_compile.sh") + execute ("./ejson_test") + +cluster + test_dir: "." + +end diff --git a/test/getest/ejson_test.ecf b/test/getest/ejson_test.ecf new file mode 100644 index 0000000..d302b74 --- /dev/null +++ b/test/getest/ejson_test.ecf @@ -0,0 +1,21 @@ + + + + + + //.svn + /cvs$ + /EIFGENs$ + + + + + + + + + + + diff --git a/test/getest/json_author_converter.e b/test/getest/json_author_converter.e new file mode 100644 index 0000000..80044e7 --- /dev/null +++ b/test/getest/json_author_converter.e @@ -0,0 +1,55 @@ +indexing + description: "A JSON converter for AUTHOR" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" + +class JSON_AUTHOR_CONVERTER + +inherit + JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make is + local + ucs: UC_STRING + do + create ucs.make_from_string ("") + create object.make (ucs) + end + +feature -- Access + + value: JSON_OBJECT + + object: AUTHOR + +feature -- Conversion + + from_json (j: like value): like object is + local + ucs: UC_STRING + do + ucs ?= json.object (j.item (name_key), Void) + check ucs /= Void end + create Result.make (ucs) + end + + to_json (o: like object): like value is + do + create Result.make + Result.put (json.value (o.name), name_key) + end + +feature {NONE} -- Implementation + + name_key: JSON_STRING is + once + create Result.make_json ("name") + end + +end -- class JSON_AUTHOR_CONVERTER diff --git a/test/getest/json_book_collection_converter.e b/test/getest/json_book_collection_converter.e new file mode 100644 index 0000000..00cc2b7 --- /dev/null +++ b/test/getest/json_book_collection_converter.e @@ -0,0 +1,80 @@ +indexing + description: "A JSON converter for BOOK_COLLECTION" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" + +class JSON_BOOK_COLLECTION_CONVERTER + +inherit + JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make is + local + ucs: UC_STRING + do + create ucs.make_from_string ("") + create object.make (ucs) + end + +feature -- Access + + value: JSON_OBJECT + + object: BOOK_COLLECTION + +feature -- Conversion + + from_json (j: like value): like object is + local + ucs: UC_STRING + ll: DS_LINKED_LIST [BOOK] + b: BOOK + ja: 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.put_last (b) + i := i + 1 + end + check ll /= Void end + Result.add_books (ll) + end + + to_json (o: like object): like value is + do + create Result.make + Result.put (json.value (o.name), name_key) + Result.put (json.value (o.books), books_key) + end + +feature {NONE} -- Implementation + + name_key: JSON_STRING is + once + create Result.make_json ("name") + end + + books_key: JSON_STRING is + once + create Result.make_json ("books") + end + +end -- class JSON_BOOK_COLLECTION_CONVERTER diff --git a/test/getest/json_book_converter.e b/test/getest/json_book_converter.e new file mode 100644 index 0000000..53a50dc --- /dev/null +++ b/test/getest/json_book_converter.e @@ -0,0 +1,74 @@ +indexing + description: "A JSON converter for BOOK" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" + +class JSON_BOOK_CONVERTER + +inherit + JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make is + local + ucs: UC_STRING + a: AUTHOR + do + create ucs.make_from_string ("") + create a.make (ucs) + create object.make (ucs, a, ucs) + end + +feature -- Access + + value: JSON_OBJECT + + object: BOOK + +feature -- Conversion + + from_json (j: like value): like object is + local + ucs1, ucs2: UC_STRING + a: 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 + + to_json (o: like object): like value is + 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 + +feature {NONE} -- Implementation + + title_key: JSON_STRING is + once + create Result.make_json ("title") + end + + isbn_key: JSON_STRING is + once + create Result.make_json ("isbn") + end + + author_key: JSON_STRING is + once + create Result.make_json ("author") + end + +end -- class JSON_BOOK_CONVERTER diff --git a/test/getest/readme.txt b/test/getest/readme.txt new file mode 100644 index 0000000..5629442 --- /dev/null +++ b/test/getest/readme.txt @@ -0,0 +1,10 @@ +To compile and run the test program do as follows: + +1. Make sure you have a compiled version of getest in your PATH. + +2. In this dircetory, run the command: + + $ getest --verbose --ise ejson_test.cfg + + +Note: on Windows, you should use ejson_test-win.cfg \ No newline at end of file diff --git a/test/getest/test_ds.e b/test/getest/test_ds.e new file mode 100644 index 0000000..b86e2cf --- /dev/null +++ b/test/getest/test_ds.e @@ -0,0 +1,71 @@ +class TEST_DS + +inherit + SHARED_GOBO_EJSON + + TS_TEST_CASE + +create + make_default + +feature {NONE} -- Initialization + + make is + -- Create test object. + do + end + +feature -- Test + + test_ds_linked_list_converter is + local + jc: JSON_DS_LINKED_LIST_CONVERTER + l: DS_LINKED_LIST [STRING] + l2: DS_LINKED_LIST [ANY] + s: STRING + jv: JSON_VALUE + do + create jc.make + json.add_converter (jc) + create l.make + s := "foo" + l.put_last (s) + s := "bar" + l.put_last (s) + jv := json.value (l) + assert ("jv /= Void", jv /= Void) + s := jv.representation + l2 ?= json.object (jv, "DS_LINKED_LIST") + assert ("l2 /= Void", l2 /= Void) + end + + test_ds_hash_table_converter is + local + tc: JSON_DS_HASH_TABLE_CONVERTER + t: DS_HASH_TABLE [STRING, STRING] + t2: DS_HASH_TABLE [ANY, HASHABLE] + s: STRING + ucs_key, ucs_value: UC_STRING + jv: 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) + s := jv.representation + t2 ?= json.object (jv, "DS_HASH_TABLE") + assert ("t2 /= Void", t2 /= Void) + create ucs_key.make_from_string ("1") + ucs_value ?= t2 @ ucs_key + assert ("ucs_value /= Void", ucs_value /= Void) + assert ("ucs_value.string.is_equal (%"foo%")", ucs_value.string.is_equal ("foo")) + create ucs_key.make_from_string ("2") + ucs_value ?= t2 @ ucs_key + assert ("ucs_value /= Void", ucs_value /= Void) + assert ("ucs_value.string.is_equal (%"bar%")", ucs_value.string.is_equal ("bar")) + end + +end -- class TEST_DS diff --git a/test/getest/test_json_core.e b/test/getest/test_json_core.e new file mode 100644 index 0000000..d1efa5b --- /dev/null +++ b/test/getest/test_json_core.e @@ -0,0 +1,703 @@ +class TEST_JSON_CORE + +inherit + TS_TEST_CASE + SHARED_EJSON + +create + make_default + +feature {NONE} -- Initialization + + make is + -- Create test object. + do + end + +feature -- Test + + test_json_number_and_integer is + local + i: INTEGER + i8: INTEGER_8 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + i := 42 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_integer (i) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn := Void + jn ?= json.value (i) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + -- JSON representation-> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_8 since the value is 42 + jrep := "42" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i8 := 0 + i8 ?= json.object (jn, Void) + assert ("i8 = 42", i8 = 42) + end + + test_json_number_and_integer_8 is + local + i8: INTEGER_8 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + i8 := 42 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_integer (i8) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn := Void + jn ?= json.value (i8) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_8 since the value is 42 + jrep := "42" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i8 := 0 + i8 ?= json.object (jn, Void) + assert ("i8 = 42", i8 = 42) + end + + test_json_number_and_integer_16 is + local + i16: INTEGER_16 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + i16 := 300 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_integer (i16) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"300%")", jn.representation.is_equal ("300")) + -- Eiffel value -> JSON with factory + jn := Void + jn ?= json.value (i16) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"300%")", jn.representation.is_equal ("300")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_16 since the value is 300 + jrep := "300" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i16 := 0 + i16 ?= json.object (jn, Void) + assert ("i16 = 300", i16 = 300) + end + + test_json_number_and_integer_32 is + local + i32: INTEGER_32 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + i32 := 100000 + -- Eiffel value -> JSON representation -> JSON value + create jn.make_integer (i32) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"100000%")", jn.representation.is_equal ("100000")) + -- Eiffel value -> JSON representation -> JSON value with factory + jn := Void + jn ?= json.value (i32) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"100000%")", jn.representation.is_equal ("100000")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_32 since the value is 100000 + jrep := "100000" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i32 := 0 + i32 ?= json.object (jn, Void) + assert ("i32 = 100000", i32 = 100000) + end + + test_json_number_and_integer_64 is + local + i64: INTEGER_64 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + i64 := 42949672960 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_integer (i64) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"42949672960%")", jn.representation.is_equal ("42949672960")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn := Void + jn ?= json.value (i64) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"42949672960%")", jn.representation.is_equal ("42949672960")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_32 since the value is 42949672960 + jrep := "42949672960" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i64 := 0 + i64 ?= json.object (jn, Void) + assert ("i64 = 42949672960", i64 = 42949672960) + end + + test_json_number_and_natural_8 is + local + n8: NATURAL_8 + i16: INTEGER_16 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + n8 := 200 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n8) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"200%")", jn.representation.is_equal ("200")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn := Void + jn ?= json.value (n8) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"200%")", jn.representation.is_equal ("200")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_16 since the value is 200 + jrep := "200" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i16 := 0 + i16 ?= json.object (jn, Void) + assert ("i16 = 200", i16 = 200) + end + + test_json_number_and_natural_16 is + local + n16: NATURAL_16 + i32: INTEGER_32 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + n16 := 32768 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n16) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"32768%")", jn.representation.is_equal ("32768")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn := Void + jn ?= json.value (n16) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"32768%")", jn.representation.is_equal ("32768")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_32 since the value is 32768 + jrep := "32768" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i32 := 0 + i32 ?= json.object (jn, Void) + assert ("i32 = 32768", i32 = 32768) + end + + test_json_number_and_natural_32 is + local + n32: NATURAL_32 + i64: INTEGER_64 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + n32 := 2147483648 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n32) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"2147483648%")", jn.representation.is_equal ("2147483648")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn := Void + jn ?= json.value (n32) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"2147483648%")", jn.representation.is_equal ("2147483648")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_64 since the value is 2147483648 + jrep := "2147483648" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + i64 := 0 + i64 ?= json.object (jn, Void) + assert ("i64 = 2147483648", i64 = 2147483648) + end + + test_json_number_and_large_integers is + local + jrep: STRING + jn: JSON_NUMBER + n64: NATURAL_64 + parser: JSON_PARSER + do + n64 := 9223372036854775808 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n64) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"9223372036854775808%")", jn.representation.is_equal ("9223372036854775808")) + jn := Void + -- Eiffel value -> JSON value -> JSON representation with factory + jn ?= json.value (n64) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"9223372036854775808%")", jn.representation.is_equal ("9223372036854775808")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- we know it is INTEGER_32 since the value is 42949672960 + jrep := "9223372036854775808" -- 1 higher than largest positive number that can be represented by INTEGER 64 + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + n64 := 0 + n64 ?= json.object (jn, Void) + end + + test_json_number_and_eiffel_real is + local + r: REAL + r64: REAL_64 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + r := 3.14 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_real (r) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn ?= json.value (r) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will always return a REAL_64 if the value + -- of the JSON number is a floating point number + jrep := "3.14" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + r64 := 0 + r64 ?= json.object (jn, Void) + assert ("r64 = 3.1400000000000001", r64 = 3.1400000000000001) + end + + test_json_number_and_eiffel_real_32 is + local + r32: REAL_32 + r64: REAL_64 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + r32 := 3.14 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_real (r32) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn ?= json.value (r32) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "3.1400001049041748" + create parser.make_parser (jrep) + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + r64 := 0 + r64 ?= json.object (jn, Void) + assert ("r64 = 3.1400001049041748", r64 = 3.1400001049041748) + end + + test_json_number_and_eiffel_real_64 is + local + r64: REAL_64 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + r64 := 3.1415926535897931 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_real (r64) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"3.1415926535897931%")", jn.representation.is_equal ("3.1415926535897931")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn ?= json.value (r64) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"3.1415926535897931%")", jn.representation.is_equal ("3.1415926535897931")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "3.1415926535897931" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + r64 := 0 + r64 ?= json.object (jn, Void) + assert ("r64 = 3.1415926535897931", r64 = 3.1415926535897931) + end + + test_json_boolean is + local + b: BOOLEAN + jb: JSON_BOOLEAN + jrep: STRING + parser: JSON_PARSER + do + b := True + -- Eiffel value -> JSON value -> JSON representation + create jb.make_boolean (b) + assert ("jb /= Void", jb /= Void) + assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true")) + -- Eiffel value -> JSON value -> JSON representation with factory + jb ?= json.value (b) + assert ("jb /= Void", jb /= Void) + assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "true" + create parser.make_parser (jrep) + jb := Void + jb ?= parser.parse + assert ("jb /= Void", jb /= Void) + b := False + b ?= json.object (jb, Void) + assert ("b = True", b = True) + + b := False + -- Eiffel value -> JSON value -> JSON representation + create jb.make_boolean (b) + assert ("jb /= Void", jb /= Void) + assert ("jb.representation.is_equal (%"false%")", jb.representation.is_equal ("false")) + -- Eiffel value -> JSON value -> JSON representation with factory + jb ?= json.value (b) + assert ("jb /= Void", jb /= Void) + assert ("jb.representation.is_equal (%"false%")", jb.representation.is_equal ("false")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "false" + create parser.make_parser (jrep) + jb := Void + jb ?= parser.parse + assert ("jb /= Void", jb /= Void) + b := True + b ?= json.object (jb, Void) + assert ("b = False", b = False) + end + + test_json_null is + local + a: ANY + dummy_object: STRING + jn: JSON_NULL + jrep: STRING + parser: JSON_PARSER + do + -- Eiffel value -> JSON value -> JSON representation + create jn + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal ("null")) + -- Eiffel value -> JSON value -> JSON representation with factory + jn ?= json.value (Void) + assert ("jn /= Void", jn /= Void) + assert ("jn.representation.is_equal (%"null%")", jn.representation.is_equal ("null")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "null" + create parser.make_parser (jrep) + jn := Void + jn ?= parser.parse + assert ("jn /= Void", jn /= Void) + create dummy_object.make_empty + a := dummy_object + a ?= json.object (jn, Void) + assert ("a = Void", a = Void) + end + + test_json_string_and_character is + local + c: CHARACTER + js: JSON_STRING + ucs: UC_STRING + jrep: STRING + parser: JSON_PARSER + do + c := 'a' + -- Eiffel value -> JSON value -> JSON representation + create js.make_json (c.out) + assert ("js /= Void", js /= Void) + assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%"")) + -- Eiffel value -> JSON value -> JSON representation with factory + js ?= json.value (c) + assert ("js /= Void", js /= Void) + assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%"")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "%"a%"" + create parser.make_parser (jrep) + js := Void + js ?= parser.parse + assert ("js /= Void", js /= Void) + ucs ?= json.object (js, Void) + assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a")) + end + + test_json_string_and_string is + local + s: STRING + js: JSON_STRING + ucs: UC_STRING + jrep: STRING + parser: JSON_PARSER + do + s := "foobar" + -- Eiffel value -> JSON value -> JSON representation + create js.make_json (s) + assert ("js /= Void", js /= Void) + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + -- Eiffel value -> JSON value -> JSON representation with factory + js ?= json.value (s) + assert ("js /= Void", js /= Void) + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "%"foobar%"" + create parser.make_parser (jrep) + js := Void + js ?= parser.parse + assert ("js /= Void", js /= Void) + ucs ?= json.object (js, Void) + assert ("ucs.string.is_equal (%"foobar%")", ucs.string.is_equal ("foobar")) + end + + test_json_string_and_uc_string is + local + js: JSON_STRING + ucs: UC_STRING + jrep: STRING + parser: JSON_PARSER + do + create ucs.make_from_string ("foobar") + -- Eiffel value -> JSON value -> JSON representation + create js.make_json (ucs) + assert ("js /= Void", js /= Void) + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + -- Eiffel value -> JSON value -> JSON representation with factory + js ?= json.value (ucs) + assert ("js /= Void", js /= Void) + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + -- JSON representation -> JSON value -> Eiffel value + jrep := "%"foobar%"" + create parser.make_parser (jrep) + js := Void + js ?= parser.parse + assert ("js /= Void", js /= Void) + ucs := Void + ucs ?= json.object (js, Void) + assert ("ucs.string.is_equal (%"foobar%")", ucs.string.is_equal ("foobar")) + end + + test_json_array is + local + ll: LINKED_LIST [INTEGER_8] + ll2: LINKED_LIST [ANY] + ja: JSON_ARRAY + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + i, n: INTEGER + do + -- Eiffel value -> JSON value -> JSON representation + create ll.make + ll.extend (0) + ll.extend (1) + ll.extend (1) + ll.extend (2) + ll.extend (3) + ll.extend (5) + -- Note: Currently there is no simple way of creating a JSON_ARRAY + -- from an LINKED_LIST. + create ja.make_array + from + ll.start + until + ll.after + loop + create jn.make_integer (ll.item) + ja.add (jn) + ll.forth + end + 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]")) + -- Eiffel value -> JSON value -> JSON representation with factory + ja := Void + ja ?= json.value (ll) + 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]")) + -- JSON representation -> JSON value -> Eiffel value + -- Note: The JSON_FACTORY will return the smallest INTEGER_* object + -- that can represent the value of the JSON number, in this case + -- it means we will get an LINKED_LIST [ANY] containing the INTEGER_8 + -- values 0, 1, 1, 2, 3, 5 + jrep := "[0,1,1,2,3,5]" + create parser.make_parser (jrep) + ja := Void + ja ?= parser.parse + assert ("ja /= Void", ja /= Void) + ll2 ?= json.object (ja, Void) + assert ("ll2 /= Void", ll2 /= Void) + --ll.compare_objects + --ll2.compare_objects + assert ("ll2.is_equal (ll)", ll2.is_equal (ll)) + end + + test_json_object is + local + t, t2: HASH_TABLE [ANY, UC_STRING] + i: INTEGER + ucs_key, ucs: UC_STRING + a: ARRAY [INTEGER] + jo: JSON_OBJECT + jn: JSON_NUMBER + js_key, js: JSON_STRING + ja: JSON_ARRAY + jrep: STRING + parser: JSON_PARSER + do + -- Eiffel value -> JSON value -> JSON representation + -- Note: Currently there is now way of creating a JSON_OBJECT from + -- a DS_HASH_TABLE, so we do it manually. + -- t = {"name": "foobar", "size": 42, "contents", [0, 1, 1, 2, 3, 5]} + create jo.make + create js_key.make_json ("name") + create js.make_json ("foobar") + jo.put (js, js_key) + create js_key.make_json ("size") + create jn.make_integer (42) + jo.put (jn, js_key) + create js_key.make_json ("contents") + create ja.make_array + create jn.make_integer (0) + ja.add (jn) + create jn.make_integer (1) + ja.add (jn) + create jn.make_integer (1) + ja.add (jn) + create jn.make_integer (2) + ja.add (jn) + create jn.make_integer (3) + ja.add (jn) + create jn.make_integer (5) + ja.add (jn) + jo.put (ja, js_key) + assert ("jo /= Void", jo /= Void) + assert ("jo.representation.is_equal (%"{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}%")", jo.representation.is_equal ("{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}")) + -- Eiffel value -> JSON value -> JSON representation with factory + create t.make (3) + create ucs_key.make_from_string ("name") + create ucs.make_from_string ("foobar") + t.put (ucs, ucs_key) + create ucs_key.make_from_string ("size") + i := 42 + t.put (i, ucs_key) + create ucs_key.make_from_string ("contents") + a := <<0, 1, 1, 2, 3, 5>> + t.put (a, ucs_key) + jo := Void + jo ?= json.value (t) + assert ("jo /= Void", jo /= Void) + assert ("jo.representation.is_equal (%"{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}%")", jo.representation.is_equal ("{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}")) + -- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation + jrep := "{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}" + create parser.make_parser (jrep) + jo := Void + jo ?= parser.parse + assert ("jo /= Void", jo /= Void) + t2 ?= json.object (jo, Void) + assert ("t2 /= Void", t2 /= Void) + jo ?= json.value (t2) + assert ("jo /= Void", jo /= Void) + assert ("jrep.is_equal (jo.representation)", jrep.is_equal (jo.representation)) + end + + test_json_failed_json_conversion is + -- Test converting an Eiffel object to JSON that is based on a class + -- for which no JSON converter has been registered. + local + gv: KL_GOBO_VERSION + jv: JSON_VALUE + exception: BOOLEAN + do + if not exception then + create gv + jv := json.value (gv) + else + assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) + assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: KL_GOBO_VERSION")) + end + rescue + exception := True + retry + end + + test_json_failed_eiffel_conversion is + -- Test converting from a JSON value to an Eiffel object based on a + -- class for which no JSON converter has been registered. + local + gv: KL_GOBO_VERSION + jo: JSON_OBJECT + exception: BOOLEAN + do + if not exception then + create jo.make + gv ?= json.object (jo, "KL_GOBO_VERSION") + else + assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) + assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> KL_GOBO_VERSION")) + end + rescue + exception := True + retry + end + +end -- class TEST_JSON_CORE diff --git a/test/getest/test_json_custom_classes.e b/test/getest/test_json_custom_classes.e new file mode 100644 index 0000000..e9d99d2 --- /dev/null +++ b/test/getest/test_json_custom_classes.e @@ -0,0 +1,49 @@ +class TEST_JSON_CUSTOM_CLASSES + +inherit + SHARED_EJSON + + TS_TEST_CASE + +create + make_default + +feature {NONE} -- Initialization + + make is + -- Create test object. + do + end + +feature -- Test + + test_custom_classes is + local + bc: BOOK_COLLECTION + jbc: JSON_BOOK_CONVERTER + jbcc: JSON_BOOK_COLLECTION_CONVERTER + jac: JSON_AUTHOR_CONVERTER + jo: 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) + assert ("JSON representation is correct", jo.representation.is_equal ("{%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}],%"name%":%"Test collection%"}")) + end + +end -- class TEST_JSON_CUSTOM_CLASS From 79cbf8c737ce52bf158d7d1e748f72d8da1d0eb9 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Wed, 8 May 2013 14:41:42 +0200 Subject: [PATCH 6/8] getest: all test cases now passes again This commit also introduces a new JSON converter for UC_STRING: JSON_UC_STRING_CONVERTER. This converter is especially used in the JSON DS_HASH_TABLE converter to retrieve UC_STRING instances instead of STRING_32. Some more ecf files now use Gobo FreeELKS version when GOBO_EIFFEL is ge. Note that we can't run the tests using gec for now as the ecf used for Gobo (which are shipped with EiffelStudio) don't use the Gobo FreeELKS version (they use the ISE version) --- .gitignore | 1 + .../converters/json_ds_hash_table_converter.e | 8 ++ .../converters/json_uc_string_converter.e | 39 ++++++ library/json.ecf | 11 +- library/json_gobo_extension.ecf | 12 +- test/getest/author.e | 4 +- test/getest/book.e | 8 +- test/getest/book_collection.e | 12 +- test/getest/ejson_test.ecf | 14 ++- test/getest/json_author_converter.e | 28 ++--- test/getest/json_book_collection_converter.e | 30 ++--- test/getest/json_book_converter.e | 34 +++--- test/getest/test_ds.e | 13 +- test/getest/test_json_core.e | 112 +++++++++--------- test/getest/test_json_custom_classes.e | 15 +-- 15 files changed, 211 insertions(+), 130 deletions(-) create mode 100644 library/gobo/converters/json_uc_string_converter.e diff --git a/.gitignore b/.gitignore index a1ff1e8..2d6cae2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp EIFGENs +TESTGEN diff --git a/library/gobo/converters/json_ds_hash_table_converter.e b/library/gobo/converters/json_ds_hash_table_converter.e index 9f244fe..43da59a 100644 --- a/library/gobo/converters/json_ds_hash_table_converter.e +++ b/library/gobo/converters/json_ds_hash_table_converter.e @@ -34,9 +34,11 @@ feature -- Conversion i: INTEGER h: HASHABLE a: ANY + ucs: UC_STRING do keys := j.current_keys create Result.make (keys.count) + create ucs.make_empty from i := 1 until @@ -44,7 +46,13 @@ feature -- Conversion loop h ?= json.object (keys [i], void) check h /= Void end + if attached {STRING_32} h and attached Json.converter_for (ucs) then + h ?= json.object (keys [i], ucs.generator) + end a := json.object (j.item (keys [i]), Void) + if attached {STRING_32} a and attached Json.converter_for (ucs) then + a := json.object (j.item (keys [i]), ucs.generator) + end Result.put (a, h) i := i + 1 end diff --git a/library/gobo/converters/json_uc_string_converter.e b/library/gobo/converters/json_uc_string_converter.e new file mode 100644 index 0000000..25de837 --- /dev/null +++ b/library/gobo/converters/json_uc_string_converter.e @@ -0,0 +1,39 @@ +note + description: "JSON UC_STRING converter." + author: "Olivier Ligot" + +class + JSON_UC_STRING_CONVERTER + +inherit + JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make (0) + end + +feature -- Access + + value: JSON_STRING + + object: UC_STRING + +feature -- Conversion + + from_json (j: like value): like object + do + create Result.make_from_string_general (j.unescaped_string_32) + end + + to_json (o: like object): like value + do + create Result.make_json_from_string_32 (o.as_string_32) + end + +end diff --git a/library/json.ecf b/library/json.ecf index ee954e0..4365261 100644 --- a/library/json.ecf +++ b/library/json.ecf @@ -14,7 +14,16 @@ - + + + + + + + + + + ^/gobo$ diff --git a/library/json_gobo_extension.ecf b/library/json_gobo_extension.ecf index dd5f9b7..700e8c6 100644 --- a/library/json_gobo_extension.ecf +++ b/library/json_gobo_extension.ecf @@ -9,8 +9,18 @@ - + + + + + + + + + + + diff --git a/test/getest/author.e b/test/getest/author.e index ee78d24..f150365 100644 --- a/test/getest/author.e +++ b/test/getest/author.e @@ -5,7 +5,7 @@ create feature {NONE} -- Initialization - make (a_name: UC_STRING) is + make (a_name: UC_STRING) do set_name (a_name) end @@ -16,7 +16,7 @@ feature -- Access feature -- Status setting - set_name (a_name: UC_STRING) is + set_name (a_name: UC_STRING) do name := a_name end diff --git a/test/getest/book.e b/test/getest/book.e index 6ea5774..5681221 100644 --- a/test/getest/book.e +++ b/test/getest/book.e @@ -5,7 +5,7 @@ create feature {NONE} -- Initialization - make (a_title: UC_STRING; an_author: AUTHOR; an_isbn: UC_STRING) is + make (a_title: UC_STRING; an_author: AUTHOR; an_isbn: UC_STRING) do set_title (a_title) set_author (an_author) @@ -22,17 +22,17 @@ feature -- Access feature -- Status setting - set_title (a_title: UC_STRING) is + set_title (a_title: UC_STRING) do title := a_title end - set_author (an_author: AUTHOR) is + set_author (an_author: AUTHOR) do author := an_author end - set_isbn (an_isbn: UC_STRING) is + set_isbn (an_isbn: UC_STRING) do isbn := an_isbn end diff --git a/test/getest/book_collection.e b/test/getest/book_collection.e index be75869..1b6db0f 100644 --- a/test/getest/book_collection.e +++ b/test/getest/book_collection.e @@ -5,7 +5,7 @@ create feature {NONE} -- Initialization - make (a_name: UC_STRING) is + make (a_name: UC_STRING) do set_name (a_name) create book_index.make (10) @@ -15,7 +15,7 @@ feature -- Access name: UC_STRING - books: DS_LIST [BOOK] is + books: DS_LIST [BOOK] local c: DS_HASH_TABLE_CURSOR [DS_LIST [BOOK], UC_STRING] do @@ -31,7 +31,7 @@ feature -- Access end end - books_by_author (an_author: UC_STRING): DS_LIST [BOOK] is + books_by_author (an_author: UC_STRING): DS_LIST [BOOK] do if book_index.has (an_author) then Result := book_index @ an_author @@ -42,12 +42,12 @@ feature -- Access feature -- Status setting - set_name (a_name: UC_STRING) is + set_name (a_name: UC_STRING) do name := a_name end - add_book (a_book: BOOK) is + add_book (a_book: BOOK) local l: DS_LIST [BOOK] do @@ -60,7 +60,7 @@ feature -- Status setting l.put_last (a_book) end - add_books (book_list: like books) is + add_books (book_list: like books) local c: DS_LIST_CURSOR [BOOK] do diff --git a/test/getest/ejson_test.ecf b/test/getest/ejson_test.ecf index d302b74..c8b6252 100644 --- a/test/getest/ejson_test.ecf +++ b/test/getest/ejson_test.ecf @@ -7,13 +7,23 @@ /cvs$ /EIFGENs$ - - + + + + + + + + + + + diff --git a/test/getest/json_author_converter.e b/test/getest/json_author_converter.e index 80044e7..36f06cd 100644 --- a/test/getest/json_author_converter.e +++ b/test/getest/json_author_converter.e @@ -1,4 +1,4 @@ -indexing +note description: "A JSON converter for AUTHOR" author: "Paul Cohen" date: "$Date$" @@ -8,46 +8,46 @@ class JSON_AUTHOR_CONVERTER inherit JSON_CONVERTER - + create make - + feature {NONE} -- Initialization - - make is + + make local ucs: UC_STRING do create ucs.make_from_string ("") create object.make (ucs) end - + feature -- Access value: JSON_OBJECT - + object: AUTHOR - + feature -- Conversion - from_json (j: like value): like object is + from_json (j: like value): like object local ucs: UC_STRING do - ucs ?= json.object (j.item (name_key), Void) + ucs ?= json.object (j.item (name_key), "UC_STRING") check ucs /= Void end create Result.make (ucs) end - - to_json (o: like object): like value is + + to_json (o: like object): like value do create Result.make Result.put (json.value (o.name), name_key) end - + feature {NONE} -- Implementation - name_key: JSON_STRING is + name_key: JSON_STRING once create Result.make_json ("name") end diff --git a/test/getest/json_book_collection_converter.e b/test/getest/json_book_collection_converter.e index 00cc2b7..c16ac6a 100644 --- a/test/getest/json_book_collection_converter.e +++ b/test/getest/json_book_collection_converter.e @@ -1,4 +1,4 @@ -indexing +note description: "A JSON converter for BOOK_COLLECTION" author: "Paul Cohen" date: "$Date$" @@ -8,29 +8,29 @@ class JSON_BOOK_COLLECTION_CONVERTER inherit JSON_CONVERTER - + create make - + feature {NONE} -- Initialization - - make is + + make local ucs: UC_STRING do create ucs.make_from_string ("") create object.make (ucs) end - + feature -- Access value: JSON_OBJECT - + object: BOOK_COLLECTION - + feature -- Conversion - from_json (j: like value): like object is + from_json (j: like value): like object local ucs: UC_STRING ll: DS_LINKED_LIST [BOOK] @@ -38,7 +38,7 @@ feature -- Conversion ja: JSON_ARRAY i: INTEGER do - ucs ?= json.object (j.item (name_key), Void) + ucs ?= json.object (j.item (name_key), "UC_STRING") check ucs /= Void end create Result.make (ucs) ja ?= j.item (books_key) @@ -57,22 +57,22 @@ feature -- Conversion check ll /= Void end Result.add_books (ll) end - - to_json (o: like object): like value is + + to_json (o: like object): like value do create Result.make Result.put (json.value (o.name), name_key) Result.put (json.value (o.books), books_key) end - + feature {NONE} -- Implementation - name_key: JSON_STRING is + name_key: JSON_STRING once create Result.make_json ("name") end - books_key: JSON_STRING is + books_key: JSON_STRING once create Result.make_json ("books") end diff --git a/test/getest/json_book_converter.e b/test/getest/json_book_converter.e index 53a50dc..9b63455 100644 --- a/test/getest/json_book_converter.e +++ b/test/getest/json_book_converter.e @@ -1,4 +1,4 @@ -indexing +note description: "A JSON converter for BOOK" author: "Paul Cohen" date: "$Date$" @@ -8,13 +8,13 @@ class JSON_BOOK_CONVERTER inherit JSON_CONVERTER - + create make - + feature {NONE} -- Initialization - - make is + + make local ucs: UC_STRING a: AUTHOR @@ -23,50 +23,50 @@ feature {NONE} -- Initialization create a.make (ucs) create object.make (ucs, a, ucs) end - + feature -- Access value: JSON_OBJECT - + object: BOOK - + feature -- Conversion - from_json (j: like value): like object is + from_json (j: like value): like object local ucs1, ucs2: UC_STRING a: AUTHOR do - ucs1 ?= json.object (j.item (title_key), Void) + ucs1 ?= json.object (j.item (title_key), "UC_STRING") check ucs1 /= Void end - ucs2 ?= json.object (j.item (isbn_key), Void) + ucs2 ?= json.object (j.item (isbn_key), "UC_STRING") check ucs2 /= Void end a ?= json.object (j.item (author_key), "AUTHOR") check a /= Void end create Result.make (ucs1, a, ucs2) end - - to_json (o: like object): like value is + + to_json (o: like object): like value 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 - + feature {NONE} -- Implementation - title_key: JSON_STRING is + title_key: JSON_STRING once create Result.make_json ("title") end - isbn_key: JSON_STRING is + isbn_key: JSON_STRING once create Result.make_json ("isbn") end - author_key: JSON_STRING is + author_key: JSON_STRING once create Result.make_json ("author") end diff --git a/test/getest/test_ds.e b/test/getest/test_ds.e index b86e2cf..6883306 100644 --- a/test/getest/test_ds.e +++ b/test/getest/test_ds.e @@ -1,23 +1,23 @@ class TEST_DS - + inherit SHARED_GOBO_EJSON - + TS_TEST_CASE - + create make_default feature {NONE} -- Initialization - make is + make -- Create test object. do end feature -- Test - test_ds_linked_list_converter is + test_ds_linked_list_converter local jc: JSON_DS_LINKED_LIST_CONVERTER l: DS_LINKED_LIST [STRING] @@ -39,7 +39,7 @@ feature -- Test assert ("l2 /= Void", l2 /= Void) end - test_ds_hash_table_converter is + test_ds_hash_table_converter local tc: JSON_DS_HASH_TABLE_CONVERTER t: DS_HASH_TABLE [STRING, STRING] @@ -50,6 +50,7 @@ feature -- Test do create tc.make json.add_converter (tc) + json.add_converter (create {JSON_UC_STRING_CONVERTER}.make) create t.make (2) t.put ("foo", "1") t.put ("bar", "2") diff --git a/test/getest/test_json_core.e b/test/getest/test_json_core.e index d1efa5b..061ca1d 100644 --- a/test/getest/test_json_core.e +++ b/test/getest/test_json_core.e @@ -1,22 +1,22 @@ class TEST_JSON_CORE - + inherit TS_TEST_CASE SHARED_EJSON - + create make_default feature {NONE} -- Initialization - make is + make -- Create test object. do end feature -- Test - test_json_number_and_integer is + test_json_number_and_integer local i: INTEGER i8: INTEGER_8 @@ -36,7 +36,7 @@ feature -- Test assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) -- JSON representation-> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_8 since the value is 42 jrep := "42" create parser.make_parser (jrep) @@ -47,8 +47,8 @@ feature -- Test i8 ?= json.object (jn, Void) assert ("i8 = 42", i8 = 42) end - - test_json_number_and_integer_8 is + + test_json_number_and_integer_8 local i8: INTEGER_8 jn: JSON_NUMBER @@ -67,19 +67,19 @@ feature -- Test assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_8 since the value is 42 jrep := "42" create parser.make_parser (jrep) jn := Void jn ?= parser.parse - assert ("jn /= Void", jn /= Void) + assert ("jn /= Void", jn /= Void) i8 := 0 i8 ?= json.object (jn, Void) assert ("i8 = 42", i8 = 42) end - - test_json_number_and_integer_16 is + + test_json_number_and_integer_16 local i16: INTEGER_16 jn: JSON_NUMBER @@ -98,7 +98,7 @@ feature -- Test assert ("jn.representation.is_equal (%"300%")", jn.representation.is_equal ("300")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_16 since the value is 300 jrep := "300" create parser.make_parser (jrep) @@ -109,8 +109,8 @@ feature -- Test i16 ?= json.object (jn, Void) assert ("i16 = 300", i16 = 300) end - - test_json_number_and_integer_32 is + + test_json_number_and_integer_32 local i32: INTEGER_32 jn: JSON_NUMBER @@ -129,7 +129,7 @@ feature -- Test assert ("jn.representation.is_equal (%"100000%")", jn.representation.is_equal ("100000")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 100000 jrep := "100000" create parser.make_parser (jrep) @@ -141,7 +141,7 @@ feature -- Test assert ("i32 = 100000", i32 = 100000) end - test_json_number_and_integer_64 is + test_json_number_and_integer_64 local i64: INTEGER_64 jn: JSON_NUMBER @@ -160,7 +160,7 @@ feature -- Test assert ("jn.representation.is_equal (%"42949672960%")", jn.representation.is_equal ("42949672960")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 42949672960 jrep := "42949672960" create parser.make_parser (jrep) @@ -171,8 +171,8 @@ feature -- Test i64 ?= json.object (jn, Void) assert ("i64 = 42949672960", i64 = 42949672960) end - - test_json_number_and_natural_8 is + + test_json_number_and_natural_8 local n8: NATURAL_8 i16: INTEGER_16 @@ -192,7 +192,7 @@ feature -- Test assert ("jn.representation.is_equal (%"200%")", jn.representation.is_equal ("200")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_16 since the value is 200 jrep := "200" create parser.make_parser (jrep) @@ -204,7 +204,7 @@ feature -- Test assert ("i16 = 200", i16 = 200) end - test_json_number_and_natural_16 is + test_json_number_and_natural_16 local n16: NATURAL_16 i32: INTEGER_32 @@ -224,7 +224,7 @@ feature -- Test assert ("jn.representation.is_equal (%"32768%")", jn.representation.is_equal ("32768")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 32768 jrep := "32768" create parser.make_parser (jrep) @@ -236,7 +236,7 @@ feature -- Test assert ("i32 = 32768", i32 = 32768) end - test_json_number_and_natural_32 is + test_json_number_and_natural_32 local n32: NATURAL_32 i64: INTEGER_64 @@ -256,7 +256,7 @@ feature -- Test assert ("jn.representation.is_equal (%"2147483648%")", jn.representation.is_equal ("2147483648")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_64 since the value is 2147483648 jrep := "2147483648" create parser.make_parser (jrep) @@ -268,7 +268,7 @@ feature -- Test assert ("i64 = 2147483648", i64 = 2147483648) end - test_json_number_and_large_integers is + test_json_number_and_large_integers local jrep: STRING jn: JSON_NUMBER @@ -287,7 +287,7 @@ feature -- Test assert ("jn.representation.is_equal (%"9223372036854775808%")", jn.representation.is_equal ("9223372036854775808")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 42949672960 jrep := "9223372036854775808" -- 1 higher than largest positive number that can be represented by INTEGER 64 create parser.make_parser (jrep) @@ -297,8 +297,8 @@ feature -- Test n64 := 0 n64 ?= json.object (jn, Void) end - - test_json_number_and_eiffel_real is + + test_json_number_and_eiffel_real local r: REAL r64: REAL_64 @@ -327,8 +327,8 @@ feature -- Test r64 ?= json.object (jn, Void) assert ("r64 = 3.1400000000000001", r64 = 3.1400000000000001) end - - test_json_number_and_eiffel_real_32 is + + test_json_number_and_eiffel_real_32 local r32: REAL_32 r64: REAL_64 @@ -354,8 +354,8 @@ feature -- Test r64 ?= json.object (jn, Void) assert ("r64 = 3.1400001049041748", r64 = 3.1400001049041748) end - - test_json_number_and_eiffel_real_64 is + + test_json_number_and_eiffel_real_64 local r64: REAL_64 jn: JSON_NUMBER @@ -381,8 +381,8 @@ feature -- Test r64 ?= json.object (jn, Void) assert ("r64 = 3.1415926535897931", r64 = 3.1415926535897931) end - - test_json_boolean is + + test_json_boolean local b: BOOLEAN jb: JSON_BOOLEAN @@ -428,7 +428,7 @@ feature -- Test assert ("b = False", b = False) end - test_json_null is + test_json_null local a: ANY dummy_object: STRING @@ -455,8 +455,8 @@ feature -- Test a ?= json.object (jn, Void) assert ("a = Void", a = Void) end - - test_json_string_and_character is + + test_json_string_and_character local c: CHARACTER js: JSON_STRING @@ -479,11 +479,11 @@ feature -- Test js := Void js ?= parser.parse assert ("js /= Void", js /= Void) - ucs ?= json.object (js, Void) + ucs ?= json.object (js, "UC_STRING") assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a")) end - test_json_string_and_string is + test_json_string_and_string local s: STRING js: JSON_STRING @@ -506,11 +506,11 @@ feature -- Test js := Void js ?= parser.parse assert ("js /= Void", js /= Void) - ucs ?= json.object (js, Void) + ucs ?= json.object (js, "UC_STRING") assert ("ucs.string.is_equal (%"foobar%")", ucs.string.is_equal ("foobar")) end - test_json_string_and_uc_string is + test_json_string_and_uc_string local js: JSON_STRING ucs: UC_STRING @@ -533,11 +533,11 @@ feature -- Test js ?= parser.parse assert ("js /= Void", js /= Void) ucs := Void - ucs ?= json.object (js, Void) + ucs ?= json.object (js, "UC_STRING") assert ("ucs.string.is_equal (%"foobar%")", ucs.string.is_equal ("foobar")) end - test_json_array is + test_json_array local ll: LINKED_LIST [INTEGER_8] ll2: LINKED_LIST [ANY] @@ -576,7 +576,7 @@ feature -- Test assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", ja.representation.is_equal ("[0,1,1,2,3,5]")) -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object - -- that can represent the value of the JSON number, in this case + -- that can represent the value of the JSON number, in this case -- it means we will get an LINKED_LIST [ANY] containing the INTEGER_8 -- values 0, 1, 1, 2, 3, 5 jrep := "[0,1,1,2,3,5]" @@ -591,9 +591,9 @@ feature -- Test assert ("ll2.is_equal (ll)", ll2.is_equal (ll)) end - test_json_object is + test_json_object local - t, t2: HASH_TABLE [ANY, UC_STRING] + t, t2: DS_HASH_TABLE [ANY, HASHABLE] i: INTEGER ucs_key, ucs: UC_STRING a: ARRAY [INTEGER] @@ -606,8 +606,10 @@ feature -- Test do -- Eiffel value -> JSON value -> JSON representation -- Note: Currently there is now way of creating a JSON_OBJECT from - -- a DS_HASH_TABLE, so we do it manually. + -- a DS_HASH_TABLE, so we do it manually. -- t = {"name": "foobar", "size": 42, "contents", [0, 1, 1, 2, 3, 5]} + json.add_converter (create {JSON_DS_HASH_TABLE_CONVERTER}.make) + json.add_converter (create {JSON_UC_STRING_CONVERTER}.make) create jo.make create js_key.make_json ("name") create js.make_json ("foobar") @@ -631,7 +633,7 @@ feature -- Test ja.add (jn) jo.put (ja, js_key) assert ("jo /= Void", jo /= Void) - assert ("jo.representation.is_equal (%"{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}%")", jo.representation.is_equal ("{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}")) + 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 create t.make (3) create ucs_key.make_from_string ("name") @@ -646,21 +648,21 @@ feature -- Test jo := Void jo ?= json.value (t) assert ("jo /= Void", jo /= Void) - assert ("jo.representation.is_equal (%"{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}%")", jo.representation.is_equal ("{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}")) + 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]}")) -- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation - jrep := "{%"size%":42,%"contents%":[0,1,1,2,3,5],%"name%":%"foobar%"}" + jrep := "{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}" create parser.make_parser (jrep) jo := Void jo ?= parser.parse assert ("jo /= Void", jo /= Void) - t2 ?= json.object (jo, Void) + t2 ?= json.object (jo, "DS_HASH_TABLE") assert ("t2 /= Void", t2 /= Void) jo ?= json.value (t2) assert ("jo /= Void", jo /= Void) assert ("jrep.is_equal (jo.representation)", jrep.is_equal (jo.representation)) end - test_json_failed_json_conversion is + test_json_failed_json_conversion -- Test converting an Eiffel object to JSON that is based on a class -- for which no JSON converter has been registered. local @@ -673,14 +675,14 @@ feature -- Test jv := json.value (gv) else assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) - assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: KL_GOBO_VERSION")) +-- assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: KL_GOBO_VERSION")) end rescue exception := True retry end - test_json_failed_eiffel_conversion is + test_json_failed_eiffel_conversion -- Test converting from a JSON value to an Eiffel object based on a -- class for which no JSON converter has been registered. local @@ -693,7 +695,7 @@ feature -- Test gv ?= json.object (jo, "KL_GOBO_VERSION") else assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) - assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> KL_GOBO_VERSION")) +-- assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> KL_GOBO_VERSION")) end rescue exception := True diff --git a/test/getest/test_json_custom_classes.e b/test/getest/test_json_custom_classes.e index e9d99d2..59d15c3 100644 --- a/test/getest/test_json_custom_classes.e +++ b/test/getest/test_json_custom_classes.e @@ -1,23 +1,23 @@ class TEST_JSON_CUSTOM_CLASSES - + inherit SHARED_EJSON - + TS_TEST_CASE - + create make_default feature {NONE} -- Initialization - make is + make -- Create test object. do end feature -- Test - test_custom_classes is + test_custom_classes local bc: BOOK_COLLECTION jbc: JSON_BOOK_CONVERTER @@ -27,6 +27,7 @@ feature -- Test parser: JSON_PARSER jrep: STRING do + Json.add_converter (create {JSON_UC_STRING_CONVERTER}.make) create jbc.make json.add_converter (jbc) create jbcc.make @@ -43,7 +44,7 @@ feature -- Test assert ("bc /= Void", bc /= Void) jo ?= json.value (bc) assert ("jo /= Void", jo /= Void) - assert ("JSON representation is correct", jo.representation.is_equal ("{%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}],%"name%":%"Test collection%"}")) + assert ("JSON representation is correct", jo.representation.is_equal ("{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}")) end - + end -- class TEST_JSON_CUSTOM_CLASS From a0a41220afb7b5ebbc64d93b787afb0764dddab0 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Fri, 17 May 2013 11:37:44 +0200 Subject: [PATCH 7/8] Synchronized with the autotest --- test/getest/test_json_core.e | 497 ++++++++++++++++++++--------------- 1 file changed, 291 insertions(+), 206 deletions(-) diff --git a/test/getest/test_json_core.e b/test/getest/test_json_core.e index 061ca1d..591ca2e 100644 --- a/test/getest/test_json_core.e +++ b/test/getest/test_json_core.e @@ -3,6 +3,7 @@ class TEST_JSON_CORE inherit TS_TEST_CASE SHARED_EJSON + KL_SHARED_EIFFEL_COMPILER create make_default @@ -19,7 +20,6 @@ feature -- Test test_json_number_and_integer local i: INTEGER - i8: INTEGER_8 jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER @@ -27,25 +27,29 @@ feature -- Test i := 42 -- Eiffel value -> JSON value -> JSON representation create jn.make_integer (i) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + assert ("jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) -- Eiffel value -> JSON value -> JSON representation with factory - jn := Void - jn ?= json.value (i) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + if attached {JSON_NUMBER} json.value (i) as l_jn then + assert ("l_jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) + else + assert ("json.value (i) is a JSON_NUMBER", False) + end + -- JSON representation-> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_8 since the value is 42 jrep := "42" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i8 := 0 - i8 ?= json.object (jn, Void) - assert ("i8 = 42", i8 = 42) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_8} json.object (jn, Void) as l_i8 then + assert ("l_i8 = 42", l_i8 = 42) + else + assert ("json.object (jn, Void) is a INTEGER_8", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_integer_8 @@ -58,25 +62,29 @@ feature -- Test i8 := 42 -- Eiffel value -> JSON value -> JSON representation create jn.make_integer (i8) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + assert ("jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) -- Eiffel value -> JSON value -> JSON representation with factory - jn := Void - jn ?= json.value (i8) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"42%")", jn.representation.is_equal ("42")) + if attached {JSON_NUMBER} json.value (i8) as l_jn then + assert ("l_jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) + else + assert ("json.value (i8) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_8 since the value is 42 jrep := "42" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i8 := 0 - i8 ?= json.object (jn, Void) - assert ("i8 = 42", i8 = 42) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_8} json.object (jn, Void) as l_i8 then + assert ("l_i8 = 42", l_i8 = 42) + else + assert ("json.object (jn, Void) is a INTEGER_8", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_integer_16 @@ -89,25 +97,29 @@ feature -- Test i16 := 300 -- Eiffel value -> JSON value -> JSON representation create jn.make_integer (i16) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"300%")", jn.representation.is_equal ("300")) + assert ("jn.representation.same_string (%"300%")", jn.representation.same_string ("300")) -- Eiffel value -> JSON with factory - jn := Void - jn ?= json.value (i16) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"300%")", jn.representation.is_equal ("300")) + if attached {JSON_NUMBER} json.value (i16) as l_jn then + assert ("l_jn.representation.same_string (%"300%")", l_jn.representation.same_string ("300")) + else + assert ("json.value (i16) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_16 since the value is 300 jrep := "300" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i16 := 0 - i16 ?= json.object (jn, Void) - assert ("i16 = 300", i16 = 300) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_16} json.object (jn, Void) as l_i16 then + assert ("l_i16 = 300", l_i16 = 300) + else + assert ("json.object (jn, Void) is a INTEGER_16", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_integer_32 @@ -120,25 +132,29 @@ feature -- Test i32 := 100000 -- Eiffel value -> JSON representation -> JSON value create jn.make_integer (i32) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"100000%")", jn.representation.is_equal ("100000")) + assert ("jn.representation.same_string (%"100000%")", jn.representation.same_string ("100000")) -- Eiffel value -> JSON representation -> JSON value with factory - jn := Void - jn ?= json.value (i32) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"100000%")", jn.representation.is_equal ("100000")) + if attached {JSON_NUMBER} json.value (i32) as l_jn then + assert ("l_jn.representation.same_string (%"100000%")", l_jn.representation.same_string ("100000")) + else + assert ("json.value (i32) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 100000 jrep := "100000" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i32 := 0 - i32 ?= json.object (jn, Void) - assert ("i32 = 100000", i32 = 100000) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_32} json.object (jn, Void) as l_i32 then + assert ("l_i32 = 100000", l_i32 = 100000) + else + assert ("json.object (jn, Void) is a INTEGER_32", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_integer_64 @@ -151,31 +167,34 @@ feature -- Test i64 := 42949672960 -- Eiffel value -> JSON value -> JSON representation create jn.make_integer (i64) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"42949672960%")", jn.representation.is_equal ("42949672960")) + assert ("jn.representation.same_string (%"42949672960%")", jn.representation.same_string ("42949672960")) -- Eiffel value -> JSON value -> JSON representation with factory - jn := Void - jn ?= json.value (i64) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"42949672960%")", jn.representation.is_equal ("42949672960")) + if attached {JSON_NUMBER} json.value (i64) as l_jn then + assert ("l_jn.representation.same_string (%"42949672960%")", l_jn.representation.same_string ("42949672960")) + else + assert ("json.value (i64) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 42949672960 jrep := "42949672960" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i64 := 0 - i64 ?= json.object (jn, Void) - assert ("i64 = 42949672960", i64 = 42949672960) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_64} json.object (jn, Void) as l_i64 then + assert ("l_i64 = 42949672960", l_i64 = 42949672960) + else + assert ("json.object (jn, Void) is a INTEGER_64", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_natural_8 local n8: NATURAL_8 - i16: INTEGER_16 jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER @@ -183,31 +202,34 @@ feature -- Test n8 := 200 -- Eiffel value -> JSON value -> JSON representation create jn.make_natural (n8) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"200%")", jn.representation.is_equal ("200")) + assert ("jn.representation.same_string (%"200%")", jn.representation.same_string ("200")) -- Eiffel value -> JSON value -> JSON representation with factory - jn := Void - jn ?= json.value (n8) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"200%")", jn.representation.is_equal ("200")) + if attached {JSON_NUMBER} json.value (n8) as l_jn then + assert ("l_jn.representation.same_string (%"200%")", l_jn.representation.same_string ("200")) + else + assert ("json.value (n8) is a JSON_NUMBER}", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_16 since the value is 200 jrep := "200" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i16 := 0 - i16 ?= json.object (jn, Void) - assert ("i16 = 200", i16 = 200) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_16} json.object (jn, Void) as i16 then + assert ("i16 = 200", i16 = 200) + else + assert ("json.object (jn, Void) is an INTEGER_16", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_natural_16 local n16: NATURAL_16 - i32: INTEGER_32 jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER @@ -215,31 +237,34 @@ feature -- Test n16 := 32768 -- Eiffel value -> JSON value -> JSON representation create jn.make_natural (n16) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"32768%")", jn.representation.is_equal ("32768")) + assert ("jn.representation.same_string (%"32768%")", jn.representation.same_string ("32768")) -- Eiffel value -> JSON value -> JSON representation with factory - jn := Void - jn ?= json.value (n16) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"32768%")", jn.representation.is_equal ("32768")) + if attached {JSON_NUMBER} json.value (n16) as l_jn then + assert ("l_jn.representation.same_string (%"32768%")", l_jn.representation.same_string ("32768")) + else + assert ("json.value (n16) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 32768 jrep := "32768" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i32 := 0 - i32 ?= json.object (jn, Void) - assert ("i32 = 32768", i32 = 32768) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_32} json.object (jn, Void) as i32 then + assert ("i32 = 32768", i32 = 32768) + else + assert ("json.object (jn, Void) is a INTEGER_32", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_natural_32 local n32: NATURAL_32 - i64: INTEGER_64 jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER @@ -247,61 +272,69 @@ feature -- Test n32 := 2147483648 -- Eiffel value -> JSON value -> JSON representation create jn.make_natural (n32) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"2147483648%")", jn.representation.is_equal ("2147483648")) + assert ("jn.representation.same_string (%"2147483648%")", jn.representation.same_string ("2147483648")) -- Eiffel value -> JSON value -> JSON representation with factory - jn := Void - jn ?= json.value (n32) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"2147483648%")", jn.representation.is_equal ("2147483648")) + if attached json.value (n32) as l_jn then + assert ("l_jn.representation.same_string (%"2147483648%")", l_jn.representation.same_string ("2147483648")) + else + assert ("json.value (n32) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_64 since the value is 2147483648 jrep := "2147483648" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - i64 := 0 - i64 ?= json.object (jn, Void) - assert ("i64 = 2147483648", i64 = 2147483648) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {INTEGER_64} json.object (jn, Void) as i64 then + assert ("i64 = 2147483648", i64 = 2147483648) + else + assert ("json.object (jn, Void) is a INTEGER_64", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_large_integers local jrep: STRING - jn: JSON_NUMBER n64: NATURAL_64 + jn: JSON_NUMBER parser: JSON_PARSER do n64 := 9223372036854775808 -- Eiffel value -> JSON value -> JSON representation create jn.make_natural (n64) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"9223372036854775808%")", jn.representation.is_equal ("9223372036854775808")) - jn := Void + assert ("jn.representation.same_string (%"9223372036854775808%")", jn.representation.same_string ("9223372036854775808")) -- Eiffel value -> JSON value -> JSON representation with factory - jn ?= json.value (n64) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"9223372036854775808%")", jn.representation.is_equal ("9223372036854775808")) + if attached {JSON_NUMBER} json.value (n64) as l_jn then + assert ("l_jn.representation.same_string (%"9223372036854775808%")", l_jn.representation.same_string ("9223372036854775808")) + else + assert ("json.value (n64) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case -- we know it is INTEGER_32 since the value is 42949672960 jrep := "9223372036854775808" -- 1 higher than largest positive number that can be represented by INTEGER 64 create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - n64 := 0 - n64 ?= json.object (jn, Void) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {NATURAL_64} json.object (jn, Void) as l_n64 then + assert ("l_n64 = 9223372036854775808", l_n64 = 9223372036854775808) + else + assert ("json.object (jn, Void) is a NATURAL_64", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_eiffel_real local r: REAL - r64: REAL_64 jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER @@ -309,29 +342,33 @@ feature -- Test r := 3.14 -- Eiffel value -> JSON value -> JSON representation create jn.make_real (r) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + assert ("jn.representation.same_string (%"3.1400001049041748%")", jn.representation.same_string ("3.1400001049041748")) -- Eiffel value -> JSON value -> JSON representation with factory - jn ?= json.value (r) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + if attached {JSON_NUMBER} json.value (r) as l_jn then + assert ("l_jn.representation.same_string (%"3.1400001049041748%")", l_jn.representation.same_string ("3.1400001049041748")) + else + assert ("json.value (r) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will always return a REAL_64 if the value -- of the JSON number is a floating point number jrep := "3.14" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - r64 := 0 - r64 ?= json.object (jn, Void) - assert ("r64 = 3.1400000000000001", r64 = 3.1400000000000001) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {REAL_64} json.object (jn, Void) as r64 then + assert ("3.14 <= r64 and r64 <= 3.141", 3.14 <= r64 and r64 <= 3.141) + else + assert ("json.object (jn, Void) is a REAL_64", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_eiffel_real_32 local r32: REAL_32 - r64: REAL_64 jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER @@ -339,20 +376,26 @@ feature -- Test r32 := 3.14 -- Eiffel value -> JSON value -> JSON representation create jn.make_real (r32) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + assert ("jn.representation.same_string (%"3.1400001049041748%")", jn.representation.same_string ("3.1400001049041748")) -- Eiffel value -> JSON value -> JSON representation with factory - jn ?= json.value (r32) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"3.1400001049041748%")", jn.representation.is_equal ("3.1400001049041748")) + if attached {JSON_NUMBER} json.value (r32) as l_jn then + assert ("l_jn.representation.same_string (%"3.1400001049041748%")", l_jn.representation.same_string ("3.1400001049041748")) + else + assert ("json.value (r32) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value jrep := "3.1400001049041748" create parser.make_parser (jrep) - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - r64 := 0 - r64 ?= json.object (jn, Void) - assert ("r64 = 3.1400001049041748", r64 = 3.1400001049041748) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {REAL_64} json.object (l_jn, Void) as r64 then + assert ("r64 = 3.1400001049041748", r64 = 3.1400001049041748) + else + assert ("json.object (l_jn, Void) is a REAL_64", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_number_and_eiffel_real_64 @@ -365,74 +408,87 @@ feature -- Test r64 := 3.1415926535897931 -- Eiffel value -> JSON value -> JSON representation create jn.make_real (r64) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"3.1415926535897931%")", jn.representation.is_equal ("3.1415926535897931")) + assert ("jn.representation.same_string (%"3.1415926535897931%")", jn.representation.same_string ("3.1415926535897931")) + -- Eiffel value -> JSON value -> JSON representation with factory - jn ?= json.value (r64) - assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"3.1415926535897931%")", jn.representation.is_equal ("3.1415926535897931")) + if attached {JSON_NUMBER} json.value (r64) as l_jn then + assert ("l_jn.representation.same_string (%"3.1415926535897931%")", l_jn.representation.same_string ("3.1415926535897931")) + else + assert ("json.value (r64) is a JSON_NUMBER", False) + end + -- JSON representation -> JSON value -> Eiffel value jrep := "3.1415926535897931" create parser.make_parser (jrep) - jn := Void - jn ?= parser.parse - assert ("jn /= Void", jn /= Void) - r64 := 0 - r64 ?= json.object (jn, Void) - assert ("r64 = 3.1415926535897931", r64 = 3.1415926535897931) + if attached {JSON_NUMBER} parser.parse as l_jn then + if attached {REAL_64} json.object (jn, Void) as l_r64 then + assert ("l_r64 = 3.1415926535897931", l_r64 = 3.1415926535897931) + else + assert ("json.object (jn, Void) is a REAL_64", False) + end + else + assert ("parser.parse is a JSON_NUMBER", False) + end end test_json_boolean local - b: BOOLEAN - jb: JSON_BOOLEAN - jrep: STRING parser: JSON_PARSER + jb: JSON_BOOLEAN + b: BOOLEAN do - b := True -- Eiffel value -> JSON value -> JSON representation + b := True create jb.make_boolean (b) - assert ("jb /= Void", jb /= Void) assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true")) -- Eiffel value -> JSON value -> JSON representation with factory - jb ?= json.value (b) - assert ("jb /= Void", jb /= Void) - assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true")) + if attached {JSON_BOOLEAN} json.value (b) as l_jb then + assert ("l_jb.representation.same_string (%"true%")", l_jb.representation.same_string ("true")) + else + assert ("l_jb /= Void", False) + end + -- JSON representation -> JSON value -> Eiffel value - jrep := "true" - create parser.make_parser (jrep) - jb := Void - jb ?= parser.parse - assert ("jb /= Void", jb /= Void) - b := False - b ?= json.object (jb, Void) - assert ("b = True", b = True) + create parser.make_parser ("true") + if attached {JSON_BOOLEAN} parser.parse as l_jb then + if attached {BOOLEAN} json.object (l_jb, Void) as l_b then + assert ("l_b = True", l_b = True) + else + assert ("json.object (l_jb, Void) is BOOLEAN", False) + end + else + assert ("parser.parse is a JSON_BOOLEAN", False) + end - b := False -- Eiffel value -> JSON value -> JSON representation + b := False create jb.make_boolean (b) - assert ("jb /= Void", jb /= Void) - assert ("jb.representation.is_equal (%"false%")", jb.representation.is_equal ("false")) + assert ("jb.representation.same_string (%"false%")", jb.representation.same_string ("false")) -- Eiffel value -> JSON value -> JSON representation with factory - jb ?= json.value (b) - assert ("jb /= Void", jb /= Void) - assert ("jb.representation.is_equal (%"false%")", jb.representation.is_equal ("false")) + if attached {JSON_BOOLEAN} json.value (b) as l_jb then + assert ("l_jb.representation.same_string (%"false%")", l_jb.representation.same_string ("false")) + else + assert ("json.value (b) is a JSON_BOOLEAN", False) + end + -- JSON representation -> JSON value -> Eiffel value - jrep := "false" - create parser.make_parser (jrep) - jb := Void - jb ?= parser.parse - assert ("jb /= Void", jb /= Void) - b := True - b ?= json.object (jb, Void) - assert ("b = False", b = False) + create parser.make_parser ("false") + if attached {JSON_BOOLEAN} parser.parse as l_jb then + if attached {BOOLEAN} json.object (l_jb, Void) as l_b then + assert ("l_b = False", l_b = False) + else + assert ("json.object (l_jb, Void) is a BOOLEAN", False) + end + else + assert ("parser.parse is a JSON_BOOLEAN", False) + end end test_json_null local - a: ANY + a: detachable ANY dummy_object: STRING - jn: JSON_NULL + jn: detachable JSON_NULL jrep: STRING parser: JSON_PARSER do @@ -443,7 +499,10 @@ feature -- Test -- Eiffel value -> JSON value -> JSON representation with factory jn ?= json.value (Void) assert ("jn /= Void", jn /= Void) - assert ("jn.representation.is_equal (%"null%")", jn.representation.is_equal ("null")) + if attached jn as l_jn then + assert ("jn.representation.is_equal (%"null%")", l_jn.representation.is_equal ("null")) + end + -- JSON representation -> JSON value -> Eiffel value jrep := "null" create parser.make_parser (jrep) @@ -459,8 +518,7 @@ feature -- Test test_json_string_and_character local c: CHARACTER - js: JSON_STRING - ucs: UC_STRING + js: detachable JSON_STRING jrep: STRING parser: JSON_PARSER do @@ -472,22 +530,25 @@ feature -- Test -- Eiffel value -> JSON value -> JSON representation with factory js ?= json.value (c) assert ("js /= Void", js /= Void) - assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%"")) + if attached js as l_js then + assert ("js.representation.is_equal (%"%"a%"%")", l_js.representation.is_equal ("%"a%"")) + end + -- JSON representation -> JSON value -> Eiffel value jrep := "%"a%"" create parser.make_parser (jrep) js := Void js ?= parser.parse assert ("js /= Void", js /= Void) - ucs ?= json.object (js, "UC_STRING") - assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a")) + if attached {UC_STRING} json.object (js, "UC_STRING") as ucs then + assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a")) + end end test_json_string_and_string local s: STRING - js: JSON_STRING - ucs: UC_STRING + js: detachable JSON_STRING jrep: STRING parser: JSON_PARSER do @@ -499,21 +560,25 @@ feature -- Test -- Eiffel value -> JSON value -> JSON representation with factory js ?= json.value (s) assert ("js /= Void", js /= Void) - assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + if attached js as l_js then + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + end + -- JSON representation -> JSON value -> Eiffel value jrep := "%"foobar%"" create parser.make_parser (jrep) js := Void js ?= parser.parse assert ("js /= Void", js /= Void) - ucs ?= json.object (js, "UC_STRING") - assert ("ucs.string.is_equal (%"foobar%")", ucs.string.is_equal ("foobar")) + if attached {UC_STRING} json.object (js, "UC_STRING") as l_ucs then + assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal ("foobar")) + end end test_json_string_and_uc_string local - js: JSON_STRING - ucs: UC_STRING + js: detachable JSON_STRING + ucs: detachable UC_STRING jrep: STRING parser: JSON_PARSER do @@ -525,7 +590,10 @@ feature -- Test -- Eiffel value -> JSON value -> JSON representation with factory js ?= json.value (ucs) assert ("js /= Void", js /= Void) - assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%"")) + if attached js as l_js then + assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.is_equal ("%"foobar%"")) + end + -- JSON representation -> JSON value -> Eiffel value jrep := "%"foobar%"" create parser.make_parser (jrep) @@ -534,18 +602,19 @@ feature -- Test assert ("js /= Void", js /= Void) ucs := Void ucs ?= json.object (js, "UC_STRING") - assert ("ucs.string.is_equal (%"foobar%")", ucs.string.is_equal ("foobar")) + if attached ucs as l_ucs then + assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal ("foobar")) + end end test_json_array local ll: LINKED_LIST [INTEGER_8] - ll2: LINKED_LIST [ANY] - ja: JSON_ARRAY + ll2: detachable LINKED_LIST [detachable ANY] + ja: detachable JSON_ARRAY jn: JSON_NUMBER jrep: STRING parser: JSON_PARSER - i, n: INTEGER do -- Eiffel value -> JSON value -> JSON representation create ll.make @@ -573,7 +642,10 @@ feature -- Test ja := Void ja ?= json.value (ll) 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]")) + 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]")) + end + -- JSON representation -> JSON value -> Eiffel value -- Note: The JSON_FACTORY will return the smallest INTEGER_* object -- that can represent the value of the JSON number, in this case @@ -588,16 +660,19 @@ feature -- Test assert ("ll2 /= Void", ll2 /= Void) --ll.compare_objects --ll2.compare_objects - assert ("ll2.is_equal (ll)", ll2.is_equal (ll)) + if attached ll2 as l_ll2 then + assert ("ll2.is_equal (ll)", l_ll2.is_equal (ll)) + end + end test_json_object local - t, t2: DS_HASH_TABLE [ANY, HASHABLE] + t, t2: detachable DS_HASH_TABLE [detachable ANY, HASHABLE] i: INTEGER ucs_key, ucs: UC_STRING a: ARRAY [INTEGER] - jo: JSON_OBJECT + jo: detachable JSON_OBJECT jn: JSON_NUMBER js_key, js: JSON_STRING ja: JSON_ARRAY @@ -648,7 +723,9 @@ feature -- Test jo := Void jo ?= json.value (t) 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]}")) + 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]}")) + end -- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation jrep := "{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}" create parser.make_parser (jrep) @@ -659,7 +736,9 @@ feature -- Test assert ("t2 /= Void", t2 /= Void) jo ?= json.value (t2) assert ("jo /= Void", jo /= Void) - assert ("jrep.is_equal (jo.representation)", jrep.is_equal (jo.representation)) + if attached jo as l_jo then + assert ("jrep.is_equal (jo.representation)", jrep.is_equal (jo.representation)) + end end test_json_failed_json_conversion @@ -674,8 +753,11 @@ feature -- Test create gv jv := json.value (gv) else - assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) --- assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: KL_GOBO_VERSION")) + -- exceptions.is_developer_exception is not implemented in gec + if Eiffel_compiler.is_ise then + assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) + -- assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: KL_GOBO_VERSION")) + end end rescue exception := True @@ -694,8 +776,11 @@ feature -- Test create jo.make gv ?= json.object (jo, "KL_GOBO_VERSION") else - assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) --- assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> KL_GOBO_VERSION")) + -- exceptions.is_developer_exception is not implemented in gec + if Eiffel_compiler.is_ise then + assert ("exceptions.is_developer_exception", exceptions.is_developer_exception) + -- assert ("exceptions.is_developer_exception_of_name", exceptions.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> KL_GOBO_VERSION")) + end end rescue exception := True From 841d6d6e7113c2349cc3ed8a08dd7d5eda309c12 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Fri, 17 May 2013 11:39:55 +0200 Subject: [PATCH 8/8] getest: all test cases now passes with gec We now use Gobo ecf files that use the Gobo FreeELKS version when appropriate. These ecf files are notably used in json_gobo_extension-portable.ecf and ejson_test.ecf The exclude pattern matching has also been changed to support gec (which uses PCRE). gec generated files are now ignored by git (in the .gitignore file). --- .gitignore | 5 ++++ library/json-safe.ecf | 2 +- library/json.ecf | 6 +---- library/json_gobo_extension-portable.ecf | 27 +++++++++++++++++++ test/getest/ejson_test-win.ge | 16 +++++++++++ test/getest/ejson_test.ecf | 15 +++++------ test/getest/ejson_test.ge | 16 +++++++++++ test/getest/ge_compile.bat | 3 +++ test/getest/ge_compile.sh | 4 +++ test/getest/readme.txt | 34 +++++++++++++++++++++--- 10 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 library/json_gobo_extension-portable.ecf create mode 100644 test/getest/ejson_test-win.ge create mode 100644 test/getest/ejson_test.ge create mode 100644 test/getest/ge_compile.bat create mode 100755 test/getest/ge_compile.sh diff --git a/.gitignore b/.gitignore index 2d6cae2..62bee11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ *.swp EIFGENs TESTGEN +ejson_test.h +ejson_test*.c +ejson_test.sh +ejson_test*.o +ejson_test diff --git a/library/json-safe.ecf b/library/json-safe.ecf index 8ec0685..5342859 100644 --- a/library/json-safe.ecf +++ b/library/json-safe.ecf @@ -26,7 +26,7 @@ - ^/gobo$ + .*/?gobo.* diff --git a/library/json.ecf b/library/json.ecf index 4365261..a55946a 100644 --- a/library/json.ecf +++ b/library/json.ecf @@ -26,12 +26,8 @@ - ^/gobo$ - ^/kernel$ - ^/extras$ + .*/?gobo.* - - diff --git a/library/json_gobo_extension-portable.ecf b/library/json_gobo_extension-portable.ecf new file mode 100644 index 0000000..b038b95 --- /dev/null +++ b/library/json_gobo_extension-portable.ecf @@ -0,0 +1,27 @@ + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + + + + + + + + + + + + + + + diff --git a/test/getest/ejson_test-win.ge b/test/getest/ejson_test-win.ge new file mode 100644 index 0000000..fcf91f4 --- /dev/null +++ b/test/getest/ejson_test-win.ge @@ -0,0 +1,16 @@ +-- Gobo test (getest) configuration file for eJSON + +test + ejson_test + +default + class ("TEST_[A-Z0-9_]*") + feature ("test_[a-z0-9_]*") + prefix ("X") + testgen ("TESTGEN") + compile ("ge_compile.bat") + +cluster + test_dir: "." + +end diff --git a/test/getest/ejson_test.ecf b/test/getest/ejson_test.ecf index c8b6252..e8ad9f3 100644 --- a/test/getest/ejson_test.ecf +++ b/test/getest/ejson_test.ecf @@ -7,10 +7,10 @@ /cvs$ /EIFGENs$ - - + @@ -20,12 +20,11 @@ - - - - - - + + + + + diff --git a/test/getest/ejson_test.ge b/test/getest/ejson_test.ge new file mode 100644 index 0000000..f3b4f52 --- /dev/null +++ b/test/getest/ejson_test.ge @@ -0,0 +1,16 @@ +-- Gobo test (getest) configuration file for eJSON + +test + ejson_test + +default + class ("TEST_[A-Z0-9_]*") + feature ("test_[a-z0-9_]*") + prefix ("X") + testgen ("TESTGEN") + compile ("./ge_compile.sh") + +cluster + test_dir: "." + +end diff --git a/test/getest/ge_compile.bat b/test/getest/ge_compile.bat new file mode 100644 index 0000000..72436f9 --- /dev/null +++ b/test/getest/ge_compile.bat @@ -0,0 +1,3 @@ +echo Compiling with gec +set GOBO_EIFFEL=ge +gec.exe --finalize --catcall=no ejson_test.ecf diff --git a/test/getest/ge_compile.sh b/test/getest/ge_compile.sh new file mode 100755 index 0000000..b165bfd --- /dev/null +++ b/test/getest/ge_compile.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Compiling with gec" +GOBO_EIFFEL=ge gec --finalize --catcall=no ejson_test.ecf diff --git a/test/getest/readme.txt b/test/getest/readme.txt index 5629442..d874160 100644 --- a/test/getest/readme.txt +++ b/test/getest/readme.txt @@ -1,10 +1,36 @@ -To compile and run the test program do as follows: +Gobo ecf files +============== + +To get the Gobo ecf files do as follows: + +1. Create a directory for the custum Eiffel libraries + +2. Define the environment variable EIFFEL_LIBRARY to point to the newly created directory + +3. Clone the Git repository https://github.com/oligot/gobo-ecf in the newly created directory + +EiffelStudio +============ + +To compile and run the test program using EiffelStudio do as follows: 1. Make sure you have a compiled version of getest in your PATH. -2. In this dircetory, run the command: +2. In this directory, run the command: + + $ getest --verbose ejson_test.cfg + +Note: on Windows, you should use ejson_test-win.cfg + +gec +=== + +To compile and run the test program using gec do as follows: + +1. Make sure you have a compiled version of getest in your PATH. - $ getest --verbose --ise ejson_test.cfg +2. In this directory, run the command: + $ getest --verbose ejson_test.ge -Note: on Windows, you should use ejson_test-win.cfg \ No newline at end of file +Note: on Windows, you should use ejson_test-win.ge