From f4c472cb9f63367a61a85d6c029acec8b5b363cd Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 7 Jul 2011 12:03:25 +0000 Subject: [PATCH] Updated eJSON to use Eiffel 6.8 version. Basically the changes are: Replace ? by detachable indexing by note removing `is' from features, and in some places replaced by = In the ecf now we need to include every gobo library, because the gobo.ecf, exclude libraries that are needed. TODO: the test-suite is not void-safety. --- library/extras/file/json_file_reader.e | 6 +- library/extras/visitor/json_visitor.e | 14 +- library/extras/visitor/print_json_visitor.e | 16 +- .../converters/json_ds_hash_table_converter.e | 162 ++-- .../json_ds_linked_list_converter.e | 124 +-- library/gobo/shared_gobo_ejson.e | 4 +- library/json-safe.ecf | 9 +- library/json.ecf | 72 +- library/kernel/converters/json_converter.e | 25 +- .../converters/json_hash_table_converter.e | 59 +- .../converters/json_linked_list_converter.e | 42 +- library/kernel/ejson.e | 311 ++++--- library/kernel/json_array.e | 24 +- library/kernel/json_boolean.e | 10 +- library/kernel/json_null.e | 10 +- library/kernel/json_number.e | 22 +- library/kernel/json_object.e | 24 +- library/kernel/json_string.e | 18 +- library/kernel/json_value.e | 6 +- library/kernel/scanner/json_parser.e | 138 +++- library/kernel/scanner/json_reader.e | 22 +- library/kernel/scanner/json_tokens.e | 26 +- library/kernel/shared_ejson.e | 4 +- test/autotest/test_suite/test_json_suite.e | 769 +++++++++--------- test/autotest/test_suite/test_suite-safe.ecf | 19 + test/autotest/test_suite/test_suite.ecf | 2 +- 26 files changed, 1009 insertions(+), 929 deletions(-) create mode 100644 test/autotest/test_suite/test_suite-safe.ecf diff --git a/library/extras/file/json_file_reader.e b/library/extras/file/json_file_reader.e index 31fdbdf9..3629c475 100644 --- a/library/extras/file/json_file_reader.e +++ b/library/extras/file/json_file_reader.e @@ -1,4 +1,4 @@ -indexing +note description: "Objects that ..." author: "" date: "$Date$" @@ -9,11 +9,11 @@ class feature -- Access - read_json_from (a_path: STRING): ?STRING is + read_json_from (a_path: STRING): detachable STRING local l_file: PLAIN_TEXT_FILE template_content: STRING - l_last_string: ?STRING + l_last_string: detachable STRING do create l_file.make (a_path) -- We perform several checks until we make a real attempt to open the file. diff --git a/library/extras/visitor/json_visitor.e b/library/extras/visitor/json_visitor.e index b2b485cb..bf2f583e 100644 --- a/library/extras/visitor/json_visitor.e +++ b/library/extras/visitor/json_visitor.e @@ -1,4 +1,4 @@ -indexing +note description: "JSON Visitor" @@ -14,42 +14,42 @@ deferred class feature -- Visitor Pattern - visit_json_array (a_json_array: JSON_ARRAY) is + visit_json_array (a_json_array: JSON_ARRAY) -- Visit `a_json_array'. require a_json_array_not_void: a_json_array /= Void deferred end - visit_json_boolean (a_json_boolean: JSON_BOOLEAN) is + visit_json_boolean (a_json_boolean: JSON_BOOLEAN) -- Visit `a_json_boolean'. require a_json_boolean_not_void: a_json_boolean /= Void deferred end - visit_json_null (a_json_null: JSON_NULL) is + visit_json_null (a_json_null: JSON_NULL) -- Visit `a_json_null'. require a_json_null_not_void: a_json_null /= Void deferred end - visit_json_number (a_json_number: JSON_NUMBER) is + visit_json_number (a_json_number: JSON_NUMBER) -- Visit `a_json_number'. require a_json_number_not_void: a_json_number /= Void deferred end - visit_json_object (a_json_object: JSON_OBJECT) is + visit_json_object (a_json_object: JSON_OBJECT) -- Visit `a_json_object'. require a_json_object_not_void: a_json_object /= Void deferred end - visit_json_string (a_json_string: JSON_STRING) is + visit_json_string (a_json_string: JSON_STRING) -- Visit `a_json_string'. require a_json_string_not_void: a_json_string /= Void diff --git a/library/extras/visitor/print_json_visitor.e b/library/extras/visitor/print_json_visitor.e index b2710c20..6fa64558 100644 --- a/library/extras/visitor/print_json_visitor.e +++ b/library/extras/visitor/print_json_visitor.e @@ -1,4 +1,4 @@ -indexing +note description: "PRINT_JSON_VISITOR Generates the JSON-String for a JSON_VALUE" author: "jvelilla" date: "2008/08/24" @@ -14,7 +14,7 @@ create make feature -- Initialization - make is + make -- Create a new instance do create to_json.make_empty @@ -27,7 +27,7 @@ feature -- Access feature -- Visitor Pattern - visit_json_array (a_json_array: JSON_ARRAY) is + visit_json_array (a_json_array: JSON_ARRAY) -- Visit `a_json_array'. local value: JSON_VALUE @@ -50,25 +50,25 @@ feature -- Visitor Pattern to_json.append ("]") end - visit_json_boolean (a_json_boolean: JSON_BOOLEAN) is + visit_json_boolean (a_json_boolean: JSON_BOOLEAN) -- Visit `a_json_boolean'. do to_json.append (a_json_boolean.item.out) end - visit_json_null (a_json_null: JSON_NULL) is + visit_json_null (a_json_null: JSON_NULL) -- Visit `a_json_null'. do to_json.append ("null") end - visit_json_number (a_json_number: JSON_NUMBER) is + visit_json_number (a_json_number: JSON_NUMBER) -- Visit `a_json_number'. do to_json.append (a_json_number.item) end - visit_json_object (a_json_object: JSON_OBJECT) is + visit_json_object (a_json_object: JSON_OBJECT) -- Visit `a_json_object'. local l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING] @@ -91,7 +91,7 @@ feature -- Visitor Pattern to_json.append ("}") end - visit_json_string (a_json_string: JSON_STRING) is + visit_json_string (a_json_string: JSON_STRING) -- Visit `a_json_string'. do to_json.append ("%"") diff --git a/library/gobo/converters/json_ds_hash_table_converter.e b/library/gobo/converters/json_ds_hash_table_converter.e index 8cd9cce1..e2532c57 100644 --- a/library/gobo/converters/json_ds_hash_table_converter.e +++ b/library/gobo/converters/json_ds_hash_table_converter.e @@ -1,81 +1,81 @@ -indexing - description: "A JSON converter for DS_HASH_TABLE [ANY, HASHABLE]" - author: "Paul Cohen" - date: "$Date: $" - revision: "$Revision: $" - file: "$HeadURL: $" - -class JSON_DS_HASH_TABLE_CONVERTER - -inherit - JSON_CONVERTER - -create - make - -feature {NONE} -- Initialization - - make is - do - create object.make (0) - end - -feature -- Access - - value: JSON_OBJECT - - object: DS_HASH_TABLE [ANY, HASHABLE] - -feature -- Conversion - - from_json (j: like value): like object is - local - keys: ARRAY [JSON_STRING] - i: INTEGER - h: HASHABLE - a: ANY - do - keys := j.current_keys - create Result.make (keys.count) - from - i := 1 - until - i > keys.count - loop - h ?= json.object (keys [i], void) - check h /= Void end - a := json.object (j.item (keys [i]), Void) - Result.put (a, h) - i := i + 1 - end - end - - to_json (o: like object): like value is - local - c: DS_HASH_TABLE_CURSOR [ANY, HASHABLE] - js: JSON_STRING - jv: JSON_VALUE - failed: BOOLEAN - do - create Result.make - from - c := o.new_cursor - c.start - until - c.after - loop - create js.make_json (c.key.out) - jv := json.value (c.item) - if jv /= Void then - Result.put (jv, js) - else - failed := True - end - c.forth - end - if failed then - Result := Void - end - end - -end -- class JSON_DS_HASH_TABLE_CONVERTER \ No newline at end of file +note + description: "A JSON converter for DS_HASH_TABLE [ANY, HASHABLE]" + author: "Paul Cohen" + date: "$Date: $" + revision: "$Revision: $" + file: "$HeadURL: $" + +class JSON_DS_HASH_TABLE_CONVERTER + +inherit + JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make (0) + end + +feature -- Access + + value: JSON_OBJECT + + object: DS_HASH_TABLE [ANY, HASHABLE] + +feature -- Conversion + + from_json (j: like value): detachable like object + local + keys: ARRAY [JSON_STRING] + i: INTEGER + h: HASHABLE + a: ANY + do + keys := j.current_keys + create Result.make (keys.count) + from + i := 1 + until + i > keys.count + loop + h ?= json.object (keys [i], void) + check h /= Void end + a := json.object (j.item (keys [i]), Void) + Result.put (a, h) + i := i + 1 + end + end + + to_json (o: like object): like value + local + c: DS_HASH_TABLE_CURSOR [ANY, HASHABLE] + js: JSON_STRING + jv: JSON_VALUE + failed: BOOLEAN + do + create Result.make + from + c := o.new_cursor + c.start + until + c.after + loop + create js.make_json (c.key.out) + jv := json.value (c.item) + if jv /= Void then + Result.put (jv, js) + else + failed := True + end + c.forth + end + if failed then + Result := Void + end + end + +end -- class JSON_DS_HASH_TABLE_CONVERTER diff --git a/library/gobo/converters/json_ds_linked_list_converter.e b/library/gobo/converters/json_ds_linked_list_converter.e index c2a1a160..bf1aa516 100644 --- a/library/gobo/converters/json_ds_linked_list_converter.e +++ b/library/gobo/converters/json_ds_linked_list_converter.e @@ -1,62 +1,62 @@ -indexing - description: "A JSON converter for DS_LINKED_LIST [ANY]" - author: "Paul Cohen" - date: "$Date: $" - revision: "$Revision: $" - file: "$HeadURL: $" - -class JSON_DS_LINKED_LIST_CONVERTER - -inherit - JSON_CONVERTER - -create - make - -feature {NONE} -- Initialization - - make is - do - create object.make - end - -feature -- Access - - value: JSON_ARRAY - - object: DS_LINKED_LIST [ANY] - -feature -- Conversion - - from_json (j: like value): like object is - local - i: INTEGER - do - create Result.make - from - i := 1 - until - i > j.count - loop - Result.put_last (json.object (j [i], Void)) - i := i + 1 - end - end - - to_json (o: like object): like value is - local - c: DS_LIST_CURSOR [ANY] - do - create Result.make_array - from - c := o.new_cursor - c.start - until - c.after - loop - Result.add (json.value (c.item)) - c.forth - end - end - -end -- class JSON_DS_LINKED_LIST_CONVERTER \ No newline at end of file +note + description: "A JSON converter for DS_LINKED_LIST [ANY]" + author: "Paul Cohen" + date: "$Date: $" + revision: "$Revision: $" + file: "$HeadURL: $" + +class JSON_DS_LINKED_LIST_CONVERTER + +inherit + JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make + end + +feature -- Access + + value: JSON_ARRAY + + object: DS_LINKED_LIST [ANY] + +feature -- Conversion + + from_json (j: like value): detachable like object + local + i: INTEGER + do + create Result.make + from + i := 1 + until + i > j.count + loop + Result.put_last (json.object (j [i], Void)) + i := i + 1 + end + end + + to_json (o: like object): like value + local + c: DS_LIST_CURSOR [ANY] + do + create Result.make_array + from + c := o.new_cursor + c.start + until + c.after + loop + Result.add (json.value (c.item)) + c.forth + end + end + +end -- class JSON_DS_LINKED_LIST_CONVERTER diff --git a/library/gobo/shared_gobo_ejson.e b/library/gobo/shared_gobo_ejson.e index 62bbfb72..ccc33432 100644 --- a/library/gobo/shared_gobo_ejson.e +++ b/library/gobo/shared_gobo_ejson.e @@ -1,4 +1,4 @@ -indexing +note description: "[ Shared factory class for creating JSON objects. Maps JSON objects to Gobo DS_HASH_TABLEs and JSON arrays to Gobo @@ -15,7 +15,7 @@ class SHARED_GOBO_EJSON feature - json: EJSON is + json: EJSON -- A shared EJSON instance with default converters for -- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE] local diff --git a/library/json-safe.ecf b/library/json-safe.ecf index 6954ead7..9acafcbc 100644 --- a/library/json-safe.ecf +++ b/library/json-safe.ecf @@ -1,8 +1,8 @@ - + - diff --git a/library/json.ecf b/library/json.ecf index 95ae5a6c..fd35350e 100644 --- a/library/json.ecf +++ b/library/json.ecf @@ -1,30 +1,42 @@ - - - - - - - - - - /EIFGENs$ - /.svn$ - /CVS$ - - - ^/kernel$ - ^/gobo$ - ^/extras$ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + ^/gobo$ + ^/kernel$ + ^/extras$ + + + + + + + diff --git a/library/kernel/converters/json_converter.e b/library/kernel/converters/json_converter.e index 2e8ff9c3..bae2bd9c 100644 --- a/library/kernel/converters/json_converter.e +++ b/library/kernel/converters/json_converter.e @@ -1,4 +1,4 @@ -indexing +note description: "A JSON converter" author: "Paul Cohen" date: "$Date: $" @@ -7,35 +7,30 @@ indexing deferred class JSON_CONVERTER -inherit +inherit SHARED_EJSON feature -- Access - value: JSON_VALUE is - -- JSON value - deferred - end - - object: ANY is + object: ANY -- Eiffel object deferred end - + feature -- Conversion - from_json (j: like value): like object is - -- Convert from JSON value. Returns Void if unable to convert + from_json (j: attached like to_json): detachable like object + -- Convert from JSON value. + -- Returns Void if unable to convert deferred end - - to_json (o: like object): like value is + + to_json (o: like object): detachable JSON_VALUE -- Convert to JSON value deferred end invariant has_eiffel_object: object /= Void -- An empty object must be created at creation time! - -end -- class JSON_CONVERTER +end diff --git a/library/kernel/converters/json_hash_table_converter.e b/library/kernel/converters/json_hash_table_converter.e index 60b9fb57..8ce5260e 100644 --- a/library/kernel/converters/json_hash_table_converter.e +++ b/library/kernel/converters/json_hash_table_converter.e @@ -1,4 +1,4 @@ -indexing +note description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]" author: "Paul Cohen" date: "$Date$" @@ -9,31 +9,30 @@ class JSON_HASH_TABLE_CONVERTER inherit JSON_CONVERTER - + create make - + feature {NONE} -- Initialization - - make is + + make do create object.make (0) end - + feature -- Access - value: JSON_OBJECT - object: HASH_TABLE [ANY, HASHABLE] - + feature -- Conversion - from_json (j: like value): like object is + from_json (j: attached like to_json): like object local keys: ARRAY [JSON_STRING] i: INTEGER - h: HASHABLE - a: ANY + h: detachable HASHABLE + jv: detachable JSON_VALUE + a: detachable ANY do keys := j.current_keys create Result.make (keys.count) @@ -44,36 +43,46 @@ feature -- Conversion loop h ?= json.object (keys [i], void) check h /= Void end - a := json.object (j.item (keys [i]), Void) - Result.put (a, h) + jv := j.item (keys [i]) + if jv /= Void then + a := json.object (jv, Void) + if a /= Void then + Result.put (a, h) + else + check a_attached: a /= Void end + end + else + check j_has_item: False end + end i := i + 1 end end - - to_json (o: like object): like value is + + to_json (o: like object): detachable JSON_OBJECT local + c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE] js: JSON_STRING - jv: JSON_VALUE + jv: detachable JSON_VALUE failed: BOOLEAN do create Result.make from - o.start + c := o.new_cursor until - o.after + c.after loop - create js.make_json (o.key_for_iteration.out) - jv := json.value (o.item_for_iteration) + create js.make_json (c.key.out) + jv := json.value (c.item) if jv /= Void then Result.put (jv, js) else failed := True - end - o.forth + end + c.forth end if failed then Result := Void end end - -end -- class JSON_HASH_TABLE_CONVERTER \ No newline at end of file + +end -- class JSON_HASH_TABLE_CONVERTER diff --git a/library/kernel/converters/json_linked_list_converter.e b/library/kernel/converters/json_linked_list_converter.e index 0eec8cfc..bcc41e49 100644 --- a/library/kernel/converters/json_linked_list_converter.e +++ b/library/kernel/converters/json_linked_list_converter.e @@ -1,4 +1,4 @@ -indexing +note description: "A JSON converter for LINKED_LIST [ANY]" author: "Paul Cohen" date: "$Date$" @@ -9,26 +9,24 @@ class JSON_LINKED_LIST_CONVERTER inherit JSON_CONVERTER - + create make - + feature {NONE} -- Initialization - - make is + + make do create object.make end - + feature -- Access - value: JSON_ARRAY - - object: LINKED_LIST [ANY] - + object: LINKED_LIST [detachable ANY] + feature -- Conversion - from_json (j: like value): like object is + from_json (j: like to_json): detachable like object local i: INTEGER do @@ -42,20 +40,24 @@ feature -- Conversion i := i + 1 end end - - to_json (o: like object): like value is + + to_json (o: like object): JSON_ARRAY local - c: LINKED_LIST_CURSOR [ANY] + c: ITERATION_CURSOR [detachable ANY] do create Result.make_array from - o.start + c := o.new_cursor until - o.after + c.after loop - Result.add (json.value (o.item)) - o.forth + if attached json.value (c.item) as v then + Result.add (v) + else + check attached_value: False end + end + c.forth end end - -end -- class JSON_LINKED_LIST_CONVERTER \ No newline at end of file + +end -- class JSON_LINKED_LIST_CONVERTER diff --git a/library/kernel/ejson.e b/library/kernel/ejson.e index 200d3f76..a22ec4ef 100644 --- a/library/kernel/ejson.e +++ b/library/kernel/ejson.e @@ -1,4 +1,4 @@ -indexing +note description: "Core factory class for creating JSON objects and corresponding Eiffel objects." author: "Paul Cohen" date: "$Date: $" @@ -8,98 +8,73 @@ indexing class EJSON inherit - {NONE} KL_EXCEPTIONS - + {NONE} EXCEPTIONS + feature -- Access - - value (an_object: ?ANY): JSON_VALUE is - -- JSON value from Eiffel object. Raises an "eJSON exception" if + + value (an_object: detachable ANY): detachable JSON_VALUE + -- JSON value from Eiffel object. Raises an "eJSON exception" if -- unable to convert value. local - b: BOOLEAN i: INTEGER - i8: INTEGER_8 - i16: INTEGER_16 - i32: INTEGER_32 - i64: INTEGER_64 - n8: NATURAL_8 - n16: NATURAL_16 - n32: NATURAL_32 - n64: NATURAL_64 - r32: REAL_32 - r64: REAL_64 - a: ARRAY [ANY] - c: CHARACTER - s8: STRING_8 - ucs: UC_STRING ja: JSON_ARRAY - jc: JSON_CONVERTER do -- Try to convert from basic Eiffel types. Note that we check with -- `conforms_to' since the client may have subclassed the base class -- that these basic types are derived from. if an_object = Void then create {JSON_NULL} Result - elseif an_object.conforms_to (a_boolean) then - b ?= an_object + elseif attached {BOOLEAN} an_object as b then create {JSON_BOOLEAN} Result.make_boolean (b) - elseif an_object.conforms_to (an_integer_8) then - i8 ?= an_object + elseif attached {INTEGER_8} an_object as i8 then create {JSON_NUMBER} Result.make_integer (i8) - elseif an_object.conforms_to (an_integer_16) then - i16 ?= an_object + elseif attached {INTEGER_16} an_object as i16 then create {JSON_NUMBER} Result.make_integer (i16) - elseif an_object.conforms_to (an_integer_32) then - i32 ?= an_object + elseif attached {INTEGER_32} an_object as i32 then create {JSON_NUMBER} Result.make_integer (i32) - elseif an_object.conforms_to (an_integer_64) then - i64 ?= an_object + elseif attached {INTEGER_64} an_object as i64 then create {JSON_NUMBER} Result.make_integer (i64) - elseif an_object.conforms_to (a_natural_8) then - n8 ?= an_object + elseif attached {NATURAL_8} an_object as n8 then create {JSON_NUMBER} Result.make_natural (n8) - elseif an_object.conforms_to (a_natural_16) then - n16 ?= an_object + elseif attached {NATURAL_16} an_object as n16 then create {JSON_NUMBER} Result.make_natural (n16) - elseif an_object.conforms_to (a_natural_32) then - n32 ?= an_object + elseif attached {NATURAL_32} an_object as n32 then create {JSON_NUMBER} Result.make_natural (n32) - elseif an_object.conforms_to (a_natural_64) then - n64 ?= an_object + elseif attached {NATURAL_64} an_object as n64 then create {JSON_NUMBER} Result.make_natural (n64) - elseif an_object.conforms_to (a_real_32) then - r32 ?= an_object + elseif attached {REAL_32} an_object as r32 then create {JSON_NUMBER} Result.make_real (r32) - elseif an_object.conforms_to (a_real_64) then - r64 ?= an_object + elseif attached {REAL_64} an_object as r64 then create {JSON_NUMBER} Result.make_real (r64) - elseif an_object.conforms_to (an_array) then - a ?= an_object + elseif attached {ARRAY [detachable ANY]} an_object as a then create ja.make_array from i := a.lower until i > a.upper loop - ja.add (value (a @ i)) + if attached value (a @ i) as v then + ja.add (v) + else + check value_attached: False end + end i := i + 1 end Result := ja - elseif an_object.conforms_to (a_character) then - c ?= an_object - create {JSON_STRING} Result.make_json (c.out) - elseif an_object.conforms_to (a_uc_string) then - ucs ?= an_object - create {JSON_STRING} Result.make_json (ucs.to_utf8) - elseif an_object.conforms_to (a_string_8) then - s8 ?= an_object + elseif attached {CHARACTER_8} an_object as c8 then + create {JSON_STRING} Result.make_json (c8.out) + elseif attached {CHARACTER_32} an_object as c32 then + create {JSON_STRING} Result.make_json (c32.out) + + elseif attached {STRING_8} an_object as s8 then create {JSON_STRING} Result.make_json (s8) + elseif attached {STRING_32} an_object as s32 then + create {JSON_STRING} Result.make_json (s32.as_string_8) -- FIXME: need correct convertion/encoding here ... end - + if Result = Void then -- Now check the converters - jc := converter_for (an_object) - if jc /= Void then + if an_object /= Void and then attached converter_for (an_object) as jc then Result := jc.to_json (an_object) else raise (exception_failed_to_convert_to_json (an_object)) @@ -107,118 +82,108 @@ feature -- Access end end - object (a_value: JSON_VALUE; base_class: ?STRING): ANY is + object (a_value: detachable JSON_VALUE; base_class: detachable STRING): detachable ANY -- Eiffel object from JSON value. If `base_class' /= Void an eiffel -- object based on `base_class' will be returned. Raises an "eJSON -- exception" if unable to convert value. - require - a_value_not_void: a_value /= Void local - jc: JSON_CONVERTER - jb: JSON_BOOLEAN - jn: JSON_NUMBER - js: JSON_STRING - ja: JSON_ARRAY - jo: JSON_OBJECT i: INTEGER - ll: LINKED_LIST [ANY] - t: HASH_TABLE [ANY, UC_STRING] + ll: LINKED_LIST [detachable ANY] + t: HASH_TABLE [detachable ANY, STRING_GENERAL] keys: ARRAY [JSON_STRING] - ucs: UC_STRING + s32: STRING_32 + s: detachable STRING_GENERAL do - if base_class = Void then - if a_value.generator.is_equal ("JSON_NULL") then - Result := Void - elseif a_value.generator.is_equal ("JSON_BOOLEAN") then - jb ?= a_value - check jb /= Void end - Result := jb.item - elseif a_value.generator.is_equal ("JSON_NUMBER") then - jn ?= a_value - check jn /= Void end - if jn.item.is_integer_8 then - Result := jn.item.to_integer_8 - elseif jn.item.is_integer_16 then - Result := jn.item.to_integer_16 - elseif jn.item.is_integer_32 then - Result := jn.item.to_integer_32 - elseif jn.item.is_integer_64 then - Result := jn.item.to_integer_64 - elseif jn.item.is_natural_64 then - Result := jn.item.to_natural_64 - elseif jn.item.is_double then - Result := jn.item.to_double - end - elseif a_value.generator.is_equal ("JSON_STRING") then - js ?= a_value - check js /= Void end - create ucs.make_from_string (js.item) - Result := ucs - elseif a_value.generator.is_equal ("JSON_ARRAY") then - ja ?= a_value - check ja /= Void end - from - create ll.make () - i := 1 - until - i > ja.count - loop - ll.extend (object (ja [i], Void)) - i := i + 1 - end - Result := ll - elseif a_value.generator.is_equal ("JSON_OBJECT") then - jo ?= a_value - check jo /= Void end - keys := jo.current_keys - create t.make (keys.count) - from - i := keys.lower - until - i > keys.upper - loop - ucs ?= object (keys [i], Void) - check ucs /= Void end - t.put (object (jo.item (keys [i]), Void), ucs) - i := i + 1 - end - Result := t - end - else - if converters.has (base_class) then - jc := converters @ base_class - Result := jc.from_json (a_value) - else - raise (exception_failed_to_convert_to_eiffel (a_value, base_class)) - end - end + if a_value = Void then + Result := Void + else + if base_class = Void then + if a_value = Void then + Result := Void + elseif attached {JSON_NULL} a_value then + Result := Void + elseif attached {JSON_BOOLEAN} a_value as jb then + Result := jb.item + elseif attached {JSON_NUMBER} a_value as jn then + if jn.item.is_integer_8 then + Result := jn.item.to_integer_8 + elseif jn.item.is_integer_16 then + Result := jn.item.to_integer_16 + elseif jn.item.is_integer_32 then + Result := jn.item.to_integer_32 + elseif jn.item.is_integer_64 then + Result := jn.item.to_integer_64 + elseif jn.item.is_natural_64 then + Result := jn.item.to_natural_64 + elseif jn.item.is_double then + Result := jn.item.to_double + end + elseif attached {JSON_STRING} a_value as js then + create s32.make_from_string (js.item) + Result := s32 + elseif attached {JSON_ARRAY} a_value as ja then + from + create ll.make + i := 1 + until + i > ja.count + loop + ll.extend (object (ja [i], Void)) + i := i + 1 + end + Result := ll + elseif attached {JSON_OBJECT} a_value as jo then + keys := jo.current_keys + create t.make (keys.count) + from + i := keys.lower + until + i > keys.upper + loop + s ?= object (keys [i], Void) + check s /= Void end + t.put (object (jo.item (keys [i]), Void), s) + i := i + 1 + end + Result := t + end + else + if converters.has_key (base_class) and then attached converters.found_item as jc then + Result := jc.from_json (a_value) + else + raise (exception_failed_to_convert_to_eiffel (a_value, base_class)) + end + end + end end - object_from_json (json: STRING; base_class: ?STRING): ANY is - -- Eiffel object from JSON representation. If `base_class' /= Void an - -- Eiffel object based on `base_class' will be returned. Raises an + object_from_json (json: STRING; base_class: detachable STRING): detachable ANY + -- Eiffel object from JSON representation. If `base_class' /= Void an + -- Eiffel object based on `base_class' will be returned. Raises an -- "eJSON exception" if unable to convert value. require json_not_void: json /= Void local - jv: JSON_VALUE + jv: detachable JSON_VALUE do json_parser.set_representation (json) jv := json_parser.parse - Result := object (jv, base_class) + if jv /= Void then + Result := object (jv, base_class) + end end - converter_for (an_object: ANY): JSON_CONVERTER is + converter_for (an_object: ANY): detachable JSON_CONVERTER -- Converter for objects. Returns Void if none found. require an_object_not_void: an_object /= Void do - if converters.has (an_object.generator) then - Result := converters @ an_object.generator + if converters.has_key (an_object.generator) then + Result := converters.found_item end end - - json_reference (s: STRING): JSON_OBJECT is + + json_reference (s: STRING): JSON_OBJECT -- A JSON (Dojo style) reference object using `s' as the -- reference value. The caller is responsable for ensuring -- the validity of `s' as a json reference. @@ -232,21 +197,20 @@ feature -- Access create js_value.make_json (s) Result.put (js_value, js_key) end - - json_references (l: DS_LIST [STRING]): JSON_ARRAY is - -- A JSON array of JSON (Dojo style) reference objects using the - -- strings in `l' as reference values. The caller is responsable - -- for ensuring the validity of all strings in `l' as json + + json_references (l: LIST [STRING]): JSON_ARRAY + -- A JSON array of JSON (Dojo style) reference objects using the + -- strings in `l' as reference values. The caller is responsable + -- for ensuring the validity of all strings in `l' as json -- references. require l_not_void: l /= Void local - c: DS_LIST_CURSOR [STRING] + c: ITERATION_CURSOR [STRING] do create Result.make_array from c := l.new_cursor - c.start until c.after loop @@ -254,10 +218,10 @@ feature -- Access c.forth end end - + feature -- Change - add_converter (jc: JSON_CONVERTER) is + add_converter (jc: JSON_CONVERTER) -- Add the converter `jc'. require jc_not_void: jc /= Void @@ -269,7 +233,7 @@ feature -- Change feature {NONE} -- Implementation - converters: DS_HASH_TABLE [JSON_CONVERTER, STRING] is + converters: HASH_TABLE [JSON_CONVERTER, STRING] -- Converters hashed by generator (base class) once create Result.make (10) @@ -277,9 +241,9 @@ feature {NONE} -- Implementation feature {NONE} -- Implementation (Exceptions) - exception_prefix: STRING is "eJSON exception: " - - exception_failed_to_convert_to_eiffel (a_value: JSON_VALUE; base_class: ?STRING): STRING is + exception_prefix: STRING = "eJSON exception: " + + exception_failed_to_convert_to_eiffel (a_value: JSON_VALUE; base_class: detachable STRING): STRING -- Exception message for failing to convert a JSON_VALUE to an instance of `a'. do Result := exception_prefix + "Failed to convert JSON_VALUE to an Eiffel object: " + a_value.generator @@ -288,15 +252,18 @@ feature {NONE} -- Implementation (Exceptions) end end - exception_failed_to_convert_to_json (an_object: ?ANY): STRING is + exception_failed_to_convert_to_json (an_object: detachable ANY): STRING -- Exception message for failing to convert `a' to a JSON_VALUE. do - Result := exception_prefix + "Failed to convert Eiffel object to a JSON_VALUE: " + an_object.generator + Result := exception_prefix + "Failed to convert Eiffel object to a JSON_VALUE" + if an_object /= Void then + Result := ": " + an_object.generator + end end feature {NONE} -- Implementation (JSON parser) - json_parser: JSON_PARSER is + json_parser: JSON_PARSER once create Result.make_parser ("") end @@ -304,7 +271,7 @@ feature {NONE} -- Implementation (JSON parser) feature {NONE} -- Implementation (Basic Eiffel objects) a_boolean: BOOLEAN - + an_integer_8: INTEGER_8 an_integer_16: INTEGER_16 @@ -320,26 +287,26 @@ feature {NONE} -- Implementation (Basic Eiffel objects) a_natural_32: NATURAL_32 a_natural_64: NATURAL_64 - + a_real_32: REAL_32 a_real_64: REAL_64 - an_array: ARRAY [ANY] is + an_array: ARRAY [ANY] once Result := <<>> end - + a_character: CHARACTER - - a_string_8: STRING_8 is + + a_string_8: STRING_8 once Result := "" end - a_uc_string: UC_STRING is + a_string_32: STRING_32 once - create Result.make_from_string ("") + Result := {STRING_32} "" end - -end -- class EJSON \ No newline at end of file + +end -- class EJSON diff --git a/library/kernel/json_array.e b/library/kernel/json_array.e index b71bc48d..dc51e1cb 100644 --- a/library/kernel/json_array.e +++ b/library/kernel/json_array.e @@ -1,4 +1,4 @@ -indexing +note description: "[ JSON_ARRAY represent an array in JSON. An array in JSON is an ordered set of names. @@ -25,7 +25,7 @@ create feature {NONE} -- Initialization - make_array is + make_array -- Initialize JSON Array do create values.make (10) @@ -33,7 +33,7 @@ feature {NONE} -- Initialization feature -- Access - i_th alias "[]" (i: INTEGER): JSON_VALUE is + i_th alias "[]" (i: INTEGER): JSON_VALUE -- Item at `i'-th position require is_valid_index: valid_index (i) @@ -41,7 +41,7 @@ feature -- Access Result := values.i_th (i) end - representation: STRING is + representation: STRING local i: INTEGER do @@ -59,10 +59,10 @@ feature -- Access end Result.append_character (']') end - + feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_json_array' procedure on `a_visitor'.) do @@ -71,7 +71,7 @@ feature -- Visitor pattern feature -- Mesurement - count: INTEGER is + count: INTEGER -- Number of items. do Result := values.count @@ -79,7 +79,7 @@ feature -- Mesurement feature -- Status report - valid_index (i: INTEGER): BOOLEAN is + valid_index (i: INTEGER): BOOLEAN -- Is `i' a valid index? do Result := (1 <= i) and (i <= count) @@ -87,11 +87,11 @@ feature -- Status report feature -- Change Element - add (value: JSON_VALUE) is + add (value: JSON_VALUE) require value_not_null: value /= void do - values.extend(value) + values.extend (value) ensure has_new_value: old values.count + 1 = values.count and values.has (value) @@ -99,7 +99,7 @@ feature -- Change Element feature -- Report - hash_code: INTEGER is + hash_code: INTEGER -- Hash code value do from @@ -116,7 +116,7 @@ feature -- Report feature -- Conversion - array_representation: ARRAYED_LIST [JSON_VALUE] is + array_representation: ARRAYED_LIST [JSON_VALUE] -- Representation as a sequences of values do Result := values diff --git a/library/kernel/json_boolean.e b/library/kernel/json_boolean.e index 86b48dbc..32e7634a 100644 --- a/library/kernel/json_boolean.e +++ b/library/kernel/json_boolean.e @@ -1,4 +1,4 @@ -indexing +note description: "JSON Truth values" author: "Javier Velilla" date: "2008/08/24" @@ -15,7 +15,7 @@ create feature {NONE} -- Initialization - make_boolean (an_item: BOOLEAN) is + make_boolean (an_item: BOOLEAN) --Initialize. do item := an_item @@ -26,13 +26,13 @@ feature -- Access item: BOOLEAN -- Content - hash_code: INTEGER is + hash_code: INTEGER -- Hash code value do Result := item.hash_code end - representation: STRING is + representation: STRING do if item then Result := "true" @@ -43,7 +43,7 @@ feature -- Access feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_json_boolean' procedure on `a_visitor'.) do diff --git a/library/kernel/json_null.e b/library/kernel/json_null.e index d7609b37..176b7d38 100644 --- a/library/kernel/json_null.e +++ b/library/kernel/json_null.e @@ -1,4 +1,4 @@ -indexing +note description: "JSON Null Values" author: "Javier Velilla" date: "2008/08/24" @@ -12,20 +12,20 @@ inherit feature --Access - hash_code: INTEGER is + hash_code: INTEGER -- Hash code value do Result := null_value.hash_code end - representation: STRING is + representation: STRING do Result := "null" end feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_element_a' procedure on `a_visitor'.) do @@ -42,6 +42,6 @@ feature -- Status report feature {NONE}-- Implementation - null_value: STRING is "null" + null_value: STRING = "null" end diff --git a/library/kernel/json_number.e b/library/kernel/json_number.e index 2f939684..69b5011e 100644 --- a/library/kernel/json_number.e +++ b/library/kernel/json_number.e @@ -1,4 +1,4 @@ -indexing +note description: "JSON Numbers, octal and hexadecimal formats are not used." author: "Javier Velilla" @@ -22,21 +22,21 @@ create feature {NONE} -- initialization - make_integer (an_argument: INTEGER_64) is + make_integer (an_argument: INTEGER_64) -- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'. do item := an_argument.out numeric_type := INTEGER_TYPE end - make_natural (an_argument: NATURAL_64) is + make_natural (an_argument: NATURAL_64) -- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'. do item := an_argument.out numeric_type := NATURAL_TYPE end - make_real (an_argument: DOUBLE) is + make_real (an_argument: DOUBLE) -- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'. do item := an_argument.out @@ -48,20 +48,20 @@ feature -- Access item: STRING -- Content - hash_code: INTEGER is + hash_code: INTEGER --Hash code value do Result := item.hash_code end - representation: STRING is + representation: STRING do Result := item end feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_json_number' procedure on `a_visitor'.) do @@ -70,7 +70,7 @@ feature -- Visitor pattern feature -- Status - is_equal (other: like Current): BOOLEAN is + is_equal (other: like Current): BOOLEAN -- Is `other' attached to an object of the same type -- as current object and identical to it? do @@ -87,9 +87,9 @@ feature -- Status report feature -- Implementation - INTEGER_TYPE: INTEGER is 1 - DOUBLE_TYPE: INTEGER is 2 - NATURAL_TYPE: INTEGER is 3 + INTEGER_TYPE: INTEGER = 1 + DOUBLE_TYPE: INTEGER = 2 + NATURAL_TYPE: INTEGER = 3 numeric_type: INTEGER diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index d91b1823..bd57aeec 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -1,4 +1,4 @@ -indexing +note description: "[ An JSON_OBJECT represent an object in JSON. @@ -27,7 +27,7 @@ create feature {NONE} -- Initialization - make is + make -- Initialize do create object.make (10) @@ -35,13 +35,13 @@ feature {NONE} -- Initialization feature -- Change Element - put (value: ?JSON_VALUE; key: JSON_STRING) is + put (value: detachable JSON_VALUE; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. require key_not_present: not has_key (key) local - l_value: ?JSON_VALUE + l_value: detachable JSON_VALUE do l_value := value if l_value = Void then @@ -52,31 +52,31 @@ feature -- Change Element feature -- Access - has_key (key: JSON_STRING): BOOLEAN is + has_key (key: JSON_STRING): BOOLEAN -- has the JSON_OBJECT contains a specific key 'key'. do Result := object.has (key) end - has_item (value: JSON_VALUE): BOOLEAN is + has_item (value: JSON_VALUE): BOOLEAN -- has the JSON_OBJECT contain a specfic item 'value' do Result := object.has_item (value) end - item (key: JSON_STRING): ?JSON_VALUE is + item (key: JSON_STRING): detachable JSON_VALUE -- the json_value associated with a key. do Result := object.item (key) end - current_keys: ARRAY [JSON_STRING] is + current_keys: ARRAY [JSON_STRING] -- array containing actually used keys do Result := object.current_keys end - representation: STRING is + representation: STRING local t: HASH_TABLE [JSON_VALUE, JSON_STRING] do @@ -100,7 +100,7 @@ feature -- Access feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_json_object' procedure on `a_visitor'.) do @@ -109,7 +109,7 @@ feature -- Visitor pattern feature -- Conversion - map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING] is + map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING] --A representation that maps keys to values do Result := object @@ -117,7 +117,7 @@ feature -- Conversion feature -- Report - hash_code: INTEGER is + hash_code: INTEGER -- Hash code value do from diff --git a/library/kernel/json_string.e b/library/kernel/json_string.e index 39afdb0c..274776a1 100644 --- a/library/kernel/json_string.e +++ b/library/kernel/json_string.e @@ -1,6 +1,6 @@ -indexing +note - description:"[ + description: "[ A JSON_STRING represent a string in JSON. A string is a collection of zero or more Unicodes characters, wrapped in double quotes, using blackslash espaces. @@ -26,7 +26,7 @@ create feature {NONE} -- Initialization - make_json (an_item: STRING) is + make_json (an_item: STRING) -- Initialize. require item_not_void: an_item /= Void @@ -39,7 +39,7 @@ feature -- Access item: STRING -- Contents - representation: STRING is + representation: STRING do Result := "%"" Result.append (item) @@ -48,7 +48,7 @@ feature -- Access feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_json_string' procedure on `a_visitor'.) do @@ -57,7 +57,7 @@ feature -- Visitor pattern feature -- Comparison - is_equal (other: like Current): BOOLEAN is + is_equal (other: like Current): BOOLEAN -- Is JSON_STRING made of same character sequence as `other' -- (possibly with a different capacity)? do @@ -66,7 +66,7 @@ feature -- Comparison feature -- Change Element - append (a_string: STRING)is + append (a_string: STRING) -- Add an_item require a_string_not_void: a_string /= Void @@ -76,7 +76,7 @@ feature -- Change Element feature -- Status report - hash_code: INTEGER is + hash_code: INTEGER -- Hash code value do Result := item.hash_code @@ -92,7 +92,7 @@ feature -- Status report feature {NONE} -- Implementation - escaped_json_string (s: STRING): STRING is + escaped_json_string (s: STRING): STRING -- JSON string with '"' and '\' characters escaped require s_not_void: s /= Void diff --git a/library/kernel/json_value.e b/library/kernel/json_value.e index 63aa7bbe..bbf47c7c 100644 --- a/library/kernel/json_value.e +++ b/library/kernel/json_value.e @@ -1,4 +1,4 @@ -indexing +note description:"[ JSON_VALUE represent a value in JSON. A value can be @@ -25,14 +25,14 @@ inherit feature -- Access - representation: STRING is + representation: STRING -- UTF-8 encoded Unicode string representation of Current deferred end feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) is + accept (a_visitor: JSON_VISITOR) -- Accept `a_visitor'. -- (Call `visit_*' procedure on `a_visitor'.) require diff --git a/library/kernel/scanner/json_parser.e b/library/kernel/scanner/json_parser.e index 50acfcf5..089d28b5 100644 --- a/library/kernel/scanner/json_parser.e +++ b/library/kernel/scanner/json_parser.e @@ -1,4 +1,4 @@ -indexing +note description: "Parse serialized JSON data" author: "jvelilla" @@ -17,7 +17,7 @@ create feature {NONE} -- Initialize - make_parser (a_json: STRING) is + make_parser (a_json: STRING) -- Initialize. require json_not_empty: a_json /= Void and then not a_json.is_empty @@ -51,7 +51,7 @@ feature -- Status report feature -- Element change - report_error (e: STRING) is + report_error (e: STRING) -- Report error `e' require e_not_void: e /= Void @@ -61,7 +61,7 @@ feature -- Element change feature -- Commands - parse_json: ?JSON_VALUE is + parse_json: detachable JSON_VALUE -- Parse JSON data `representation' -- start ::= object | array do @@ -76,7 +76,7 @@ feature -- Commands end end - parse: ?JSON_VALUE is + parse: detachable JSON_VALUE -- Parse JSON data `representation' local c: CHARACTER @@ -121,14 +121,14 @@ feature -- Commands is_parsed_implies_result_not_void: is_parsed implies Result /= Void end - parse_object: JSON_OBJECT is + parse_object: JSON_OBJECT -- object -- {} -- {"key" : "value" [,]} local has_more: BOOLEAN - l_json_string: ?JSON_STRING - l_value: ?JSON_VALUE + l_json_string: detachable JSON_STRING + l_value: detachable JSON_VALUE do create Result.make -- check if is an empty object {} @@ -174,7 +174,7 @@ feature -- Commands end end - parse_string: ?JSON_STRING is + parse_string: detachable JSON_STRING -- Parsed string local has_more: BOOLEAN @@ -200,7 +200,7 @@ feature -- Commands create l_unicode.make_from_string ("\u") l_unicode.append (read_unicode) c := actual - if is_a_valid_unicode (l_unicode) then + if is_valid_unicode (l_unicode) then l_json_string.append (l_unicode) else has_more := False @@ -231,13 +231,13 @@ feature -- Commands end end - parse_array: JSON_ARRAY is + parse_array: JSON_ARRAY -- array -- [] -- [elements [,]] local flag: BOOLEAN - l_value: ?JSON_VALUE + l_value: detachable JSON_VALUE c: like actual do create Result.make_array @@ -276,7 +276,7 @@ feature -- Commands end end - parse_number: ?JSON_NUMBER is + parse_number: detachable JSON_NUMBER -- Parsed number local sb: STRING @@ -304,7 +304,7 @@ feature -- Commands end end - if is_a_valid_number (sb) then + if is_valid_number (sb) then if sb.is_integer then create Result.make_integer (sb.to_integer) is_integer := True @@ -317,7 +317,7 @@ feature -- Commands end end - is_null: BOOLEAN is + is_null: BOOLEAN -- Word at index represents null? local l_null: STRING @@ -330,7 +330,7 @@ feature -- Commands end end - is_false: BOOLEAN is + is_false: BOOLEAN -- Word at index represents false? local l_false: STRING @@ -343,7 +343,7 @@ feature -- Commands end end - is_true: BOOLEAN is + is_true: BOOLEAN -- Word at index represents true? local l_true: STRING @@ -356,7 +356,7 @@ feature -- Commands end end - read_unicode: STRING is + read_unicode: STRING -- Read unicode and return value local i: INTEGER @@ -375,27 +375,83 @@ feature -- Commands feature {NONE} -- Implementation - is_a_valid_number (a_number: STRING): BOOLEAN is + is_valid_number (a_number: STRING): BOOLEAN -- is 'a_number' a valid number based on this regular expression -- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"? - local - word_set: RX_CHARACTER_SET - regexp: RX_PCRE_REGULAR_EXPRESSION - number_regex: STRING - do - create regexp.make - create word_set.make_empty - a_number.right_adjust - a_number.left_adjust - word_set.add_string ("0123456789.eE+-") - regexp.set_word_set (word_set) - number_regex := "-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?\b" - regexp.compile (number_regex) - if regexp.matches (a_number) then - Result := a_number.is_equal (regexp.captured_substring (0)) - end - end - is_a_valid_unicode (a_unicode: STRING): BOOLEAN is + local + s: detachable STRING + c: CHARACTER + i,n: INTEGER + do + create s.make_empty + n := a_number.count + if n = 0 then + Result := False + else + Result := True + i := 1 + --| "-?" + c := a_number[i] + if c = '-' then + s.extend (c); i := i + 1; c := a_number[i] + end + --| "0|[1-9]\d* + if c.is_digit then + if c = '0' then + --| "0" + s.extend (c); i := i + 1; c := a_number[i] + else + --| "[1-9]" + s.extend (c); i := i + 1; c := a_number[i] + --| "\d*" + from until i > n or not c.is_digit loop + s.extend (c); i := i + 1; c := a_number[i] + end + end + end + end + if Result then + --| "(\.\d+)?" + if c = '.' then + --| "\.\d+" = "\.\d\d*" + s.extend (c); i := i + 1; c := a_number[i] + if c.is_digit then + from until i > n or not c.is_digit loop + s.extend (c); i := i + 1; c := a_number[i] + end + else + Result := False --| expecting digit + end + end + end + if Result then --| "(?:[eE][+-]?\d+)?\b" + if c = 'e' or c = 'E' then + --| "[eE][+-]?\d+" + s.extend (c); i := i + 1; c := a_number[i] + if c = '+' or c = '-' then + s.extend (c); i := i + 1; c := a_number[i] + end + if c.is_digit then + from until i > n or not c.is_digit loop + s.extend (c); i := i + 1; c := a_number[i] + end + else + Result := False --| expecting digit + end + end + end + if Result then --| "\b" + from until i > n or not c.is_space loop + s.extend (c); i := i + 1; c := a_number[i] + end + Result := i > n + if Result then + Result := s.same_string (a_number) + end + end + end + + is_valid_unicode (a_unicode: STRING): BOOLEAN -- is 'a_unicode' a valid unicode based on this regular expression -- "\\u[0-9a-fA-F]{4}" local @@ -423,7 +479,7 @@ feature {NONE} -- Implementation end end - extra_elements: BOOLEAN is + extra_elements: BOOLEAN -- has more elements? local c: like actual @@ -449,11 +505,11 @@ feature {NONE} -- Implementation feature {NONE} -- Constants - false_id: STRING is "false" + false_id: STRING = "false" - true_id: STRING is "true" + true_id: STRING = "true" - null_id: STRING is "null" + null_id: STRING = "null" end diff --git a/library/kernel/scanner/json_reader.e b/library/kernel/scanner/json_reader.e index 151019c3..12a074ea 100644 --- a/library/kernel/scanner/json_reader.e +++ b/library/kernel/scanner/json_reader.e @@ -1,4 +1,4 @@ -indexing +note description: "Objects that ..." author: "jvelilla" date: "2008/08/24" @@ -12,7 +12,7 @@ create feature {NONE} -- Initialization - make (a_json: STRING) is + make (a_json: STRING) -- Initialize Reader do set_representation (a_json) @@ -20,7 +20,7 @@ feature {NONE} -- Initialization feature -- Commands - set_representation (a_json: STRING) is + set_representation (a_json: STRING) -- Set `representation'. do a_json.left_adjust @@ -29,7 +29,7 @@ feature -- Commands index := 1 end - read: CHARACTER is + read: CHARACTER -- Read character do if not representation.is_empty then @@ -37,7 +37,7 @@ feature -- Commands end end - next is + next -- Move to next index require has_more_elements: has_next @@ -47,7 +47,7 @@ feature -- Commands incremented: old index + 1 = index end - previous is + previous -- Move to previous index require not_is_first: has_previous @@ -57,7 +57,7 @@ feature -- Commands incremented: old index - 1 = index end - skip_white_spaces is + skip_white_spaces -- Remove white spaces local c: like actual @@ -72,7 +72,7 @@ feature -- Commands end end - json_substring (start_index, end_index: INTEGER_32): STRING is + json_substring (start_index, end_index: INTEGER_32): STRING -- JSON representation between `start_index' and `end_index' do Result := representation.substring (start_index, end_index) @@ -80,13 +80,13 @@ feature -- Commands feature -- Status report - has_next: BOOLEAN is + has_next: BOOLEAN -- Has a next character? do Result := index <= representation.count end - has_previous: BOOLEAN is + has_previous: BOOLEAN -- Has a previous character? do Result := index >= 1 @@ -99,7 +99,7 @@ feature -- Access feature {NONE} -- Implementation - actual: CHARACTER is + actual: CHARACTER -- Current character or '%U' if none do if index > representation.count then diff --git a/library/kernel/scanner/json_tokens.e b/library/kernel/scanner/json_tokens.e index 319a044c..db8dd9df 100644 --- a/library/kernel/scanner/json_tokens.e +++ b/library/kernel/scanner/json_tokens.e @@ -1,4 +1,4 @@ -indexing +note description: "" author: "jvelilla" date: "2008/08/24" @@ -9,19 +9,19 @@ class feature -- Access - j_OBJECT_OPEN: CHARACTER is '{' - j_ARRAY_OPEN: CHARACTER is '[' - j_OBJECT_CLOSE: CHARACTER is '}' - j_ARRAY_CLOSE: CHARACTER is ']' + j_OBJECT_OPEN: CHARACTER = '{' + j_ARRAY_OPEN: CHARACTER = '[' + j_OBJECT_CLOSE: CHARACTER = '}' + j_ARRAY_CLOSE: CHARACTER = ']' - j_STRING: CHARACTER is '"' - j_PLUS: CHARACTER is '+' - j_MINUS: CHARACTER is '-' - j_DOT: CHARACTER is '.' + j_STRING: CHARACTER = '"' + j_PLUS: CHARACTER = '+' + j_MINUS: CHARACTER = '-' + j_DOT: CHARACTER = '.' feature -- Status report - is_open_token (c: CHARACTER): BOOLEAN is + is_open_token (c: CHARACTER): BOOLEAN -- Characters which open a type do inspect c @@ -32,7 +32,7 @@ feature -- Status report end end - is_close_token (c: CHARACTER): BOOLEAN is + is_close_token (c: CHARACTER): BOOLEAN -- Characters which close a type do inspect c @@ -43,7 +43,7 @@ feature -- Status report end end - is_special_character (c: CHARACTER): BOOLEAN is + is_special_character (c: CHARACTER): BOOLEAN -- Control Characters -- %F Form feed -- %H backslasH @@ -62,7 +62,7 @@ feature -- Status report end end - is_special_control (c: CHARACTER): BOOLEAN is + is_special_control (c: CHARACTER): BOOLEAN --Control Characters -- \b\f\n\r\t do diff --git a/library/kernel/shared_ejson.e b/library/kernel/shared_ejson.e index 4d6ef7f5..d08a6766 100644 --- a/library/kernel/shared_ejson.e +++ b/library/kernel/shared_ejson.e @@ -1,4 +1,4 @@ -indexing +note description: "[ Shared factory class for creating JSON objects. Maps JSON objects to ELKS HASH_TABLEs and JSON arrays to ELKS @@ -15,7 +15,7 @@ class SHARED_EJSON feature - json: EJSON is + json: EJSON -- A shared EJSON instance with default converters for -- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE] local diff --git a/test/autotest/test_suite/test_json_suite.e b/test/autotest/test_suite/test_json_suite.e index 1f495c15..f1b95a92 100644 --- a/test/autotest/test_suite/test_json_suite.e +++ b/test/autotest/test_suite/test_json_suite.e @@ -1,374 +1,395 @@ -note - description: "[ - Eiffel tests that can be executed by testing tool. - ]" - author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" - testing: "type/manual" - -class - TEST_JSON_SUITE - -inherit - EQA_TEST_SET - redefine - on_prepare - end - -feature {NONE} -- Events - - on_prepare - -- - do - create file_reader - end - - -feature -- Tests Pass - - test_json_pass1 is - -- - do - json_file:=file_reader.read_json_from (test_dir + "pass1.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("pass1.json",parse_json.is_parsed = True) - end - - test_json_pass2 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"pass2.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("pass2.json",parse_json.is_parsed = True) - end - - test_json_pass3 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"pass3.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("pass3.json",parse_json.is_parsed = True) - end - -feature -- Tests Failures - test_json_fail1 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail1.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail1.json",parse_json.is_parsed = False) - end - - test_json_fail2 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail2.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail2.json",parse_json.is_parsed = False) - end - - test_json_fail3 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail3.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail3.json",parse_json.is_parsed = False) - end - - test_json_fail4 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail4.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail4.json",parse_json.is_parsed = False) - end - - test_json_fail5 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail5.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail5.json",parse_json.is_parsed = False) - end - - - test_json_fail6 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail6.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail6.json",parse_json.is_parsed = False ) - end - - test_json_fail7 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail7.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail7.json",parse_json.is_parsed = False) - end - - test_json_fail8 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail8.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail8.json",parse_json.is_parsed = False ) - end - - - test_json_fail9 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail9.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail9.json",parse_json.is_parsed = False) - end - - - test_json_fail10 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail10.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail10.json",parse_json.is_parsed = False) - end - - test_json_fail11 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail11.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail11.json",parse_json.is_parsed = False) - end - - test_json_fail12 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail12.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail12.json",parse_json.is_parsed = False) - end - - test_json_fail13 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail13.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail13.json",parse_json.is_parsed = False) - end - - test_json_fail14 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail14.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail14.json",parse_json.is_parsed = False) - end - - test_json_fail15 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail15.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail15.json",parse_json.is_parsed = False) - end - - test_json_fail16 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail16.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail16.json",parse_json.is_parsed = False) - end - - test_json_fail17 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail17.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail17.json",parse_json.is_parsed = False) - end - - test_json_fail18 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail18.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail18.json",parse_json.is_parsed = True) - end - - test_json_fail19 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail19.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail19.json",parse_json.is_parsed = False) - end - - test_json_fail20 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail20.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail20.json",parse_json.is_parsed = False) - end - - test_json_fail21 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail21.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail21.json",parse_json.is_parsed = False) - end - - - test_json_fail22 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail22.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail22.json",parse_json.is_parsed = False) - end - - test_json_fail23 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail23.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail23.json",parse_json.is_parsed = False) - end - - test_json_fail24 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail24.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail24.json",parse_json.is_parsed = False) - end - - test_json_fail25 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail25.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail25.json",parse_json.is_parsed = False) - end - - - test_json_fail26 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail26.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail26.json",parse_json.is_parsed = False) - end - - - test_json_fail27 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail27.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail27.json",parse_json.is_parsed = False) - end - - - test_json_fail28 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail28.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail28.json",parse_json.is_parsed = False) - end - - - test_json_fail29 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail29.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail29.json",parse_json.is_parsed = False ) - end - - - test_json_fail30 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail30.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail30.json",parse_json.is_parsed = False) - end - - test_json_fail31 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail31.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail31.json",parse_json.is_parsed = False) - end - - test_json_fail32 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail32.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail32.json",parse_json.is_parsed = False) - end - - test_json_fail33 is - -- - do - json_file:=file_reader.read_json_from (test_dir +"fail33.json") - create parse_json.make_parser (json_file) - json_value := parse_json.parse_json - assert ("fail33.json",parse_json.is_parsed = False) - end -feature -- JSON_FROM_FILE - - json_file:STRING - parse_json:JSON_PARSER - json_object:JSON_OBJECT - file_reader:JSON_FILE_READER - json_value : JSON_VALUE - test_dir : STRING is "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/" - -end - - +note + description: "[ + Eiffel tests that can be executed by testing tool. + ]" + author: "EiffelStudio test wizard" + date: "$Date$" + revision: "$Revision$" + testing: "type/manual" + +class + TEST_JSON_SUITE + +inherit + EQA_TEST_SET + redefine + on_prepare + end + +feature {NONE} -- Events + + on_prepare + -- + do + create file_reader + end + + +feature -- Tests Pass + + test_json_pass1 + -- + do + json_file:=file_reader.read_json_from (test_dir + "pass1.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("pass1.json",parse_json.is_parsed = True) + end + + test_json_pass2 + -- + do + json_file:=file_reader.read_json_from (test_dir +"pass2.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("pass2.json",parse_json.is_parsed = True) + end + + test_json_pass3 + -- + do + json_file:=file_reader.read_json_from (test_dir +"pass3.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("pass3.json",parse_json.is_parsed = True) + end + +feature -- Tests Failures + test_json_fail1 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail1.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail1.json",parse_json.is_parsed = False) + end + + test_json_fail2 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail2.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail2.json",parse_json.is_parsed = False) + end + + test_json_fail3 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail3.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail3.json",parse_json.is_parsed = False) + end + + test_json_fail4 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail4.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail4.json",parse_json.is_parsed = False) + end + + test_json_fail5 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail5.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail5.json",parse_json.is_parsed = False) + end + + + test_json_fail6 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail6.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail6.json",parse_json.is_parsed = False ) + end + + test_json_fail7 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail7.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail7.json",parse_json.is_parsed = False) + end + + test_json_fail8 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail8.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail8.json",parse_json.is_parsed = False ) + end + + + test_json_fail9 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail9.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail9.json",parse_json.is_parsed = False) + end + + + test_json_fail10 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail10.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail10.json",parse_json.is_parsed = False) + end + + test_json_fail11 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail11.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail11.json",parse_json.is_parsed = False) + end + + test_json_fail12 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail12.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail12.json",parse_json.is_parsed = False) + end + + test_json_fail13 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail13.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail13.json",parse_json.is_parsed = False) + end + + test_json_fail14 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail14.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail14.json",parse_json.is_parsed = False) + end + + test_json_fail15 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail15.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail15.json",parse_json.is_parsed = False) + end + + test_json_fail16 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail16.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail16.json",parse_json.is_parsed = False) + end + + test_json_fail17 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail17.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail17.json",parse_json.is_parsed = False) + end + + test_json_fail18 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail18.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail18.json",parse_json.is_parsed = True) + end + + test_json_fail19 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail19.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail19.json",parse_json.is_parsed = False) + end + + test_json_fail20 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail20.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail20.json",parse_json.is_parsed = False) + end + + test_json_fail21 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail21.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail21.json",parse_json.is_parsed = False) + end + + + test_json_fail22 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail22.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail22.json",parse_json.is_parsed = False) + end + + test_json_fail23 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail23.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail23.json",parse_json.is_parsed = False) + end + + test_json_fail24 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail24.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail24.json",parse_json.is_parsed = False) + end + + test_json_fail25 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail25.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail25.json",parse_json.is_parsed = False) + end + + + test_json_fail26 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail26.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail26.json",parse_json.is_parsed = False) + end + + + test_json_fail27 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail27.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail27.json",parse_json.is_parsed = False) + end + + + test_json_fail28 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail28.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail28.json",parse_json.is_parsed = False) + end + + + test_json_fail29 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail29.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail29.json",parse_json.is_parsed = False ) + end + + + test_json_fail30 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail30.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail30.json",parse_json.is_parsed = False) + end + + test_json_fail31 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail31.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail31.json",parse_json.is_parsed = False) + end + + test_json_fail32 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail32.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail32.json",parse_json.is_parsed = False) + end + + test_json_fail33 + -- + do + json_file:=file_reader.read_json_from (test_dir +"fail33.json") + create parse_json.make_parser (json_file) + json_value := parse_json.parse_json + assert ("fail33.json",parse_json.is_parsed = False) + end + +feature -- JSON_FROM_FILE + + json_file : STRING + parse_json : JSON_PARSER + json_object : JSON_OBJECT + file_reader : JSON_FILE_READER + json_value : JSON_VALUE + test_dir : STRING + local + i: INTEGER + do + Result := (create {EXECUTION_ENVIRONMENT}).current_working_directory + Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator) + -- The should looks like + -- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json + from + i := 5 + until + i = 0 + loop + Result.append_character ('.') + Result.append_character ('.') + Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator) + i := i - 1 + end +-- Result := "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/" + end + invariant + file_reader /= Void +end + + diff --git a/test/autotest/test_suite/test_suite-safe.ecf b/test/autotest/test_suite/test_suite-safe.ecf new file mode 100644 index 00000000..3d3f9c37 --- /dev/null +++ b/test/autotest/test_suite/test_suite-safe.ecf @@ -0,0 +1,19 @@ + + + + + + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + diff --git a/test/autotest/test_suite/test_suite.ecf b/test/autotest/test_suite/test_suite.ecf index 880aa9cc..4d9ec8c7 100644 --- a/test/autotest/test_suite/test_suite.ecf +++ b/test/autotest/test_suite/test_suite.ecf @@ -1,7 +1,7 @@ - +