From 20e704604a297d28ddfe88378e2d8e7a5b827a87 Mon Sep 17 00:00:00 2001 From: Conaclos Date: Fri, 4 Jul 2014 17:59:05 +0200 Subject: [PATCH] Apply pretty print tool. Apply on each class in test suite and library. --- library/extras/file/json_file_reader.e | 4 +- library/extras/visitor/json_iterator.e | 10 +- .../visitor/json_pretty_string_visitor.e | 30 +- library/extras/visitor/json_visitor.e | 9 +- library/extras/visitor/print_json_visitor.e | 14 +- .../converters/json_arrayed_list_converter.e | 10 +- library/kernel/converters/json_converter.e | 32 +- .../converters/json_hash_table_converter.e | 110 +- .../converters/json_linked_list_converter.e | 10 +- .../kernel/converters/json_list_converter.e | 86 +- library/kernel/ejson.e | 20 +- library/kernel/json_array.e | 230 ++- library/kernel/json_boolean.e | 79 +- library/kernel/json_null.e | 59 +- library/kernel/json_number.e | 132 +- library/kernel/json_object.e | 458 +++--- library/kernel/json_string.e | 283 ++-- library/kernel/json_value.e | 60 +- library/kernel/scanner/json_parser.e | 161 +- library/kernel/scanner/json_reader.e | 26 +- library/kernel/scanner/json_tokens.e | 24 +- library/kernel/shared_ejson.e | 58 +- test/autotest/test_suite/application.e | 9 +- test/autotest/test_suite/author.e | 27 +- test/autotest/test_suite/book.e | 55 +- test/autotest/test_suite/book_collection.e | 94 +- .../test_suite/json_author_converter.e | 57 +- .../json_book_collection_converter.e | 77 +- .../autotest/test_suite/json_book_converter.e | 83 +- test/autotest/test_suite/test_ds.e | 106 +- test/autotest/test_suite/test_json_core.e | 1310 ++++++++--------- .../test_suite/test_json_custom_classes.e | 49 +- test/autotest/test_suite/test_json_suite.e | 216 ++- 33 files changed, 2005 insertions(+), 1983 deletions(-) diff --git a/library/extras/file/json_file_reader.e b/library/extras/file/json_file_reader.e index a7c60481..9537a547 100644 --- a/library/extras/file/json_file_reader.e +++ b/library/extras/file/json_file_reader.e @@ -26,7 +26,9 @@ feature -- Access create template_content.make_empty l_file.read_stream (l_file.count) l_last_string := l_file.last_string - check l_last_string /= Void end -- implied by postcondition of `l_file.read_stream' + check + l_last_string /= Void + end -- implied by postcondition of `l_file.read_stream' template_content.append (l_last_string.string) Result := template_content l_file.close diff --git a/library/extras/visitor/json_iterator.e b/library/extras/visitor/json_iterator.e index dae48dd1..3489ce85 100644 --- a/library/extras/visitor/json_iterator.e +++ b/library/extras/visitor/json_iterator.e @@ -1,11 +1,8 @@ note - description: - - "JSON Iterator" - + description: "JSON Iterator" pattern: "Iterator visitor" author: "Jocelyn Fiat" - license:"MIT (see http://www.opensource.org/licenses/mit-license.php)" + license: "MIT (see http://www.opensource.org/licenses/mit-license.php)" date: "2013/08/01" revision: "Revision 0.1" @@ -13,6 +10,7 @@ deferred class JSON_ITERATOR inherit + JSON_VISITOR feature -- Visitor Pattern @@ -52,7 +50,7 @@ feature -- Visitor Pattern end end - visit_json_string (a_json_string: JSON_STRING) + visit_json_string (a_json_string: JSON_STRING) -- Visit `a_json_string'. do end diff --git a/library/extras/visitor/json_pretty_string_visitor.e b/library/extras/visitor/json_pretty_string_visitor.e index 98b17c81..3ac76617 100644 --- a/library/extras/visitor/json_pretty_string_visitor.e +++ b/library/extras/visitor/json_pretty_string_visitor.e @@ -6,11 +6,11 @@ class JSON_PRETTY_STRING_VISITOR inherit + JSON_VISITOR create - make, - make_custom + make, make_custom feature -- Initialization @@ -26,7 +26,6 @@ feature -- Initialization output := a_output create indentation.make_empty indentation_step := "%T" - object_count_inlining := a_object_count_inlining array_count_inlining := a_array_count_inlining end @@ -34,7 +33,7 @@ feature -- Initialization feature -- Access output: STRING_32 - -- JSON representation + -- JSON representation indentation: like output @@ -60,6 +59,7 @@ feature -- Access end object_count_inlining: INTEGER + array_count_inlining: INTEGER feature -- Visitor Pattern @@ -82,10 +82,7 @@ feature -- Visitor Pattern until l_json_array.off loop - if - line_number > l_line or - l_multiple_lines - then + if line_number > l_line or l_multiple_lines then new_line end value := l_json_array.item @@ -96,10 +93,7 @@ feature -- Visitor Pattern end end exdent - if - line_number > l_line or - l_json_array.count >= array_count_inlining - then + if line_number > l_line or l_json_array.count >= array_count_inlining then new_line end output.append ("]") @@ -140,10 +134,7 @@ feature -- Visitor Pattern until l_pairs.off loop - if - line_number > l_line or - l_multiple_lines - then + if line_number > l_line or l_multiple_lines then new_line end l_pairs.key_for_iteration.accept (Current) @@ -155,16 +146,13 @@ feature -- Visitor Pattern end end exdent - if - line_number > l_line or - l_pairs.count >= object_count_inlining - then + if line_number > l_line or l_pairs.count >= object_count_inlining then new_line end output.append ("}") end - visit_json_string (a_json_string: JSON_STRING) + visit_json_string (a_json_string: JSON_STRING) -- Visit `a_json_string'. do output.append ("%"") diff --git a/library/extras/visitor/json_visitor.e b/library/extras/visitor/json_visitor.e index f032b564..a4fc6d3f 100644 --- a/library/extras/visitor/json_visitor.e +++ b/library/extras/visitor/json_visitor.e @@ -1,11 +1,8 @@ note - description: - - "JSON Visitor" - + description: "JSON Visitor" pattern: "Visitor" author: "Javier Velilla" - license:"MIT (see http://www.opensource.org/licenses/mit-license.php)" + license: "MIT (see http://www.opensource.org/licenses/mit-license.php)" date: "2008/08/24" revision: "Revision 0.1" @@ -49,7 +46,7 @@ feature -- Visitor Pattern deferred end - visit_json_string (a_json_string: JSON_STRING) + 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 6072769b..4dcd08a3 100644 --- a/library/extras/visitor/print_json_visitor.e +++ b/library/extras/visitor/print_json_visitor.e @@ -8,9 +8,11 @@ class PRINT_JSON_VISITOR inherit + JSON_VISITOR -create make +create + make feature -- Initialization @@ -23,7 +25,7 @@ feature -- Initialization feature -- Access to_json: STRING - -- JSON representation + -- JSON representation feature -- Visitor Pattern @@ -33,7 +35,7 @@ feature -- Visitor Pattern value: JSON_VALUE l_json_array: ARRAYED_LIST [JSON_VALUE] do - l_json_array:=a_json_array.array_representation + l_json_array := a_json_array.array_representation to_json.append ("[") from l_json_array.start @@ -44,7 +46,7 @@ feature -- Visitor Pattern value.accept (Current) l_json_array.forth if not l_json_array.after then - to_json.append(",") + to_json.append (",") end end to_json.append ("]") @@ -71,7 +73,7 @@ feature -- Visitor Pattern visit_json_object (a_json_object: JSON_OBJECT) -- Visit `a_json_object'. local - l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING] + l_pairs: HASH_TABLE [JSON_VALUE, JSON_STRING] do l_pairs := a_json_object.map_representation to_json.append ("{") @@ -91,7 +93,7 @@ feature -- Visitor Pattern to_json.append ("}") end - visit_json_string (a_json_string: JSON_STRING) + visit_json_string (a_json_string: JSON_STRING) -- Visit `a_json_string'. do to_json.append ("%"") diff --git a/library/kernel/converters/json_arrayed_list_converter.e b/library/kernel/converters/json_arrayed_list_converter.e index da089f7b..21bcd4d4 100644 --- a/library/kernel/converters/json_arrayed_list_converter.e +++ b/library/kernel/converters/json_arrayed_list_converter.e @@ -5,20 +5,22 @@ note revision: "$Revision$" file: "$HeadURL: $" -class JSON_ARRAYED_LIST_CONVERTER +class + JSON_ARRAYED_LIST_CONVERTER inherit - JSON_LIST_CONVERTER + + JSON_LIST_CONVERTER redefine object end create - make + make feature -- Access - object: ARRAYED_LIST [detachable ANY] + object: ARRAYED_LIST [detachable ANY] feature {NONE} -- Factory diff --git a/library/kernel/converters/json_converter.e b/library/kernel/converters/json_converter.e index 796ef4eb..b4d78a66 100644 --- a/library/kernel/converters/json_converter.e +++ b/library/kernel/converters/json_converter.e @@ -5,32 +5,34 @@ note revision: "$Revision$" file: "$HeadURL: $" -deferred class JSON_CONVERTER +deferred class + JSON_CONVERTER inherit - SHARED_EJSON + + SHARED_EJSON feature -- Access - object: ANY - -- Eiffel object - deferred - end + object: ANY + -- Eiffel object + deferred + end feature -- Conversion - from_json (j: attached like to_json): detachable like object - -- Convert from JSON value. + from_json (j: attached like to_json): detachable like object + -- Convert from JSON value. -- Returns Void if unable to convert - deferred - end + deferred + end - to_json (o: like object): detachable JSON_VALUE - -- Convert to JSON value - deferred - end + 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! + has_eiffel_object: object /= Void -- An empty object must be created at creation time! end diff --git a/library/kernel/converters/json_hash_table_converter.e b/library/kernel/converters/json_hash_table_converter.e index e1264de7..00b87374 100644 --- a/library/kernel/converters/json_hash_table_converter.e +++ b/library/kernel/converters/json_hash_table_converter.e @@ -1,76 +1,82 @@ note - description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]" - author: "Paul Cohen" + description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]" + author: "Paul Cohen" date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $" revision: "$Revision: 94128 $" - file: "$HeadURL: $" + file: "$HeadURL: $" -class JSON_HASH_TABLE_CONVERTER +class + JSON_HASH_TABLE_CONVERTER inherit - JSON_CONVERTER + + JSON_CONVERTER create - make + make feature {NONE} -- Initialization - make - do - create object.make (0) - end + make + do + create object.make (0) + end feature -- Access - object: HASH_TABLE [ANY, HASHABLE] + object: HASH_TABLE [ANY, HASHABLE] feature -- Conversion - from_json (j: attached like to_json): like object - do - create Result.make (j.count) - across - j as ic - loop - if attached json.object (ic.item, Void) as l_object then + from_json (j: attached like to_json): like object + do + create Result.make (j.count) + across + j as ic + loop + if attached json.object (ic.item, Void) as l_object then if attached {HASHABLE} json.object (ic.key, Void) as h then Result.put (l_object, h) else - check key_is_hashable: False end + check + key_is_hashable: False + end end - else - check object_attached: False end - end - end - end + else + check + object_attached: False + end + end + end + end - to_json (o: like object): detachable JSON_OBJECT - local - c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE] - js: JSON_STRING - failed: BOOLEAN - do - create Result.make - from - c := o.new_cursor - until - c.after - loop - if attached {JSON_STRING} json.value (c.key) as l_key then - js := l_key - else - create js.make_json (c.key.out) - end - if attached json.value (c.item) as jv then - Result.put (jv, js) - else - failed := True - end - c.forth - end - if failed then - Result := Void - end - end + to_json (o: like object): detachable JSON_OBJECT + local + c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE] + js: JSON_STRING + failed: BOOLEAN + do + create Result.make + from + c := o.new_cursor + until + c.after + loop + if attached {JSON_STRING} json.value (c.key) as l_key then + js := l_key + else + create js.make_json (c.key.out) + end + if attached json.value (c.item) as jv then + Result.put (jv, js) + else + failed := True + end + c.forth + end + if failed then + Result := Void + end + end 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 42a1c2c4..1edb6bf8 100644 --- a/library/kernel/converters/json_linked_list_converter.e +++ b/library/kernel/converters/json_linked_list_converter.e @@ -5,20 +5,22 @@ note revision: "$Revision$" file: "$HeadURL: $" -class JSON_LINKED_LIST_CONVERTER +class + JSON_LINKED_LIST_CONVERTER inherit - JSON_LIST_CONVERTER + + JSON_LIST_CONVERTER redefine object end create - make + make feature -- Access - object: LINKED_LIST [detachable ANY] + object: LINKED_LIST [detachable ANY] feature {NONE} -- Factory diff --git a/library/kernel/converters/json_list_converter.e b/library/kernel/converters/json_list_converter.e index 75e0f848..7872756b 100644 --- a/library/kernel/converters/json_list_converter.e +++ b/library/kernel/converters/json_list_converter.e @@ -1,25 +1,27 @@ note - description: "A JSON converter for LIST [ANY]" - author: "Paul Cohen" - date: "$Date$" - revision: "$Revision$" - file: "$HeadURL: $" + description: "A JSON converter for LIST [ANY]" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" + file: "$HeadURL: $" -deferred class JSON_LIST_CONVERTER +deferred class + JSON_LIST_CONVERTER inherit - JSON_CONVERTER + + JSON_CONVERTER feature {NONE} -- Initialization - make + make do object := new_object (0) - end + end feature -- Access - object: LIST [detachable ANY] + object: LIST [detachable ANY] feature {NONE} -- Factory @@ -31,44 +33,44 @@ feature {NONE} -- Factory feature -- Conversion - from_json (j: attached like to_json): detachable like object - local - i: INTEGER - do - Result := new_object (j.count) - from - i := 1 - until - i > j.count - loop - Result.extend (json.object (j [i], Void)) - i := i + 1 - end - end + from_json (j: attached like to_json): detachable like object + local + i: INTEGER + do + Result := new_object (j.count) + from + i := 1 + until + i > j.count + loop + Result.extend (json.object (j [i], Void)) + i := i + 1 + end + end - to_json (o: like object): detachable JSON_ARRAY - local - c: ITERATION_CURSOR [detachable ANY] - jv: detachable JSON_VALUE + to_json (o: like object): detachable JSON_ARRAY + local + c: ITERATION_CURSOR [detachable ANY] + jv: detachable JSON_VALUE failed: BOOLEAN - do - create Result.make_array - from - c := o.new_cursor - until - c.after - loop - jv := json.value (c.item) - if jv /= Void then - Result.add (jv) - else + do + create Result.make_array + from + c := o.new_cursor + until + c.after + loop + jv := json.value (c.item) + if jv /= Void then + Result.add (jv) + else failed := True - end + end c.forth - end + end if failed then Result := Void end - end + end end -- class JSON_ARRAYED_LIST_CONVERTER diff --git a/library/kernel/ejson.e b/library/kernel/ejson.e index cb5ed967..86f114ee 100644 --- a/library/kernel/ejson.e +++ b/library/kernel/ejson.e @@ -5,9 +5,11 @@ note revision: "$Revision$" file: "$HeadURL: $" -class EJSON +class + EJSON inherit + EXCEPTIONS feature -- Access @@ -19,9 +21,9 @@ feature -- Access i: INTEGER ja: JSON_ARRAY 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. + -- 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 attached {BOOLEAN} an_object as b then @@ -56,7 +58,9 @@ feature -- Access if attached value (a @ i) as v then ja.add (v) else - check value_attached: False end + check + value_attached: False + end end i := i + 1 end @@ -65,15 +69,13 @@ feature -- Access 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_from_string_32 (s32) end - if Result = Void then - -- Now check the converters + -- Now check the converters if an_object /= Void and then attached converter_for (an_object) as jc then Result := jc.to_json (an_object) else @@ -84,7 +86,7 @@ feature -- Access 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 + -- object based on `base_class' will be returned. Raises an "eJSON -- exception" if unable to convert value. local i: INTEGER diff --git a/library/kernel/json_array.e b/library/kernel/json_array.e index cd693f5c..0f2e50ef 100644 --- a/library/kernel/json_array.e +++ b/library/kernel/json_array.e @@ -1,75 +1,75 @@ note - description: "[ - JSON_ARRAY represent an array in JSON. - An array in JSON is an ordered set of names. - Examples - array - [] - [elements] - ]" - - author: "Javier Velilla" - date: "2008/08/24" - revision: "Revision 0.1" + description: "[ + JSON_ARRAY represent an array in JSON. + An array in JSON is an ordered set of names. + Examples + array + [] + [elements] + ]" + author: "Javier Velilla" + date: "2008/08/24" + revision: "Revision 0.1" class - JSON_ARRAY + JSON_ARRAY inherit - JSON_VALUE + + JSON_VALUE ITERABLE [JSON_VALUE] DEBUG_OUTPUT create - make_array + make_array feature {NONE} -- Initialization - make_array - -- Initialize JSON Array - do - create values.make (10) - end + make_array + -- Initialize JSON Array + do + create values.make (10) + end feature -- Access - i_th alias "[]" (i: INTEGER): JSON_VALUE - -- Item at `i'-th position - require - is_valid_index: valid_index (i) - do - Result := values.i_th (i) - end + i_th alias "[]" (i: INTEGER): JSON_VALUE + -- Item at `i'-th position + require + is_valid_index: valid_index (i) + do + Result := values.i_th (i) + end - representation: STRING - local - i: INTEGER - do - Result := "[" - from - i := 1 - until - i > count - loop - Result.append (i_th (i).representation) - i := i + 1 - if i <= count then - Result.append_character (',') - end - end - Result.append_character (']') - end + representation: STRING + local + i: INTEGER + do + Result := "[" + from + i := 1 + until + i > count + loop + Result.append (i_th (i).representation) + i := i + 1 + if i <= count then + Result.append_character (',') + end + end + Result.append_character (']') + end feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_json_array' procedure on `a_visitor'.) - do - a_visitor.visit_json_array (Current) - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_json_array' procedure on `a_visitor'.) + do + a_visitor.visit_json_array (Current) + end feature -- Access @@ -81,98 +81,96 @@ feature -- Access feature -- Mesurement - count: INTEGER - -- Number of items. - do - Result := values.count - end + count: INTEGER + -- Number of items. + do + Result := values.count + end feature -- Status report - valid_index (i: INTEGER): BOOLEAN - -- Is `i' a valid index? - do - Result := (1 <= i) and (i <= count) - end + valid_index (i: INTEGER): BOOLEAN + -- Is `i' a valid index? + do + Result := (1 <= i) and (i <= count) + end feature -- Change Element put_front (v: JSON_VALUE) - require - v_not_void: v /= Void - do - values.put_front (v) - ensure - has_new_value: old values.count + 1 = values.count and - values.first = v - end + require + v_not_void: v /= Void + do + values.put_front (v) + ensure + has_new_value: old values.count + 1 = values.count and values.first = v + end - add, extend (v: JSON_VALUE) - require - v_not_void: v /= Void - do - values.extend (v) - ensure - has_new_value: old values.count + 1 = values.count and - values.has (v) - end + add, extend (v: JSON_VALUE) + require + v_not_void: v /= Void + do + values.extend (v) + ensure + has_new_value: old values.count + 1 = values.count and values.has (v) + end prune_all (v: JSON_VALUE) -- Remove all occurrences of `v'. - require - v_not_void: v /= Void - do - values.prune_all (v) - ensure - not_has_new_value: not values.has (v) - end + require + v_not_void: v /= Void + do + values.prune_all (v) + ensure + not_has_new_value: not values.has (v) + end wipe_out -- Remove all items. - do - values.wipe_out - end + do + values.wipe_out + end feature -- Report - hash_code: INTEGER - -- Hash code value - do - from - values.start - Result := values.item.hash_code - until - values.off - loop - Result:= ((Result \\ 8388593) |<< 8) + values.item.hash_code - values.forth - end - Result := Result \\ values.count - end + hash_code: INTEGER + -- Hash code value + do + from + values.start + Result := values.item.hash_code + until + values.off + loop + Result := ((Result \\ 8388593) |<< 8) + values.item.hash_code + values.forth + end + Result := Result \\ values.count + end feature -- Conversion - array_representation: ARRAYED_LIST [JSON_VALUE] - -- Representation as a sequences of values - -- be careful, modifying the return object may have impact on the original JSON_ARRAY object - do - Result := values - end + array_representation: ARRAYED_LIST [JSON_VALUE] + -- Representation as a sequences of values + -- be careful, modifying the return object may have impact on the original JSON_ARRAY object + do + Result := values + end feature -- Status report - debug_output: STRING - -- String that should be displayed in debugger to represent `Current'. - do - Result := count.out + " item(s)" - end + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := count.out + " item(s)" + end feature {NONE} -- Implementation - values: ARRAYED_LIST [JSON_VALUE] - -- Value container + values: ARRAYED_LIST [JSON_VALUE] + -- Value container invariant - value_not_void: values /= Void + value_not_void: values /= Void end diff --git a/library/kernel/json_boolean.e b/library/kernel/json_boolean.e index cc17681c..4e1a24a7 100644 --- a/library/kernel/json_boolean.e +++ b/library/kernel/json_boolean.e @@ -1,61 +1,62 @@ note - description: "JSON Truth values" - author: "Javier Velilla" - date: "2008/08/24" - revision: "Revision 0.1" + description: "JSON Truth values" + author: "Javier Velilla" + date: "2008/08/24" + revision: "Revision 0.1" class - JSON_BOOLEAN + JSON_BOOLEAN inherit - JSON_VALUE + + JSON_VALUE create - make_boolean + make_boolean feature {NONE} -- Initialization - make_boolean (an_item: BOOLEAN) - --Initialize. - do - item := an_item - end + make_boolean (an_item: BOOLEAN) + --Initialize. + do + item := an_item + end feature -- Access - item: BOOLEAN - -- Content + item: BOOLEAN + -- Content - hash_code: INTEGER - -- Hash code value - do - Result := item.hash_code - end + hash_code: INTEGER + -- Hash code value + do + Result := item.hash_code + end + + representation: STRING + do + if item then + Result := "true" + else + Result := "false" + end + end - representation: STRING - do - if item then - Result := "true" - else - Result := "false" - end - end - feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_json_boolean' procedure on `a_visitor'.) - do - a_visitor.visit_json_boolean (Current) - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_json_boolean' procedure on `a_visitor'.) + do + a_visitor.visit_json_boolean (Current) + end feature -- Status report - debug_output: STRING - -- String that should be displayed in debugger to represent `Current'. - do - Result := item.out - end + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := item.out + end end diff --git a/library/kernel/json_null.e b/library/kernel/json_null.e index 9c6f4ed7..04130ce5 100644 --- a/library/kernel/json_null.e +++ b/library/kernel/json_null.e @@ -1,47 +1,48 @@ note - description: "JSON Null Values" - author: "Javier Velilla" - date: "2008/08/24" - revision: "Revision 0.1" + description: "JSON Null Values" + author: "Javier Velilla" + date: "2008/08/24" + revision: "Revision 0.1" class - JSON_NULL + JSON_NULL inherit - JSON_VALUE + + JSON_VALUE feature --Access - hash_code: INTEGER - -- Hash code value - do - Result := null_value.hash_code - end + hash_code: INTEGER + -- Hash code value + do + Result := null_value.hash_code + end + + representation: STRING + do + Result := "null" + end - representation: STRING - do - Result := "null" - end - feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_element_a' procedure on `a_visitor'.) - do - a_visitor.visit_json_null (Current) - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_element_a' procedure on `a_visitor'.) + do + a_visitor.visit_json_null (Current) + end feature -- Status report - debug_output: STRING - -- String that should be displayed in debugger to represent `Current'. - do - Result := null_value - end + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := null_value + end -feature {NONE}-- Implementation +feature {NONE} -- Implementation - null_value: STRING = "null" + null_value: STRING = "null" end diff --git a/library/kernel/json_number.e b/library/kernel/json_number.e index 5f8ea60f..213a32e2 100644 --- a/library/kernel/json_number.e +++ b/library/kernel/json_number.e @@ -1,99 +1,99 @@ note - - description: "JSON Numbers, octal and hexadecimal formats are not used." - author: "Javier Velilla" - date: "2008/08/24" - revision: "Revision 0.1" - license:"MIT (see http://www.opensource.org/licenses/mit-license.php)" + description: "JSON Numbers, octal and hexadecimal formats are not used." + author: "Javier Velilla" + date: "2008/08/24" + revision: "Revision 0.1" + license: "MIT (see http://www.opensource.org/licenses/mit-license.php)" class - JSON_NUMBER + JSON_NUMBER inherit - JSON_VALUE - redefine - is_equal - end + + JSON_VALUE + redefine + is_equal + end create - make_integer, - make_natural, - make_real + make_integer, make_natural, make_real feature {NONE} -- initialization - 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_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) - -- 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_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) - -- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'. - do - item := an_argument.out - numeric_type := DOUBLE_TYPE - end + make_real (an_argument: DOUBLE) + -- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'. + do + item := an_argument.out + numeric_type := DOUBLE_TYPE + end feature -- Access - item: STRING - -- Content + item: STRING + -- Content - hash_code: INTEGER - --Hash code value - do - Result := item.hash_code - end + hash_code: INTEGER + --Hash code value + do + Result := item.hash_code + end + + representation: STRING + do + Result := item + end - representation: STRING - do - Result := item - end - feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_json_number' procedure on `a_visitor'.) - do - a_visitor.visit_json_number (Current) - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_json_number' procedure on `a_visitor'.) + do + a_visitor.visit_json_number (Current) + end feature -- Status - is_equal (other: like Current): BOOLEAN - -- Is `other' attached to an object of the same type - -- as current object and identical to it? - do - Result := item.is_equal (other.item) - end + is_equal (other: like Current): BOOLEAN + -- Is `other' attached to an object of the same type + -- as current object and identical to it? + do + Result := item.is_equal (other.item) + end feature -- Status report - debug_output: STRING - -- String that should be displayed in debugger to represent `Current'. - do - Result := item - end + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := item + end feature -- Implementation - INTEGER_TYPE: INTEGER = 1 - DOUBLE_TYPE: INTEGER = 2 - NATURAL_TYPE: INTEGER = 3 + INTEGER_TYPE: INTEGER = 1 - numeric_type: INTEGER + DOUBLE_TYPE: INTEGER = 2 + + NATURAL_TYPE: INTEGER = 3 + + numeric_type: INTEGER invariant - item_not_void: item /= Void + item_not_void: item /= Void end diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index 8a13c64c..8cff2589 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -1,182 +1,180 @@ note - - description: "[ - An JSON_OBJECT represent an object in JSON. - An object is an unordered set of name/value pairs - - Examples: - - object - {} - {"key": "value"} - - ]" - author: "Javier Velilla" - date: "2008/08/24" - revision: "Revision 0.1" - license:"MIT (see http://www.opensource.org/licenses/mit-license.php)" + description: "[ + An JSON_OBJECT represent an object in JSON. + An object is an unordered set of name/value pairs + + Examples: + + object + {} + {"key": "value"} + ]" + author: "Javier Velilla" + date: "2008/08/24" + revision: "Revision 0.1" + license: "MIT (see http://www.opensource.org/licenses/mit-license.php)" class - JSON_OBJECT + JSON_OBJECT inherit - JSON_VALUE - TABLE_ITERABLE [JSON_VALUE, JSON_STRING] + JSON_VALUE - DEBUG_OUTPUT + TABLE_ITERABLE [JSON_VALUE, JSON_STRING] + + DEBUG_OUTPUT create - make + make feature {NONE} -- Initialization - make - -- Initialize - do - create object.make (10) - end + make + -- Initialize + do + create object.make (10) + end feature -- Change Element - 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: like value - do - l_value := value - if l_value = Void then - create {JSON_NULL} l_value - end - object.extend (l_value, key) - end + 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: like value + do + l_value := value + if l_value = Void then + create {JSON_NULL} l_value + end + object.extend (l_value, key) + end - put_string (value: READABLE_STRING_GENERAL; 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_STRING - do - create l_value.make_json_from_string_32 (value.as_string_32) - put (l_value, key) - end + put_string (value: READABLE_STRING_GENERAL; 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_STRING + do + create l_value.make_json_from_string_32 (value.as_string_32) + put (l_value, key) + end + put_integer (value: INTEGER_64; 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_NUMBER + do + create l_value.make_integer (value) + put (l_value, key) + end - put_integer (value: INTEGER_64; 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_NUMBER - do - create l_value.make_integer (value) - put (l_value, key) - end + put_natural (value: NATURAL_64; 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_NUMBER + do + create l_value.make_natural (value) + put (l_value, key) + end - put_natural (value: NATURAL_64; 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_NUMBER - do - create l_value.make_natural (value) - put (l_value, key) - end + put_real (value: DOUBLE; 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_NUMBER + do + create l_value.make_real (value) + put (l_value, key) + end - put_real (value: DOUBLE; 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_NUMBER - do - create l_value.make_real (value) - put (l_value, key) - end + put_boolean (value: BOOLEAN; 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_BOOLEAN + do + create l_value.make_boolean (value) + put (l_value, key) + end - put_boolean (value: BOOLEAN; 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_BOOLEAN - do - create l_value.make_boolean (value) - put (l_value, key) - end + replace (value: detachable JSON_VALUE; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: like value + do + l_value := value + if l_value = Void then + create {JSON_NULL} l_value + end + object.force (l_value, key) + end - replace (value: detachable JSON_VALUE; key: JSON_STRING) - -- Assuming there is no item of key `key', - -- insert `value' with `key'. - local - l_value: like value - do - l_value := value - if l_value = Void then - create {JSON_NULL} l_value - end - object.force (l_value, key) - end + replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: JSON_STRING + do + create l_value.make_json_from_string_32 (value.as_string_32) + replace (l_value, key) + end - replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING) - -- Assuming there is no item of key `key', - -- insert `value' with `key'. - local - l_value: JSON_STRING - do - create l_value.make_json_from_string_32 (value.as_string_32) - replace (l_value, key) - end + replace_with_integer (value: INTEGER_64; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: JSON_NUMBER + do + create l_value.make_integer (value) + replace (l_value, key) + end - replace_with_integer (value: INTEGER_64; key: JSON_STRING) - -- Assuming there is no item of key `key', - -- insert `value' with `key'. - local - l_value: JSON_NUMBER - do - create l_value.make_integer (value) - replace (l_value, key) - end + replace_with_with_natural (value: NATURAL_64; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: JSON_NUMBER + do + create l_value.make_natural (value) + replace (l_value, key) + end - replace_with_with_natural (value: NATURAL_64; key: JSON_STRING) - -- Assuming there is no item of key `key', - -- insert `value' with `key'. - local - l_value: JSON_NUMBER - do - create l_value.make_natural (value) - replace (l_value, key) - end + replace_with_real (value: DOUBLE; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: JSON_NUMBER + do + create l_value.make_real (value) + replace (l_value, key) + end - replace_with_real (value: DOUBLE; key: JSON_STRING) - -- Assuming there is no item of key `key', - -- insert `value' with `key'. - local - l_value: JSON_NUMBER - do - create l_value.make_real (value) - replace (l_value, key) - end - - replace_with_boolean (value: BOOLEAN; key: JSON_STRING) - -- Assuming there is no item of key `key', - -- insert `value' with `key'. - local - l_value: JSON_BOOLEAN - do - create l_value.make_boolean (value) - replace (l_value, key) - end + replace_with_boolean (value: BOOLEAN; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: JSON_BOOLEAN + do + create l_value.make_boolean (value) + replace (l_value, key) + end remove (key: JSON_STRING) -- Remove item indexed by `key' if any. @@ -185,59 +183,59 @@ feature -- Change Element end wipe_out - -- Reset all items to default values; reset status. + -- Reset all items to default values; reset status. do object.wipe_out end feature -- Access - has_key (key: JSON_STRING): BOOLEAN - -- has the JSON_OBJECT contains a specific key 'key'. - do - Result := object.has (key) - end + 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 - -- has the JSON_OBJECT contain a specfic item 'value' - do - Result := object.has_item (value) - end + 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): detachable JSON_VALUE - -- the json_value associated with a key. - do - Result := object.item (key) - end + 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] - -- array containing actually used keys - do - Result := object.current_keys - end + current_keys: ARRAY [JSON_STRING] + -- array containing actually used keys + do + Result := object.current_keys + end - representation: STRING - local - t: HASH_TABLE [JSON_VALUE, JSON_STRING] - do - create Result.make (2) - Result.append_character ('{') - from - t := map_representation - t.start - until - t.after - loop - Result.append (t.key_for_iteration.representation) - Result.append_character (':') - Result.append (t.item_for_iteration.representation) - t.forth - if not t.after then - Result.append_character (',') - end - end - Result.append_character ('}') - end + representation: STRING + local + t: HASH_TABLE [JSON_VALUE, JSON_STRING] + do + create Result.make (2) + Result.append_character ('{') + from + t := map_representation + t.start + until + t.after + loop + Result.append (t.key_for_iteration.representation) + Result.append_character (':') + Result.append (t.item_for_iteration.representation) + t.forth + if not t.after then + Result.append_character (',') + end + end + Result.append_character ('}') + end feature -- Mesurement @@ -265,53 +263,53 @@ feature -- Status report feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_json_object' procedure on `a_visitor'.) - do - a_visitor.visit_json_object (Current) - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_json_object' procedure on `a_visitor'.) + do + a_visitor.visit_json_object (Current) + end feature -- Conversion - map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING] - --A representation that maps keys to values - do - Result := object - end + map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING] + --A representation that maps keys to values + do + Result := object + end feature -- Report - hash_code: INTEGER - -- Hash code value - do - from - object.start - Result := object.out.hash_code - until - object.off - loop - Result := ((Result \\ 8388593) |<< 8) + object.item_for_iteration.hash_code - object.forth - end - -- Ensure it is a positive value. - Result := Result.hash_code - end + hash_code: INTEGER + -- Hash code value + do + from + object.start + Result := object.out.hash_code + until + object.off + loop + Result := ((Result \\ 8388593) |<< 8) + object.item_for_iteration.hash_code + object.forth + end + -- Ensure it is a positive value. + Result := Result.hash_code + end feature -- Status report - debug_output: STRING - -- String that should be displayed in debugger to represent `Current'. - do - Result := count.out + " item(s)" - end + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := count.out + " item(s)" + end feature {NONE} -- Implementation - object: HASH_TABLE [JSON_VALUE, JSON_STRING] - -- Value container + object: HASH_TABLE [JSON_VALUE, JSON_STRING] + -- Value container invariant - object_not_void: object /= Void + object_not_void: object /= Void end diff --git a/library/kernel/json_string.e b/library/kernel/json_string.e index 89ec4648..f8d051c0 100644 --- a/library/kernel/json_string.e +++ b/library/kernel/json_string.e @@ -1,30 +1,26 @@ note - - 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. - ]" - - author: "Javier Velilla" - date: "2008/08/24" - revision: "Revision 0.1" - license:"MIT (see http://www.opensource.org/licenses/mit-license.php)" - + 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. + ]" + author: "Javier Velilla" + date: "2008/08/24" + revision: "Revision 0.1" + license: "MIT (see http://www.opensource.org/licenses/mit-license.php)" class - JSON_STRING + JSON_STRING inherit - JSON_VALUE - redefine - is_equal - end + + JSON_VALUE + redefine + is_equal + end create - make_json, - make_json_from_string_32, - make_with_escaped_json + make_json, make_json_from_string_32, make_with_escaped_json convert make_json ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}), @@ -32,34 +28,34 @@ convert feature {NONE} -- Initialization - make_json (s: READABLE_STRING_8) - -- Initialize. - require - item_not_void: s /= Void - do - make_with_escaped_json (escaped_json_string (s)) - end + make_json (s: READABLE_STRING_8) + -- Initialize. + require + item_not_void: s /= Void + do + make_with_escaped_json (escaped_json_string (s)) + end - make_json_from_string_32 (s: READABLE_STRING_32) - -- Initialize from STRING_32 `s'. - require - item_not_void: s /= Void - do - make_with_escaped_json (escaped_json_string_32 (s)) - end + make_json_from_string_32 (s: READABLE_STRING_32) + -- Initialize from STRING_32 `s'. + require + item_not_void: s /= Void + do + make_with_escaped_json (escaped_json_string_32 (s)) + end - make_with_escaped_json (s: READABLE_STRING_8) - -- Initialize with an_item already escaped - require - item_not_void: s /= Void - do - item := s - end + make_with_escaped_json (s: READABLE_STRING_8) + -- Initialize with an_item already escaped + require + item_not_void: s /= Void + do + item := s + end feature -- Access - item: STRING - -- Contents with escaped entities if any + item: STRING + -- Contents with escaped entities if any feature -- Conversion @@ -86,14 +82,14 @@ feature -- Conversion unescape_to_string_32 (Result) end - representation: STRING + representation: STRING -- String representation of `item' with escaped entities if any - do - create Result.make (item.count + 2) - Result.append_character ('%"') - Result.append (item) - Result.append_character ('%"') - end + do + create Result.make (item.count + 2) + Result.append_character ('%"') + Result.append (item) + Result.append_character ('%"') + end unescape_to_string_8 (a_output: STRING_8) -- Unescape string `item' into `a_output'. @@ -105,11 +101,15 @@ feature -- Conversion do s := item n := s.count - from i := 1 until i > n loop - c := s[i] + from + i := 1 + until + i > n + loop + c := s [i] if c = '\' then if i < n then - inspect s[i+1] + inspect s [i + 1] when '\' then a_output.append_character ('\') i := i + 2 @@ -132,7 +132,7 @@ feature -- Conversion a_output.append_character ('%T') i := i + 2 when 'u' then - --| Leave Unicode \uXXXX unescaped + --| Leave Unicode \uXXXX unescaped a_output.append_character ('\') i := i + 1 else @@ -153,7 +153,7 @@ feature -- Conversion unescape_to_string_32 (a_output: STRING_32) -- Unescape string `item' into `a_output' string 32. --| some encoders uses UTF-8 , and not the recommended pure json encoding - --| thus, let's support the UTF-8 encoding during decoding. + --| thus, let's support the UTF-8 encoding during decoding. local s: READABLE_STRING_8 i, n: INTEGER @@ -163,11 +163,15 @@ feature -- Conversion do s := item n := s.count - from i := 1 until i > n loop + from + i := 1 + until + i > n + loop ch := s.item (i) if ch = '\' then if i < n then - inspect s[i+1] + inspect s [i + 1] when '\' then a_output.append_character ('\') i := i + 2 @@ -207,37 +211,27 @@ feature -- Conversion c := ch.natural_32_code if c <= 0x7F then -- 0xxxxxxx - check ch = c.to_character_32 end + check + ch = c.to_character_32 + end a_output.append_character (ch) elseif c <= 0xDF then -- 110xxxxx 10xxxxxx i := i + 1 if i <= n then - a_output.append_code ( - ((c & 0x1F) |<< 6) | - (s.code (i) & 0x3F) - ) + a_output.append_code (((c & 0x1F) |<< 6) | (s.code (i) & 0x3F)) end elseif c <= 0xEF then -- 1110xxxx 10xxxxxx 10xxxxxx i := i + 2 if i <= n then - a_output.append_code ( - ((c & 0xF) |<< 12) | - ((s.code (i - 1) & 0x3F) |<< 6) | - (s.code (i) & 0x3F) - ) + a_output.append_code (((c & 0xF) |<< 12) | ((s.code (i - 1) & 0x3F) |<< 6) | (s.code (i) & 0x3F)) end elseif c <= 0xF7 then -- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx i := i + 3 if i <= n then - a_output.append_code ( - ((c & 0x7) |<< 18) | - ((s.code (i - 2) & 0x3F) |<< 12) | - ((s.code (i - 1) & 0x3F) |<< 6) | - (s.code (i) & 0x3F) - ) + a_output.append_code (((c & 0x7) |<< 18) | ((s.code (i - 2) & 0x3F) |<< 12) | ((s.code (i - 1) & 0x3F) |<< 6) | (s.code (i) & 0x3F)) end end i := i + 1 @@ -247,52 +241,52 @@ feature -- Conversion feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_json_string' procedure on `a_visitor'.) - do - a_visitor.visit_json_string (Current) - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_json_string' procedure on `a_visitor'.) + do + a_visitor.visit_json_string (Current) + end feature -- Comparison - is_equal (other: like Current): BOOLEAN - -- Is JSON_STRING made of same character sequence as `other' - -- (possibly with a different capacity)? - do - Result := item.same_string (other.item) - end + is_equal (other: like Current): BOOLEAN + -- Is JSON_STRING made of same character sequence as `other' + -- (possibly with a different capacity)? + do + Result := item.same_string (other.item) + end feature -- Change Element - append (a_string: STRING) - -- Add a_string - require - a_string_not_void: a_string /= Void - do - item.append_string (a_string) - end + append (a_string: STRING) + -- Add a_string + require + a_string_not_void: a_string /= Void + do + item.append_string (a_string) + end feature -- Status report - hash_code: INTEGER - -- Hash code value - do - Result := item.hash_code - end + hash_code: INTEGER + -- Hash code value + do + Result := item.hash_code + end feature -- Status report - debug_output: STRING - -- String that should be displayed in debugger to represent `Current'. - do - Result := item - end + debug_output: STRING + -- String that should be displayed in debugger to represent `Current'. + do + Result := item + end feature {NONE} -- Implementation is_hexadecimal (s: READABLE_STRING_8): BOOLEAN - -- Is `s' an hexadecimal value? + -- Is `s' an hexadecimal value? local i: INTEGER do @@ -302,7 +296,7 @@ feature {NONE} -- Implementation until i > s.count or not Result loop - Result := s[i].is_hexa_digit + Result := s [i].is_hexa_digit i := i + 1 end end @@ -317,13 +311,11 @@ feature {NONE} -- Implementation char: CHARACTER do nb := s.count - if nb >= 2 and then s.item (2) = 'x' then i := 3 else i := 1 end - from until i > nb @@ -339,26 +331,37 @@ feature {NONE} -- Implementation end end - escaped_json_string (s: READABLE_STRING_8): STRING_8 - -- JSON string with '"' and '\' characters escaped - require - s_not_void: s /= Void + escaped_json_string (s: READABLE_STRING_8): STRING_8 + -- JSON string with '"' and '\' characters escaped + require + s_not_void: s /= Void local i, n: INTEGER c: CHARACTER_8 do n := s.count create Result.make (n + n // 10) - from i := 1 until i > n loop + from + i := 1 + until + i > n + loop c := s.item (i) inspect c - when '%"' then Result.append_string ("\%"") - when '\' then Result.append_string ("\\") - when '%B' then Result.append_string ("\b") - when '%F' then Result.append_string ("\f") - when '%N' then Result.append_string ("\n") - when '%R' then Result.append_string ("\r") - when '%T' then Result.append_string ("\t") + when '%"' then + Result.append_string ("\%"") + when '\' then + Result.append_string ("\\") + when '%B' then + Result.append_string ("\b") + when '%F' then + Result.append_string ("\f") + when '%N' then + Result.append_string ("\n") + when '%R' then + Result.append_string ("\r") + when '%T' then + Result.append_string ("\t") else Result.extend (c) end @@ -366,10 +369,10 @@ feature {NONE} -- Implementation end end - escaped_json_string_32 (s: READABLE_STRING_32): STRING_8 - -- JSON string with '"' and '\' characters and Unicode escaped - require - s_not_void: s /= Void + escaped_json_string_32 (s: READABLE_STRING_32): STRING_8 + -- JSON string with '"' and '\' characters and Unicode escaped + require + s_not_void: s /= Void local i, j, n: INTEGER uc: CHARACTER_32 @@ -378,25 +381,36 @@ feature {NONE} -- Implementation do n := s.count create Result.make (n + n // 10) - from i := 1 until i > n loop + from + i := 1 + until + i > n + loop uc := s.item (i) if uc.is_character_8 then c := uc.to_character_8 inspect c - when '%"' then Result.append_string ("\%"") - when '\' then Result.append_string ("\\") - when '%B' then Result.append_string ("\b") - when '%F' then Result.append_string ("\f") - when '%N' then Result.append_string ("\n") - when '%R' then Result.append_string ("\r") - when '%T' then Result.append_string ("\t") + when '%"' then + Result.append_string ("\%"") + when '\' then + Result.append_string ("\\") + when '%B' then + Result.append_string ("\b") + when '%F' then + Result.append_string ("\f") + when '%N' then + Result.append_string ("\n") + when '%R' then + Result.append_string ("\r") + when '%T' then + Result.append_string ("\t") else Result.extend (c) end else Result.append ("\u") h := uc.code.to_hex_string - -- Remove first 0 and keep 4 hexa digit + -- Remove first 0 and keep 4 hexa digit from j := 1 until @@ -405,14 +419,15 @@ feature {NONE} -- Implementation j := j + 1 end h := h.substring (j, h.count) - from until h.count >= 4 loop h.prepend_integer (0) end - check h.count = 4 end + check + h.count = 4 + end Result.append (h) end i := i + 1 @@ -420,6 +435,6 @@ feature {NONE} -- Implementation end invariant - item_not_void: item /= Void + item_not_void: item /= Void end diff --git a/library/kernel/json_value.e b/library/kernel/json_value.e index bbf47c7c..f5a5fccf 100644 --- a/library/kernel/json_value.e +++ b/library/kernel/json_value.e @@ -1,43 +1,43 @@ note - description:"[ - JSON_VALUE represent a value in JSON. - A value can be - * a string in double quotes - * a number - * boolean value(true, false ) - * null - * an object - * an array - ]" - author: "Javier Velilla" - date: "2008/05/19" - revision: "Revision 0.1" - license:"MIT (see http://www.opensource.org/licenses/mit-license.php)" - + description: "[ + JSON_VALUE represent a value in JSON. + A value can be + * a string in double quotes + * a number + * boolean value(true, false ) + * null + * an object + * an array + ]" + author: "Javier Velilla" + date: "2008/05/19" + revision: "Revision 0.1" + license: "MIT (see http://www.opensource.org/licenses/mit-license.php)" deferred class - JSON_VALUE + JSON_VALUE inherit - HASHABLE - DEBUG_OUTPUT - + HASHABLE + + DEBUG_OUTPUT + feature -- Access - representation: STRING - -- UTF-8 encoded Unicode string representation of Current - deferred - end + representation: STRING + -- UTF-8 encoded Unicode string representation of Current + deferred + end feature -- Visitor pattern - accept (a_visitor: JSON_VISITOR) - -- Accept `a_visitor'. - -- (Call `visit_*' procedure on `a_visitor'.) - require - a_visitor_not_void: a_visitor /= Void - deferred - end + accept (a_visitor: JSON_VISITOR) + -- Accept `a_visitor'. + -- (Call `visit_*' procedure on `a_visitor'.) + require + a_visitor_not_void: a_visitor /= Void + deferred + end end diff --git a/library/kernel/scanner/json_parser.e b/library/kernel/scanner/json_parser.e index a3bf29f3..1df4ff39 100644 --- a/library/kernel/scanner/json_parser.e +++ b/library/kernel/scanner/json_parser.e @@ -1,5 +1,4 @@ note - description: "Parse serialized JSON data" author: "jvelilla" date: "2008/08/24" @@ -9,7 +8,9 @@ class JSON_PARSER inherit + JSON_READER + JSON_TOKENS create @@ -62,18 +63,18 @@ feature -- Element change feature -- Commands parse_json: detachable JSON_VALUE - -- Parse JSON data `representation' - -- start ::= object | array + -- Parse JSON data `representation' + -- start ::= object | array do - if is_valid_start_symbol then - Result := parse - if extra_elements then - is_parsed := False - end - else - is_parsed := False - report_error ("Syntax error unexpected token, expecting `{' or `['") - end + if is_valid_start_symbol then + Result := parse + if extra_elements then + is_parsed := False + end + else + is_parsed := False + report_error ("Syntax error unexpected token, expecting `{' or `['") + end end parse: detachable JSON_VALUE @@ -92,7 +93,7 @@ feature -- Commands when j_ARRAY_OPEN then Result := parse_array else - if c.is_digit or c = j_MINUS then + if c.is_digit or c = j_MINUS then Result := parse_number elseif is_null then Result := create {JSON_NULL} @@ -131,15 +132,19 @@ feature -- Commands l_value: detachable JSON_VALUE do create Result.make - -- check if is an empty object {} + -- check if is an empty object {} next skip_white_spaces if actual = j_OBJECT_CLOSE then - --is an empty object + --is an empty object else - -- a complex object {"key" : "value"} + -- a complex object {"key" : "value"} previous - from has_more := True until not has_more loop + from + has_more := True + until + not has_more + loop next skip_white_spaces l_json_string := parse_string @@ -153,7 +158,6 @@ feature -- Commands report_error ("%N Input string is a not well formed JSON, expected: : found: " + actual.out) has_more := False end - l_value := parse if is_parsed and then (l_value /= Void and l_json_string /= Void) then Result.put (l_value, l_json_string) @@ -168,7 +172,7 @@ feature -- Commands end else has_more := False - -- explain the error + -- explain the error end end end @@ -241,11 +245,11 @@ feature -- Commands c: like actual do create Result.make_array - --check if is an empty array [] + --check if is an empty array [] next skip_white_spaces if actual = j_array_close then - --is an empty array + --is an empty array else previous from @@ -263,7 +267,7 @@ feature -- Commands c := actual if c = j_ARRAY_CLOSE then flag := False - elseif c /= ',' then + elseif c /= ',' then flag := False is_parsed := False report_error ("Array is not well formed JSON, found [" + c.out + " ]") @@ -286,7 +290,6 @@ feature -- Commands do create sb.make_empty sb.append_character (actual) - from flag := True until @@ -294,16 +297,13 @@ feature -- Commands loop next c := actual - if not has_next or is_close_token (c) - or c = ',' or c = '%N' or c = '%R' - then + if not has_next or is_close_token (c) or c = ',' or c = '%N' or c = '%R' then flag := False previous else sb.append_character (c) end end - if is_valid_number (sb) then if sb.is_integer then create Result.make_integer (sb.to_integer) @@ -313,7 +313,7 @@ feature -- Commands end else is_parsed := False - report_error ("Expected a number, found: [ " + sb + " ]") + report_error ("Expected a number, found: [ " + sb + " ]") end end @@ -324,7 +324,7 @@ feature -- Commands l_string: STRING do l_null := null_id - l_string := json_substring (index,index + l_null.count - 1) + l_string := json_substring (index, index + l_null.count - 1) if l_string.is_equal (l_null) then Result := True end @@ -350,7 +350,7 @@ feature -- Commands l_string: STRING do l_true := true_id - l_string := json_substring (index,index + l_true.count - 1) + l_string := json_substring (index, index + l_true.count - 1) if l_string.is_equal (l_true) then Result := True end @@ -376,12 +376,12 @@ feature -- Commands feature {NONE} -- Implementation 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"? + -- is 'a_number' a valid number based on this regular expression + -- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"? local s: detachable STRING c: CHARACTER - i,n: INTEGER + i, n: INTEGER do create s.make_empty n := a_number.count @@ -390,34 +390,52 @@ feature {NONE} -- Implementation else Result := True i := 1 - --| "-?" - c := a_number[i] + --| "-?" + c := a_number [i] if c = '-' then - s.extend (c); i := i + 1; c := a_number[i] + s.extend (c); + i := i + 1; + c := a_number [i] end - --| "0|[1-9]\d* + --| "0|[1-9]\d* if c.is_digit then if c = '0' then - --| "0" - s.extend (c); i := i + 1; c := a_number[i] + --| "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] + --| "[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+)?" + --| "(\.\d+)?" if c = '.' then - --| "\.\d+" = "\.\d\d*" - s.extend (c); i := i + 1; c := a_number[i] + --| "\.\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] + 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 @@ -426,23 +444,37 @@ feature {NONE} -- Implementation 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] + --| "[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] + 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] + 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 + 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] + from + until + i > n or not c.is_space + loop + s.extend (c); + i := i + 1; + c := a_number [i] end Result := i > n and then s.same_string (a_number) end @@ -454,19 +486,15 @@ feature {NONE} -- Implementation local i: INTEGER do - if - a_unicode.count = 6 and then - a_unicode[1] = '\' and then - a_unicode[2] = 'u' - then + if a_unicode.count = 6 and then a_unicode [1] = '\' and then a_unicode [2] = 'u' then from Result := True i := 3 until i > 6 or Result = False loop - inspect a_unicode[i] - when '0'..'9', 'a'..'f', 'A'..'F' then + inspect a_unicode [i] + when '0'..'9', 'a'..'f', 'A'..'F' then else Result := False end @@ -493,11 +521,11 @@ feature {NONE} -- Implementation Result := has_next end - is_valid_start_symbol : BOOLEAN + is_valid_start_symbol: BOOLEAN -- expecting `{' or `[' as start symbol do if attached representation as s and then s.count > 0 then - Result := s[1] = '{' or s[1] = '[' + Result := s [1] = '{' or s [1] = '[' end end @@ -509,5 +537,4 @@ feature {NONE} -- Constants null_id: STRING = "null" - end diff --git a/library/kernel/scanner/json_reader.e b/library/kernel/scanner/json_reader.e index 977e91ae..7700285b 100644 --- a/library/kernel/scanner/json_reader.e +++ b/library/kernel/scanner/json_reader.e @@ -12,22 +12,22 @@ create feature {NONE} -- Initialization - make (a_json: STRING) - -- Initialize Reader - do - set_representation (a_json) - end + make (a_json: STRING) + -- Initialize Reader + do + set_representation (a_json) + end feature -- Commands - set_representation (a_json: STRING) - -- Set `representation'. - do - a_json.left_adjust - a_json.right_adjust + set_representation (a_json: STRING) + -- Set `representation'. + do + a_json.left_adjust + a_json.right_adjust representation := a_json - index := 1 - end + index := 1 + end read: CHARACTER -- Read character @@ -65,7 +65,7 @@ feature -- Commands from c := actual until - (c /= ' ' and c /= '%N' and c /= '%R' and c /= '%U' and c /= '%T' ) or not has_next + (c /= ' ' and c /= '%N' and c /= '%R' and c /= '%U' and c /= '%T') or not has_next loop next c := actual diff --git a/library/kernel/scanner/json_tokens.e b/library/kernel/scanner/json_tokens.e index 86f86ba3..be35d1e5 100644 --- a/library/kernel/scanner/json_tokens.e +++ b/library/kernel/scanner/json_tokens.e @@ -10,36 +10,40 @@ class feature -- Access j_OBJECT_OPEN: CHARACTER = '{' + j_ARRAY_OPEN: CHARACTER = '[' + j_OBJECT_CLOSE: CHARACTER = '}' + j_ARRAY_CLOSE: CHARACTER = ']' j_STRING: CHARACTER = '"' + j_PLUS: CHARACTER = '+' + j_MINUS: CHARACTER = '-' + j_DOT: CHARACTER = '.' feature -- Status report is_open_token (c: CHARACTER): BOOLEAN - -- Characters which open a type + -- Characters which open a type do inspect c when j_OBJECT_OPEN, j_ARRAY_OPEN, j_STRING, j_PLUS, j_MINUS, j_DOT then Result := True else - end end is_close_token (c: CHARACTER): BOOLEAN - -- Characters which close a type + -- Characters which close a type do inspect c when j_OBJECT_CLOSE, j_ARRAY_CLOSE, j_STRING then Result := True else - end end @@ -51,26 +55,24 @@ feature -- Status report -- %R carriage Return -- %T horizontal Tab -- %B Backspace - -- / Solidus - -- " Quotation + -- / Solidus + -- " Quotation do inspect c when '%F', '%H', '%N', '%R', '%T', '%B', '/', '"' then Result := True else - end end - is_special_control (c: CHARACTER): BOOLEAN - --Control Characters - -- \b\f\n\r\t + is_special_control (c: CHARACTER): BOOLEAN + --Control Characters + -- \b\f\n\r\t do inspect c when 'b', 'f', 'n', 'r', 't' then Result := True else - end end diff --git a/library/kernel/shared_ejson.e b/library/kernel/shared_ejson.e index 421b83a4..eda0ecb2 100644 --- a/library/kernel/shared_ejson.e +++ b/library/kernel/shared_ejson.e @@ -1,38 +1,36 @@ note - description: "[ - Shared factory class for creating JSON objects. Maps JSON - objects to ELKS HASH_TABLEs and JSON arrays to ELKS - LINKED_LISTs. Use non-conforming inheritance from this - class to ensure that your classes share the same - JSON_FACTORY instance. - ]" - author: "Paul Cohen" - date: "$Date$" - revision: "$Revision: 89185 $" - file: "$HeadURL: $" + description: "[ + Shared factory class for creating JSON objects. Maps JSON + objects to ELKS HASH_TABLEs and JSON arrays to ELKS + LINKED_LISTs. Use non-conforming inheritance from this + class to ensure that your classes share the same + JSON_FACTORY instance. + ]" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision: 89185 $" + file: "$HeadURL: $" -class SHARED_EJSON +class + SHARED_EJSON feature - json: EJSON - -- A shared EJSON instance with default converters for - --LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE] - local + json: EJSON + -- A shared EJSON instance with default converters for + --LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE] + local jalc: JSON_ARRAYED_LIST_CONVERTER - jllc: JSON_LINKED_LIST_CONVERTER - jhtc: JSON_HASH_TABLE_CONVERTER - once - create Result + jllc: JSON_LINKED_LIST_CONVERTER + jhtc: JSON_HASH_TABLE_CONVERTER + once + create Result + create jalc.make + Result.add_converter (jalc) + create jllc.make + Result.add_converter (jllc) + create jhtc.make + Result.add_converter (jhtc) + end - create jalc.make - Result.add_converter (jalc) - - create jllc.make - Result.add_converter (jllc) - - create jhtc.make - Result.add_converter (jhtc) - end - end -- class SHARED_EJSON diff --git a/test/autotest/test_suite/application.e b/test/autotest/test_suite/application.e index 77d42fe7..01160cbe 100644 --- a/test/autotest/test_suite/application.e +++ b/test/autotest/test_suite/application.e @@ -1,12 +1,13 @@ note - description : "test_suite application root class" - date : "$Date$" - revision : "$Revision$" + description: "test_suite application root class" + date: "$Date$" + revision: "$Revision$" class APPLICATION inherit + ARGUMENTS create @@ -17,7 +18,7 @@ feature {NONE} -- Initialization make -- Run application. do - --| Add your code here + --| Add your code here print ("Hello Eiffel World!%N") end diff --git a/test/autotest/test_suite/author.e b/test/autotest/test_suite/author.e index 235cae9f..35118404 100644 --- a/test/autotest/test_suite/author.e +++ b/test/autotest/test_suite/author.e @@ -1,33 +1,32 @@ - class AUTHOR create - make + make feature {NONE} -- Initialization - make (a_name: STRING_32) + make (a_name: STRING_32) -- Create an author with `a_name' as `name'. - do - set_name (a_name) - ensure + do + set_name (a_name) + ensure name_set: name = a_name - end + end feature -- Access - name: STRING_32 - -- Author name + name: STRING_32 + -- Author name feature -- Change - set_name (a_name: STRING_32) + set_name (a_name: STRING_32) -- Set `name' with `a_name'. - do - name := a_name - ensure + do + name := a_name + ensure name_set: name = a_name - end + end end -- class AUTHOR diff --git a/test/autotest/test_suite/book.e b/test/autotest/test_suite/book.e index cd2c2764..96670f16 100644 --- a/test/autotest/test_suite/book.e +++ b/test/autotest/test_suite/book.e @@ -1,60 +1,59 @@ - class BOOK create - make + make feature {NONE} -- Initialization - make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32) + make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32) -- Create a book with `a_title' as `title', - -- `a_author' as `author', and `a_isbn' as `isbn', - do - set_title (a_title) - set_author (a_author) - set_isbn (a_isbn) - ensure + -- `a_author' as `author', and `a_isbn' as `isbn'. + do + set_title (a_title) + set_author (a_author) + set_isbn (a_isbn) + ensure title_set: title = a_title author_set: author = a_author isbn_set: isbn = a_isbn - end + end feature -- Access - title: STRING_32 + title: STRING_32 -- Main title. - isbn: STRING_32 + isbn: STRING_32 -- ISBN. - author: AUTHOR + author: AUTHOR -- Author. feature -- Change - set_title (a_title: STRING_32) + set_title (a_title: STRING_32) -- Set `title' with `a_title'. - do - title := a_title - ensure + do + title := a_title + ensure title_set: title = a_title - end + end - set_author (a_author: AUTHOR) + set_author (a_author: AUTHOR) -- Set `author' with `a_author'. - do - author := a_author - ensure + do + author := a_author + ensure author_set: author = a_author - end + end - set_isbn (a_isbn: STRING_32) + set_isbn (a_isbn: STRING_32) -- Set `isbn' with `a_isbn'. - do - isbn := a_isbn - ensure + do + isbn := a_isbn + ensure isbn_set: isbn = a_isbn - end + end end -- class BOOK diff --git a/test/autotest/test_suite/book_collection.e b/test/autotest/test_suite/book_collection.e index 4813d9ea..8959455a 100644 --- a/test/autotest/test_suite/book_collection.e +++ b/test/autotest/test_suite/book_collection.e @@ -2,77 +2,81 @@ class BOOK_COLLECTION create - make + make feature {NONE} -- Initialization - make (a_name: STRING_32) - -- Create a collection of book with `a_name' as `name' - do - set_name (a_name) - create book_index.make (10) - ensure + make (a_name: STRING_32) + -- Create a book collection with `a_name' as `name'. + do + set_name (a_name) + create book_index.make (10) + ensure name_set: name = a_name - end + end feature -- Access - name: STRING_32 + name: STRING_32 -- Name. - books: LIST [BOOK] + books: LIST [BOOK] -- collection of book. - do - create {LINKED_LIST [BOOK]} Result.make - across book_index as it loop + do + create {LINKED_LIST [BOOK]} Result.make + across + book_index as it + loop Result.append (it.item) - end - end + end + end - books_by_author (a_author: STRING_32): LIST [BOOK] + books_by_author (a_author: STRING_32): LIST [BOOK] -- Books wrote by `a_author' in this collection. - do - if attached book_index [a_author] as l_result then - Result := l_result - else - create {LINKED_LIST [BOOK]} Result.make - end - end + do + if attached book_index [a_author] as l_result then + Result := l_result + else + create {LINKED_LIST [BOOK]} Result.make + end + end feature -- Change - set_name (a_name: STRING_32) + set_name (a_name: STRING_32) -- Set `name' with `a_name'. - do - name := a_name - ensure + do + name := a_name + ensure name_set: name = a_name - end + end - add_book (a_book: BOOK) + add_book (a_book: BOOK) -- Extend collection with `a_book'. - local - l: detachable LIST [BOOK] - do - l := book_index.at (a_book.author.name ) - if l = Void then - create {LINKED_LIST [BOOK]} l.make - book_index.put (l, a_book.author.name) - end - l.force (a_book) - end + local + l: detachable LIST [BOOK] + do + l := book_index.at (a_book.author.name) + if l = Void then + create {LINKED_LIST [BOOK]} l.make + book_index.put (l, a_book.author.name) + end + l.force (a_book) + end - add_books (book_list: like books) + add_books (book_list: like books) -- Append collection with `book_list'. - do - across book_list as it loop + do + across + book_list as it + loop add_book (it.item) - end - end + end + end feature {NONE} -- Implementation - book_index: HASH_TABLE [LIST [BOOK], STRING_32] + book_index: HASH_TABLE [LIST [BOOK], STRING_32] -- Association of author name and its books. end -- class BOOK_COLLECTION diff --git a/test/autotest/test_suite/json_author_converter.e b/test/autotest/test_suite/json_author_converter.e index 6375a01a..1eafac8e 100644 --- a/test/autotest/test_suite/json_author_converter.e +++ b/test/autotest/test_suite/json_author_converter.e @@ -1,53 +1,54 @@ note - description: "A JSON converter for AUTHOR" - author: "Paul Cohen" - date: "$Date$" - revision: "$Revision$" + description: "A JSON converter for AUTHOR" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" class JSON_AUTHOR_CONVERTER inherit - JSON_CONVERTER + + JSON_CONVERTER create - make + make feature {NONE} -- Initialization - make - local - ucs: STRING_32 - do - create ucs.make_from_string ("") - create object.make (ucs) - end + make + local + ucs: STRING_32 + do + create ucs.make_from_string ("") + create object.make (ucs) + end feature -- Access - object: AUTHOR + object: AUTHOR feature -- Conversion - from_json (j: like to_json): detachable like object - do - if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then + from_json (j: like to_json): detachable like object + do + if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then create Result.make (l_name) - end - end + end + end - to_json (o: like object): JSON_OBJECT - do - create Result.make - Result.put (json.value (o.name), name_key) - end + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.name), name_key) + end feature {NONE} -- Implementation - name_key: JSON_STRING + name_key: JSON_STRING -- Author's name label. - once - create Result.make_json ("name") - end + once + create Result.make_json ("name") + end end -- class JSON_AUTHOR_CONVERTER diff --git a/test/autotest/test_suite/json_book_collection_converter.e b/test/autotest/test_suite/json_book_collection_converter.e index e78b070e..0ba713f2 100644 --- a/test/autotest/test_suite/json_book_collection_converter.e +++ b/test/autotest/test_suite/json_book_collection_converter.e @@ -1,45 +1,45 @@ note - description: "A JSON converter for BOOK_COLLECTION" - author: "Paul Cohen" - date: "$Date$" - revision: "$Revision$" + description: "A JSON converter for BOOK_COLLECTION" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" class JSON_BOOK_COLLECTION_CONVERTER inherit - JSON_CONVERTER + + JSON_CONVERTER create - make + make feature {NONE} -- Initialization - make - local - ucs: STRING_32 - do - create ucs.make_from_string ("") - create object.make (ucs) - end + make + local + ucs: STRING_32 + do + create ucs.make_from_string ("") + create object.make (ucs) + end feature -- Access - object: BOOK_COLLECTION + object: BOOK_COLLECTION feature -- Conversion - from_json (j: like to_json): detachable like object - local - l_books: LINKED_LIST [BOOK] - do - if + from_json (j: like to_json): detachable like object + local + l_books: LINKED_LIST [BOOK] + do + if attached {STRING_32} json.object (j.item (name_key), Void) as l_name and attached {JSON_ARRAY} j.item (books_key) as l_json_array - then + then create Result.make (l_name) create l_books.make - across l_json_array as it until @@ -52,32 +52,31 @@ feature -- Conversion -- Failed end end - if Result /= Void then Result.add_books (l_books) end - end - end + end + end - to_json (o: like object): JSON_OBJECT - do - create Result.make - Result.put (json.value (o.name), name_key) - Result.put (json.value (o.books), books_key) - end + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.name), name_key) + Result.put (json.value (o.books), books_key) + end -feature {NONE} -- Implementation +feature {NONE} -- Implementation - name_key: JSON_STRING + name_key: JSON_STRING -- Collection's name label. - once - create Result.make_json ("name") - end + once + create Result.make_json ("name") + end - books_key: JSON_STRING + books_key: JSON_STRING -- Book list label. - once - create Result.make_json ("books") - end + once + create Result.make_json ("books") + end end -- class JSON_BOOK_COLLECTION_CONVERTER diff --git a/test/autotest/test_suite/json_book_converter.e b/test/autotest/test_suite/json_book_converter.e index 9da210a5..8711420c 100644 --- a/test/autotest/test_suite/json_book_converter.e +++ b/test/autotest/test_suite/json_book_converter.e @@ -1,73 +1,74 @@ note - description: "A JSON converter for BOOK" - author: "Paul Cohen" - date: "$Date$" - revision: "$Revision$" + description: "A JSON converter for BOOK" + author: "Paul Cohen" + date: "$Date$" + revision: "$Revision$" class JSON_BOOK_CONVERTER inherit - JSON_CONVERTER + + JSON_CONVERTER create - make + make feature {NONE} -- Initialization - make - local - ucs: STRING_32 - a: AUTHOR - do - create ucs.make_from_string ("") - create a.make (ucs) - create object.make (ucs, a, ucs) - end + make + local + ucs: STRING_32 + a: AUTHOR + do + create ucs.make_from_string ("") + create a.make (ucs) + create object.make (ucs, a, ucs) + end feature -- Access - object: BOOK + object: BOOK feature -- Conversion - from_json (j: like to_json): detachable like object - do - if + from_json (j: like to_json): detachable like object + do + if attached {STRING_32} json.object (j.item (title_key), Void) as l_title and attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author - then + then create Result.make (l_title, l_author, l_isbn) - end - end + end + end - to_json (o: like object): JSON_OBJECT - do - create Result.make - Result.put (json.value (o.title), title_key) - Result.put (json.value (o.isbn), isbn_key) - Result.put (json.value (o.author), author_key) - end + to_json (o: like object): JSON_OBJECT + do + create Result.make + 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 + title_key: JSON_STRING -- Book's title label. - once - create Result.make_json ("title") - end + once + create Result.make_json ("title") + end - isbn_key: JSON_STRING + isbn_key: JSON_STRING -- Book ISBN label. - once - create Result.make_json ("isbn") - end + once + create Result.make_json ("isbn") + end - author_key: JSON_STRING + author_key: JSON_STRING -- Author label. - once - create Result.make_json ("author") - end + once + create Result.make_json ("author") + end end -- class JSON_BOOK_CONVERTER diff --git a/test/autotest/test_suite/test_ds.e b/test/autotest/test_suite/test_ds.e index 5b3f28f8..5f737ea8 100644 --- a/test/autotest/test_suite/test_ds.e +++ b/test/autotest/test_suite/test_ds.e @@ -1,14 +1,14 @@ - note - description: "Linked list and hash table converters test." - date: "$Date$" - revision: "$Revision$" + description: "Linked list and hash table converters test." + date: "$Date$" + revision: "$Revision$" class TEST_DS inherit - SHARED_EJSON + + SHARED_EJSON undefine default_create end @@ -17,60 +17,56 @@ inherit feature -- Test - test_linked_list_converter + test_linked_list_converter -- Convert a linked list to a json value and -- convert this one to a linked list. - local - l: LINKED_LIST [STRING] - s: STRING - do - create l.make - l.force ("foo") - l.force ("bar") + local + l: LINKED_LIST [STRING] + s: STRING + do + create l.make + l.force ("foo") + l.force ("bar") + if attached json.value (l) as l_value then + s := l_value.representation + assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST")) + else + assert ("LINKED_LIST converted to a JSON value", False) + end + end - if attached json.value (l) as l_value then - s := l_value.representation - assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST")) - else - assert ("LINKED_LIST converted to a JSON value", False) - end - end - - test_hash_table_converter + test_hash_table_converter -- Convert a hash table to a json value and -- convert this one to a hash table. - local - t: HASH_TABLE [STRING, STRING] - s: STRING - l_ucs_key: detachable STRING_32 - do - create t.make (2) - t.put ("foo", "1") - t.put ("bar", "2") - - if attached json.value (t) as l_value then - s := l_value.representation - if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then - - create l_ucs_key.make_from_string ("1") - if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then - assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo")) - else - assert ("ucs_value /= Void", False) - end - - create l_ucs_key.make_from_string ("2") - if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then - assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar")) - else - assert ("ucs_value /= Void", False) - end - else - assert ("JSON object converted to HASH_TABLE", False); - end - else - assert ("HASH_TABLE converted to a JSON value", False) - end - end + local + t: HASH_TABLE [STRING, STRING] + s: STRING + l_ucs_key: detachable STRING_32 + do + create t.make (2) + t.put ("foo", "1") + t.put ("bar", "2") + if attached json.value (t) as l_value then + s := l_value.representation + if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then + create l_ucs_key.make_from_string ("1") + if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then + assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo")) + else + assert ("ucs_value /= Void", False) + end + create l_ucs_key.make_from_string ("2") + if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then + assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar")) + else + assert ("ucs_value /= Void", False) + end + else + assert ("JSON object converted to HASH_TABLE", False); + end + else + assert ("HASH_TABLE converted to a JSON value", False) + end + end end -- class TEST_DS diff --git a/test/autotest/test_suite/test_json_core.e b/test/autotest/test_suite/test_json_core.e index 61b68b39..7db16c2c 100644 --- a/test/autotest/test_suite/test_json_core.e +++ b/test/autotest/test_suite/test_json_core.e @@ -1,8 +1,9 @@ -class +class TEST_JSON_CORE inherit - SHARED_EJSON + + SHARED_EJSON undefine default_create end @@ -11,32 +12,32 @@ inherit feature -- Test - test_json_number_and_integer - local - i: INTEGER - jn: JSON_NUMBER - jrep: STRING - parser: JSON_PARSER - do - i := 42 - -- Eiffel value -> JSON value -> JSON representation - create jn.make_integer (i) - assert ("jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_NUMBER} json.value (i) as l_jn then + test_json_number_and_integer + local + i: INTEGER + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + i := 42 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_integer (i) + assert ("jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 + 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) - if attached {JSON_NUMBER} parser.parse as l_jn then - if attached {INTEGER_8} json.object (jn, Void) as l_i8 then + -- 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) + 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) @@ -44,34 +45,34 @@ feature -- Test else assert ("parser.parse is a JSON_NUMBER", False) end - end + end - test_json_number_and_integer_8 - 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.representation.same_string (%"42%")", jn.representation.same_string ("42")) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_NUMBER} json.value (i8) as l_jn then - assert ("l_jn.representation.same_string (%"42%")", jn.representation.same_string ("42")) + test_json_number_and_integer_8 + 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.representation.same_string (%"42%")", jn.representation.same_string ("42")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 + 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) - if attached {JSON_NUMBER} parser.parse as l_jn then - if attached {INTEGER_8} json.object (jn, Void) as l_i8 then + -- 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) + 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) @@ -79,34 +80,34 @@ feature -- Test else assert ("parser.parse is a JSON_NUMBER", False) end - end + end - test_json_number_and_integer_16 - 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.representation.same_string (%"300%")", jn.representation.same_string ("300")) - -- Eiffel value -> JSON with factory - if attached {JSON_NUMBER} json.value (i16) as l_jn then - assert ("l_jn.representation.same_string (%"300%")", l_jn.representation.same_string ("300")) + test_json_number_and_integer_16 + 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.representation.same_string (%"300%")", jn.representation.same_string ("300")) + -- Eiffel value -> JSON with factory + 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 + 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) - if attached {JSON_NUMBER} parser.parse as l_jn then - if attached {INTEGER_16} json.object (jn, Void) as l_i16 then + -- 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) + 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) @@ -114,34 +115,34 @@ feature -- Test else assert ("parser.parse is a JSON_NUMBER", False) end - end + end - test_json_number_and_integer_32 - 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.representation.same_string (%"100000%")", jn.representation.same_string ("100000")) - -- Eiffel value -> JSON representation -> JSON value with factory - if attached {JSON_NUMBER} json.value (i32) as l_jn then - assert ("l_jn.representation.same_string (%"100000%")", l_jn.representation.same_string ("100000")) + test_json_number_and_integer_32 + 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.representation.same_string (%"100000%")", jn.representation.same_string ("100000")) + -- Eiffel value -> JSON representation -> JSON value with factory + 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 + 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) - if attached {JSON_NUMBER} parser.parse as l_jn then - if attached {INTEGER_32} json.object (jn, Void) as l_i32 then + -- 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) + 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) @@ -149,34 +150,34 @@ feature -- Test else assert ("parser.parse is a JSON_NUMBER", False) end - end + end - test_json_number_and_integer_64 - 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.representation.same_string (%"42949672960%")", jn.representation.same_string ("42949672960")) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_NUMBER} json.value (i64) as l_jn then - assert ("l_jn.representation.same_string (%"42949672960%")", l_jn.representation.same_string ("42949672960")) + test_json_number_and_integer_64 + 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.representation.same_string (%"42949672960%")", jn.representation.same_string ("42949672960")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 + 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) - if attached {JSON_NUMBER} parser.parse as l_jn then - if attached {INTEGER_64} json.object (jn, Void) as l_i64 then + -- 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) + 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) @@ -184,69 +185,69 @@ feature -- Test else assert ("parser.parse is a JSON_NUMBER", False) end - end + end - test_json_number_and_natural_8 - local - n8: NATURAL_8 - jn: JSON_NUMBER - jrep: STRING - parser: JSON_PARSER - do - n8 := 200 - -- Eiffel value -> JSON value -> JSON representation - create jn.make_natural (n8) - assert ("jn.representation.same_string (%"200%")", jn.representation.same_string ("200")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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 + test_json_number_and_natural_8 + local + n8: NATURAL_8 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + n8 := 200 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n8) + assert ("jn.representation.same_string (%"200%")", jn.representation.same_string ("200")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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) - 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 + -- 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) + 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 + end + end - test_json_number_and_natural_16 - local - n16: NATURAL_16 - jn: JSON_NUMBER - jrep: STRING - parser: JSON_PARSER - do - n16 := 32768 - -- Eiffel value -> JSON value -> JSON representation - create jn.make_natural (n16) - assert ("jn.representation.same_string (%"32768%")", jn.representation.same_string ("32768")) - -- Eiffel value -> JSON value -> JSON representation with factory + test_json_number_and_natural_16 + local + n16: NATURAL_16 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + n16 := 32768 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n16) + assert ("jn.representation.same_string (%"32768%")", jn.representation.same_string ("32768")) + -- Eiffel value -> JSON value -> JSON representation with factory 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 + 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) - if attached {JSON_NUMBER} parser.parse as l_jn then - if attached {INTEGER_32} json.object (jn, Void) as i32 then + -- 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) + 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) @@ -254,310 +255,308 @@ feature -- Test else assert ("parser.parse is a JSON_NUMBER", False) end - end + end - test_json_number_and_natural_32 - local - n32: NATURAL_32 - jn: JSON_NUMBER - jrep: STRING - parser: JSON_PARSER - do - n32 := 2147483648 - -- Eiffel value -> JSON value -> JSON representation - create jn.make_natural (n32) - assert ("jn.representation.same_string (%"2147483648%")", jn.representation.same_string ("2147483648")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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) - 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 - 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.representation.same_string (%"9223372036854775808%")", jn.representation.same_string ("9223372036854775808")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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) - 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 - 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.representation.same_string (%"3.1400001049041748%")", jn.representation.same_string ("3.1400001049041748")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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) - 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 - 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.representation.same_string (%"3.1400001049041748%")", jn.representation.same_string ("3.1400001049041748")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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")) + test_json_number_and_natural_32 + local + n32: NATURAL_32 + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + do + n32 := 2147483648 + -- Eiffel value -> JSON value -> JSON representation + create jn.make_natural (n32) + assert ("jn.representation.same_string (%"2147483648%")", jn.representation.same_string ("2147483648")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 (r32) is a JSON_NUMBER", False) - end + assert ("json.value (n32) is a JSON_NUMBER", False) + end - -- JSON representation -> JSON value -> Eiffel value - jrep := "3.1400001049041748" - create parser.make_parser (jrep) - 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 + -- 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) + 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 + end + end - test_json_number_and_eiffel_real_64 - 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.representation.same_string (%"3.1415926535897931%")", jn.representation.same_string ("3.1415926535897931")) - - -- Eiffel value -> JSON value -> JSON representation with factory - 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) - 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 - parser: JSON_PARSER - jb: JSON_BOOLEAN - b: BOOLEAN - do - -- Eiffel value -> JSON value -> JSON representation - b := True - create jb.make_boolean (b) - assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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 - 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 + test_json_number_and_large_integers + local + jrep: STRING + 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.representation.same_string (%"9223372036854775808%")", jn.representation.same_string ("9223372036854775808")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 ("parser.parse is a JSON_BOOLEAN", False) - end + assert ("json.value (n64) is a JSON_NUMBER", False) + end - -- Eiffel value -> JSON value -> JSON representation - b := False - create jb.make_boolean (b) - assert ("jb.representation.same_string (%"false%")", jb.representation.same_string ("false")) - -- Eiffel value -> JSON value -> JSON representation with factory - 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 + -- 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) + 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 - -- JSON representation -> JSON value -> Eiffel value - 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) + test_json_number_and_eiffel_real + local + r: REAL + 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.representation.same_string (%"3.1400001049041748%")", jn.representation.same_string ("3.1400001049041748")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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) + 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 + 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.representation.same_string (%"3.1400001049041748%")", jn.representation.same_string ("3.1400001049041748")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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) + 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 + 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.representation.same_string (%"3.1415926535897931%")", jn.representation.same_string ("3.1415926535897931")) + + -- Eiffel value -> JSON value -> JSON representation with factory + 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) + 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 + parser: JSON_PARSER + jb: JSON_BOOLEAN + b: BOOLEAN + do + -- Eiffel value -> JSON value -> JSON representation + b := True + create jb.make_boolean (b) + assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 + 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 + + -- Eiffel value -> JSON value -> JSON representation + b := False + create jb.make_boolean (b) + assert ("jb.representation.same_string (%"false%")", jb.representation.same_string ("false")) + -- Eiffel value -> JSON value -> JSON representation with factory + 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 + 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 + else + assert ("parser.parse is a JSON_BOOLEAN", False) + end + end - test_json_null - local - jrep: STRING - jn: JSON_NULL - parser: JSON_PARSER - do - -- Eiffel value -> JSON value -> JSON representation - create jn - jrep := "null" - - assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal (jrep)) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_NULL} json.value (Void) as l_json_null then + test_json_null + local + jrep: STRING + jn: JSON_NULL + parser: JSON_PARSER + do + -- Eiffel value -> JSON value -> JSON representation + create jn + jrep := "null" + assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal (jrep)) + -- Eiffel value -> JSON value -> JSON representation with factory + if attached {JSON_NULL} json.value (Void) as l_json_null then assert ("jn.representation.is_equal (%"null%")", l_json_null.representation.is_equal ("null")) - else - assert ("json.value (Void) /= Void", False) - end + else + assert ("json.value (Void) /= Void", False) + end - -- JSON representation -> JSON value -> Eiffel value - create parser.make_parser (jrep) - if attached parser.parse as l_json_null then - assert ("a = Void", json.object (l_json_null, Void) = Void) - else - assert ("parser.parse /= Void", False) - end - end + -- JSON representation -> JSON value -> Eiffel value + create parser.make_parser (jrep) + if attached parser.parse as l_json_null then + assert ("a = Void", json.object (l_json_null, Void) = Void) + else + assert ("parser.parse /= Void", False) + end + end - test_json_string_and_character - local - c: CHARACTER - jrep: STRING - js: JSON_STRING - parser: JSON_PARSER - do - c := 'a' - -- Eiffel value -> JSON value -> JSON representation - create js.make_json (c.out) - - assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%"")) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_STRING} json.value (c) as l_json_str then + test_json_string_and_character + local + c: CHARACTER + jrep: STRING + js: JSON_STRING + parser: JSON_PARSER + do + c := 'a' + -- Eiffel value -> JSON value -> JSON representation + create js.make_json (c.out) + assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%"")) + -- Eiffel value -> JSON value -> JSON representation with factory + if attached {JSON_STRING} json.value (c) as l_json_str then assert ("js.representation.is_equal (%"%"a%"%")", l_json_str.representation.is_equal ("%"a%"")) - else - assert ("json.value (c) /= Void", False) - end + else + assert ("json.value (c) /= Void", False) + end - -- JSON representation -> JSON value -> Eiffel value - jrep := "%"a%"" - create parser.make_parser (jrep) - if attached {JSON_STRING} parser.parse as l_json_str then + -- JSON representation -> JSON value -> Eiffel value + jrep := "%"a%"" + create parser.make_parser (jrep) + if attached {JSON_STRING} parser.parse as l_json_str then if attached {STRING_32} json.object (l_json_str, Void) as ucs then assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a")) end else assert ("parser.parse /= Void", False) end - end + end - test_json_string_and_string - local - s: STRING - js: detachable JSON_STRING - jrep: STRING - parser: JSON_PARSER - do - s := "foobar" - jrep := "%"foobar%"" + test_json_string_and_string + local + s: STRING + js: detachable JSON_STRING + jrep: STRING + parser: JSON_PARSER + do + s := "foobar" + jrep := "%"foobar%"" - -- Eiffel value -> JSON value -> JSON representation - create js.make_json (s) - assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep)) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_STRING} json.value (s) as l_js then + -- Eiffel value -> JSON value -> JSON representation + create js.make_json (s) + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep)) + -- Eiffel value -> JSON value -> JSON representation with factory + if attached {JSON_STRING} json.value (s) as l_js then assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep)) - else + else assert ("json.value (s) /= Void", False) - end + end - -- JSON representation -> JSON value -> Eiffel value - create parser.make_parser (jrep) + -- JSON representation -> JSON value -> Eiffel value + create parser.make_parser (jrep) if attached {JSON_STRING} parser.parse as l_js then if attached {STRING_32} json.object (l_js, Void) as l_ucs then assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal (s)) @@ -565,34 +564,34 @@ feature -- Test else assert ("parser.parse /= Void", False) end - end + end - test_json_string_and_uc_string - local - js: detachable JSON_STRING - ucs: detachable STRING_32 - jrep, s: STRING - parser: JSON_PARSER - do - s := "foobar" - jrep := "%"foobar%"" - create ucs.make_from_string (s) + test_json_string_and_uc_string + local + js: detachable JSON_STRING + ucs: detachable STRING_32 + jrep, s: STRING + parser: JSON_PARSER + do + s := "foobar" + jrep := "%"foobar%"" + create ucs.make_from_string (s) - -- Eiffel value -> JSON value -> JSON representation - create js.make_json (ucs) - assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep)) + -- Eiffel value -> JSON value -> JSON representation + create js.make_json (ucs) + assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep)) - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_STRING} json.value (ucs) as l_js then + -- Eiffel value -> JSON value -> JSON representation with factory + if attached {JSON_STRING} json.value (ucs) as l_js then assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.is_equal (jrep)) - else + else assert ("json.value (ucs) /= Void", False) - end + end - -- JSON representation -> JSON value -> Eiffel value - create parser.make_parser (jrep) - if attached {JSON_STRING} parser.parse as l_js then - if attached {STRING_32} json.object (l_js, Void) as l_ucs then + -- JSON representation -> JSON value -> Eiffel value + create parser.make_parser (jrep) + if attached {JSON_STRING} parser.parse as l_js then + if attached {STRING_32} json.object (l_js, Void) as l_ucs then assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal (s)) else assert ("json.object (js, Void) /= Void", False) @@ -600,104 +599,99 @@ feature -- Test else assert ("parser.parse /= Void", False) end - end + end - test_json_string_and_special_characters - local - js: detachable JSON_STRING - s: detachable STRING_8 - jrep: STRING - parser: JSON_PARSER - do - jrep := "%"foo\\bar%"" - create s.make_from_string ("foo\bar") - create js.make_json (s) + test_json_string_and_special_characters + local + js: detachable JSON_STRING + s: detachable STRING_8 + jrep: STRING + parser: JSON_PARSER + do + jrep := "%"foo\\bar%"" + create s.make_from_string ("foo\bar") + create js.make_json (s) + assert ("js.representation.same_string (%"%"foo\\bar%"%")", js.representation.same_string (jrep)) - assert ("js.representation.same_string (%"%"foo\\bar%"%")", js.representation.same_string (jrep)) - - -- Eiffel value -> JSON value -> JSON representation with factory - if attached {JSON_STRING} json.value (s) as l_js then - assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.same_string (jrep)) - else + -- Eiffel value -> JSON value -> JSON representation with factory + if attached {JSON_STRING} json.value (s) as l_js then + assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.same_string (jrep)) + else assert ("json.value (s) /= Void", False) - end + end - -- JSON representation -> JSON value -> Eiffel value - create parser.make_parser (jrep) - if attached {JSON_STRING} parser.parse as l_js then - if attached {STRING_32} json.object (l_js, Void) as l_ucs then + -- JSON representation -> JSON value -> Eiffel value + create parser.make_parser (jrep) + if attached {JSON_STRING} parser.parse as l_js then + if attached {STRING_32} json.object (l_js, Void) as l_ucs then assert ("ucs.same_string (%"foo\bar%")", l_ucs.same_string ("foo\bar")) - end - else + end + else assert ("parser.parse /= Void", False) - end - - - jrep := "%"foo\\bar%"" + end + jrep := "%"foo\\bar%"" create parser.make_parser (jrep) if attached {JSON_STRING} parser.parse as jstring then assert ("unescaped string %"foo\\bar%" to %"foo\bar%"", jstring.unescaped_string_8.same_string ("foo\bar")) else assert ("parser.parse /= Void", False) end - - create js.make_json_from_string_32 ({STRING_32}"%/20320/%/22909/") - assert ("escaping unicode string32 %"%%/20320/%%/22909/%" %"\u4F60\u597D%"", js.item.same_string ("\u4F60\u597D")) - - jrep := "%"\u4F60\u597D%"" --| Ni hao + create js.make_json_from_string_32 ({STRING_32} "你好") + assert ("escaping unicode string32 %"%%/20320/%%/22909/%" %"\u4F60\u597D%"", js.item.same_string ("\u4F60\u597D")) + jrep := "%"\u4F60\u597D%"" --| Ni hao create parser.make_parser (jrep) if attached {JSON_STRING} parser.parse as jstring then - assert ("same unicode string32 %"%%/20320/%%/22909/%"", jstring.unescaped_string_32.same_string ({STRING_32}"%/20320/%/22909/")) + assert ("same unicode string32 %"%%/20320/%%/22909/%"", jstring.unescaped_string_32.same_string ({STRING_32} "你好")) else assert ("parser.parse /= Void", False) end - end + end - test_json_array - local - ll: LINKED_LIST [INTEGER_8] - ja: detachable JSON_ARRAY - jn: JSON_NUMBER - jrep: STRING - parser: JSON_PARSER - 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 - if attached {JSON_ARRAY} json.value (ll) 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]")) - else + test_json_array + local + ll: LINKED_LIST [INTEGER_8] + ja: detachable JSON_ARRAY + jn: JSON_NUMBER + jrep: STRING + parser: JSON_PARSER + 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 + if attached {JSON_ARRAY} json.value (ll) 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]")) + else assert ("json.value (ll) /= Void", False) - end + 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 - -- 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) - if attached {JSON_ARRAY} parser.parse as l_ja then + -- 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) + if attached {JSON_ARRAY} parser.parse as l_ja then if attached {LINKED_LIST [detachable ANY]} json.object (ja, Void) as l_ll2 then assert ("ll2.is_equal (ll)", l_ll2.is_equal (ll)) else @@ -705,71 +699,71 @@ feature -- Test end else assert ("parser.parse /= Void", False) - end - end + end + end - test_json_object - local - t: detachable HASH_TABLE [detachable ANY, STRING_GENERAL] - i: INTEGER - ucs_key, ucs: STRING_32 - a: ARRAY [INTEGER] - jo: detachable 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 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 (%"{%"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]}")) + test_json_object + local + t: detachable HASH_TABLE [detachable ANY, STRING_GENERAL] + i: INTEGER + ucs_key, ucs: STRING_32 + a: ARRAY [INTEGER] + jo: detachable 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 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 (%"{%"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") - 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) - if attached {JSON_OBJECT} json.value (t) as l_jo then + -- 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) + if attached {JSON_OBJECT} json.value (t) 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]}")) - else + else assert ("json.value (t) /= Void", False) - end + 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) + -- 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) if attached {JSON_OBJECT} parser.parse as l_jo then if attached {HASH_TABLE [detachable ANY, STRING_GENERAL]} json.object (l_jo, Void) as l_t2 then if attached json.value (l_t2) as l_jo_2 then @@ -783,55 +777,55 @@ feature -- Test else assert ("parser.parse /= Void", jo /= Void) end - end + end - test_json_object_hash_code - local - ht: HASH_TABLE [ANY, JSON_VALUE] - jo: JSON_OBJECT - do - create ht.make (1) - create jo.make - ht.force ("", jo) - assert ("ht.has_key (jo)", ht.has_key (jo)) - end + test_json_object_hash_code + local + ht: HASH_TABLE [ANY, JSON_VALUE] + jo: JSON_OBJECT + do + create ht.make (1) + create jo.make + ht.force ("", jo) + assert ("ht.has_key (jo)", ht.has_key (jo)) + end - 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 - gv: OPERATING_ENVIRONMENT - jv: detachable JSON_VALUE - exception: BOOLEAN - do - if not exception then - create gv - jv := json.value (gv) - else - assert ("exceptions.is_developer_exception", json.is_developer_exception) - end - rescue - exception := True - retry - end + 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 + gv: OPERATING_ENVIRONMENT + jv: detachable JSON_VALUE + exception: BOOLEAN + do + if not exception then + create gv + jv := json.value (gv) + else + assert ("exceptions.is_developer_exception", json.is_developer_exception) + end + rescue + exception := True + retry + end - 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 - gv : detachable ANY - jo: JSON_OBJECT - exception: BOOLEAN - do - if not exception then - create jo.make - gv := json.object (jo, "OPERATING_ENVIRONMENT") - else - assert ("exceptions.is_developer_exception", json.is_developer_exception) - end - rescue - exception := True - retry - end + 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 + gv: detachable ANY + jo: JSON_OBJECT + exception: BOOLEAN + do + if not exception then + create jo.make + gv := json.object (jo, "OPERATING_ENVIRONMENT") + else + assert ("exceptions.is_developer_exception", json.is_developer_exception) + end + rescue + exception := True + retry + end end -- class TEST_JSON_CORE diff --git a/test/autotest/test_suite/test_json_custom_classes.e b/test/autotest/test_suite/test_json_custom_classes.e index 0b0b0715..7db1df10 100644 --- a/test/autotest/test_suite/test_json_custom_classes.e +++ b/test/autotest/test_suite/test_json_custom_classes.e @@ -1,14 +1,14 @@ - note - description: "Parsing and converter of book collection test." - date: "$Date$" - revision: "$Revision$" + description: "Parsing and converter of book collection test." + date: "$Date$" + revision: "$Revision$" class TEST_JSON_CUSTOM_CLASSES inherit - SHARED_EJSON + + SHARED_EJSON undefine default_create end @@ -17,25 +17,24 @@ inherit feature -- Test - test_custom_classes + test_custom_classes -- Parse JSON representation to JSON_OBJECT and test book collection converter. - local - jbc: JSON_BOOK_CONVERTER - jbcc: JSON_BOOK_COLLECTION_CONVERTER - jac: JSON_AUTHOR_CONVERTER - parser: JSON_PARSER - jrep: STRING - do - create jbc.make - json.add_converter (jbc) - create jbcc.make - json.add_converter (jbcc) - create jac.make - json.add_converter (jac) - jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}" - create parser.make_parser (jrep) - - if attached {JSON_OBJECT} parser.parse as l_json_object then + local + jbc: JSON_BOOK_CONVERTER + jbcc: JSON_BOOK_COLLECTION_CONVERTER + jac: JSON_AUTHOR_CONVERTER + parser: JSON_PARSER + jrep: STRING + do + create jbc.make + json.add_converter (jbc) + create jbcc.make + json.add_converter (jbcc) + create jac.make + json.add_converter (jac) + jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}" + create parser.make_parser (jrep) + if attached {JSON_OBJECT} parser.parse as l_json_object then if attached {BOOK_COLLECTION} json.object (l_json_object, "BOOK_COLLECTION") as l_collection then if attached {JSON_OBJECT} json.value (l_collection) as l_json_object_2 then assert ("JSON representation is correct", l_json_object_2.representation.same_string (jrep)) @@ -47,7 +46,7 @@ feature -- Test end else assert ("JSON object representation to JSON_OBJECT", False) - end - end + end + end end -- class TEST_JSON_CUSTOM_CLASS diff --git a/test/autotest/test_suite/test_json_suite.e b/test/autotest/test_suite/test_json_suite.e index c2a66b71..096a8db2 100644 --- a/test/autotest/test_suite/test_json_suite.e +++ b/test/autotest/test_suite/test_json_suite.e @@ -11,6 +11,7 @@ class TEST_JSON_SUITE inherit + EQA_TEST_SET redefine on_prepare @@ -27,38 +28,38 @@ feature {NONE} -- Events feature -- Tests Pass test_json_pass1 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("pass1.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("pass1.json",parse_json.is_parsed = True) + assert ("pass1.json", parse_json.is_parsed = True) end end test_json_pass2 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("pass2.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("pass2.json",parse_json.is_parsed = True) + assert ("pass2.json", parse_json.is_parsed = True) end end - test_json_pass3 - -- + test_json_pass3 + -- local parse_json: like new_json_parser do if attached json_file_from ("pass3.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("pass3.json",parse_json.is_parsed = True) + assert ("pass3.json", parse_json.is_parsed = True) end end @@ -69,14 +70,10 @@ feature -- Tests Pass s: READABLE_STRING_32 do s := {STRING_32} "{ %"nihaoma%": %"你好吗\t?%" }" - parse_json := new_json_parser (utf.string_32_to_utf_8_string_8 (s)) json_value := parse_json.parse_json assert ("utf8.pass1.json", parse_json.is_parsed = True) - if - attached {JSON_OBJECT} json_value as jo and then - attached {JSON_STRING} jo.item ("nihaoma") as js - then + if attached {JSON_OBJECT} json_value as jo and then attached {JSON_STRING} jo.item ("nihaoma") as js then assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "你好吗%T?")) else assert ("utf8.nihaoma", False) @@ -84,408 +81,400 @@ feature -- Tests Pass end feature -- Tests Failures - test_json_fail1 - -- + + test_json_fail1 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail1.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail1.json",parse_json.is_parsed = False) + assert ("fail1.json", parse_json.is_parsed = False) end end - test_json_fail2 - -- + test_json_fail2 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail2.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail2.json",parse_json.is_parsed = False) + assert ("fail2.json", parse_json.is_parsed = False) end end test_json_fail3 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail3.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail3.json",parse_json.is_parsed = False) + assert ("fail3.json", parse_json.is_parsed = False) end end test_json_fail4 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail4.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail4.json",parse_json.is_parsed = False) + assert ("fail4.json", parse_json.is_parsed = False) end end - test_json_fail5 - -- + test_json_fail5 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail5.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail5.json",parse_json.is_parsed = False) + assert ("fail5.json", parse_json.is_parsed = False) end end - test_json_fail6 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail6.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail6.json",parse_json.is_parsed = False ) + assert ("fail6.json", parse_json.is_parsed = False) end end - test_json_fail7 - -- + test_json_fail7 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail7.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail7.json",parse_json.is_parsed = False) + assert ("fail7.json", parse_json.is_parsed = False) end end - test_json_fail8 - -- + test_json_fail8 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail8.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail8.json",parse_json.is_parsed = False ) + assert ("fail8.json", parse_json.is_parsed = False) end end - test_json_fail9 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail9.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail9.json",parse_json.is_parsed = False) + assert ("fail9.json", parse_json.is_parsed = False) end end - test_json_fail10 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail10.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail10.json",parse_json.is_parsed = False) + assert ("fail10.json", parse_json.is_parsed = False) end end - test_json_fail11 - -- + test_json_fail11 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail11.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail11.json",parse_json.is_parsed = False) + assert ("fail11.json", parse_json.is_parsed = False) end end test_json_fail12 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail12.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail12.json",parse_json.is_parsed = False) + assert ("fail12.json", parse_json.is_parsed = False) end end - test_json_fail13 - -- + test_json_fail13 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail13.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail13.json",parse_json.is_parsed = False) + assert ("fail13.json", parse_json.is_parsed = False) end end - test_json_fail14 - -- + test_json_fail14 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail14.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail14.json",parse_json.is_parsed = False) + assert ("fail14.json", parse_json.is_parsed = False) end end test_json_fail15 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail15.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail15.json",parse_json.is_parsed = False) + assert ("fail15.json", parse_json.is_parsed = False) end end test_json_fail16 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail16.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail16.json",parse_json.is_parsed = False) + assert ("fail16.json", parse_json.is_parsed = False) end end test_json_fail17 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail17.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail17.json",parse_json.is_parsed = False) + assert ("fail17.json", parse_json.is_parsed = False) end end test_json_fail18 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail18.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail18.json",parse_json.is_parsed = True) + assert ("fail18.json", parse_json.is_parsed = True) end end test_json_fail19 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail19.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail19.json",parse_json.is_parsed = False) + assert ("fail19.json", parse_json.is_parsed = False) end end test_json_fail20 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail20.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail20.json",parse_json.is_parsed = False) + assert ("fail20.json", parse_json.is_parsed = False) end end - test_json_fail21 - -- + test_json_fail21 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail21.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail21.json",parse_json.is_parsed = False) + assert ("fail21.json", parse_json.is_parsed = False) end end - - test_json_fail22 - -- + test_json_fail22 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail22.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail22.json",parse_json.is_parsed = False) + assert ("fail22.json", parse_json.is_parsed = False) end end - test_json_fail23 - -- + test_json_fail23 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail23.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail23.json",parse_json.is_parsed = False) + assert ("fail23.json", parse_json.is_parsed = False) end end - test_json_fail24 - -- + test_json_fail24 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail24.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail24.json",parse_json.is_parsed = False) + assert ("fail24.json", parse_json.is_parsed = False) end end test_json_fail25 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail25.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail25.json",parse_json.is_parsed = False) + assert ("fail25.json", parse_json.is_parsed = False) end end - - test_json_fail26 - -- + test_json_fail26 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail26.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail26.json",parse_json.is_parsed = False) + assert ("fail26.json", parse_json.is_parsed = False) end end - - test_json_fail27 - -- + test_json_fail27 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail27.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail27.json",parse_json.is_parsed = False) + assert ("fail27.json", parse_json.is_parsed = False) end end - - test_json_fail28 - -- + test_json_fail28 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail28.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail28.json",parse_json.is_parsed = False) + assert ("fail28.json", parse_json.is_parsed = False) end end - - test_json_fail29 - -- + test_json_fail29 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail29.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail29.json",parse_json.is_parsed = False ) + assert ("fail29.json", parse_json.is_parsed = False) end end - - test_json_fail30 - -- + test_json_fail30 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail30.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail30.json",parse_json.is_parsed = False) + assert ("fail30.json", parse_json.is_parsed = False) end end test_json_fail31 - -- + -- local parse_json: like new_json_parser do if attached json_file_from ("fail31.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail31.json",parse_json.is_parsed = False) + assert ("fail31.json", parse_json.is_parsed = False) end end - test_json_fail32 - -- + test_json_fail32 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail32.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail32.json",parse_json.is_parsed = False) + assert ("fail32.json", parse_json.is_parsed = False) end end - test_json_fail33 - -- + test_json_fail33 + -- local parse_json: like new_json_parser do if attached json_file_from ("fail33.json") as json_file then parse_json := new_json_parser (json_file) json_value := parse_json.parse_json - assert ("fail33.json",parse_json.is_parsed = False) + assert ("fail33.json", parse_json.is_parsed = False) end end @@ -495,23 +484,22 @@ feature -- JSON_FROM_FILE json_value: detachable JSON_VALUE - json_file_from (fn: STRING): detachable STRING - local - f: RAW_FILE - l_path: STRING + json_file_from (fn: STRING): detachable STRING + local + f: RAW_FILE + l_path: STRING test_dir: STRING i: INTEGER do test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_directory test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator) - l_path := test_dir + fn create f.make_with_name (l_path) if f.exists then -- Found json file else - -- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like - -- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json + -- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like + -- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json from i := 5 until @@ -536,9 +524,7 @@ feature -- JSON_FROM_FILE create Result.make_parser (a_string) end - invariant file_reader /= Void end -