From cb7c20a0b74735752e21402031f979016c52235a Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 3 Feb 2014 09:52:09 +0100 Subject: [PATCH] Udated to highest level of void-safety. Fixed obsolete calls. --- library/json-safe.ecf | 2 +- .../converters/json_hash_table_converter.e | 44 +++++---------- test/autotest/test_suite/test_json_suite.e | 53 +++++++++++-------- 3 files changed, 46 insertions(+), 53 deletions(-) diff --git a/library/json-safe.ecf b/library/json-safe.ecf index b957513f..0eb6cc52 100644 --- a/library/json-safe.ecf +++ b/library/json-safe.ecf @@ -1,5 +1,5 @@ - + diff --git a/library/kernel/converters/json_hash_table_converter.e b/library/kernel/converters/json_hash_table_converter.e index cf3f9cfc..e1264de7 100644 --- a/library/kernel/converters/json_hash_table_converter.e +++ b/library/kernel/converters/json_hash_table_converter.e @@ -1,8 +1,8 @@ note description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]" author: "Paul Cohen" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $" + revision: "$Revision: 94128 $" file: "$HeadURL: $" class JSON_HASH_TABLE_CONVERTER @@ -27,34 +27,20 @@ feature -- Access feature -- Conversion from_json (j: attached like to_json): like object - local - keys: ARRAY [JSON_STRING] - i: INTEGER - h: detachable HASHABLE - jv: detachable JSON_VALUE - a: detachable ANY do - keys := j.current_keys - create Result.make (keys.count) - from - i := 1 - until - i > keys.count + create Result.make (j.count) + across + j as ic loop - h ?= json.object (keys [i], Void) - check h /= Void end - jv := j.item (keys [i]) - if jv /= Void then - a := json.object (jv, Void) - if a /= Void then - Result.put (a, h) - else - check a_attached: a /= Void end - end - else - check j_has_item: False end + 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 + end + else + check object_attached: False end end - i := i + 1 end end @@ -62,7 +48,6 @@ feature -- Conversion local c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE] js: JSON_STRING - jv: detachable JSON_VALUE failed: BOOLEAN do create Result.make @@ -76,8 +61,7 @@ feature -- Conversion else create js.make_json (c.key.out) end - jv := json.value (c.item) - if jv /= Void then + if attached json.value (c.item) as jv then Result.put (jv, js) else failed := True diff --git a/test/autotest/test_suite/test_json_suite.e b/test/autotest/test_suite/test_json_suite.e index 30849c92..eb5df766 100644 --- a/test/autotest/test_suite/test_json_suite.e +++ b/test/autotest/test_suite/test_json_suite.e @@ -475,8 +475,38 @@ feature -- JSON_FROM_FILE json_value: detachable JSON_VALUE json_file_from (fn: STRING): detachable STRING + local + f: RAW_FILE + l_path: STRING + test_dir: STRING + i: INTEGER do - Result := file_reader.read_json_from (test_dir + fn) + 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 + from + i := 5 + until + i = 0 + loop + test_dir.append_character ('.') + test_dir.append_character ('.') + test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator) + i := i - 1 + end + l_path := test_dir + fn + end + create f.make_with_name (l_path) + if f.exists then + Result := file_reader.read_json_from (l_path) + end assert ("File contains json data", Result /= Void) end @@ -485,30 +515,9 @@ feature -- JSON_FROM_FILE create Result.make_parser (a_string) end - test_dir: STRING - local - i: INTEGER - do - Result := (create {EXECUTION_ENVIRONMENT}).current_working_directory - Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator) - -- The should looks like - -- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json - from - i := 5 - until - i = 0 - loop - Result.append_character ('.') - Result.append_character ('.') - Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator) - i := i - 1 - end --- Result := "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/" - end invariant file_reader /= Void end -