This commit is contained in:
2014-02-27 09:16:48 +01:00
4 changed files with 47 additions and 54 deletions

View File

@@ -14,7 +14,7 @@ feature -- Access
template_content: STRING template_content: STRING
l_last_string: detachable STRING l_last_string: detachable STRING
do do
create l_file.make (a_path) create l_file.make_with_name (a_path)
-- We perform several checks until we make a real attempt to open the file. -- We perform several checks until we make a real attempt to open the file.
if not l_file.exists then if not l_file.exists then
print ("error: '" + a_path + "' does not exist%N") print ("error: '" + a_path + "' does not exist%N")

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json"> <system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
<target name="json"> <target name="json">
<root all_classes="true"/> <root all_classes="true"/>
<file_rule> <file_rule>

View File

@@ -1,8 +1,8 @@
note note
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]" description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
author: "Paul Cohen" author: "Paul Cohen"
date: "$Date$" date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $"
revision: "$Revision$" revision: "$Revision: 94128 $"
file: "$HeadURL: $" file: "$HeadURL: $"
class JSON_HASH_TABLE_CONVERTER class JSON_HASH_TABLE_CONVERTER
@@ -27,34 +27,20 @@ feature -- Access
feature -- Conversion feature -- Conversion
from_json (j: attached like to_json): like object 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 do
keys := j.current_keys create Result.make (j.count)
create Result.make (keys.count) across
from j as ic
i := 1
until
i > keys.count
loop loop
h ?= json.object (keys [i], Void) if attached json.object (ic.item, Void) as l_object then
check h /= Void end if attached {HASHABLE} json.object (ic.key, Void) as h then
jv := j.item (keys [i]) Result.put (l_object, h)
if jv /= Void then else
a := json.object (jv, Void) check key_is_hashable: False end
if a /= Void then end
Result.put (a, h) else
else check object_attached: False end
check a_attached: a /= Void end
end
else
check j_has_item: False end
end end
i := i + 1
end end
end end
@@ -62,7 +48,6 @@ feature -- Conversion
local local
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE] c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
js: JSON_STRING js: JSON_STRING
jv: detachable JSON_VALUE
failed: BOOLEAN failed: BOOLEAN
do do
create Result.make create Result.make
@@ -76,8 +61,7 @@ feature -- Conversion
else else
create js.make_json (c.key.out) create js.make_json (c.key.out)
end end
jv := json.value (c.item) if attached json.value (c.item) as jv then
if jv /= Void then
Result.put (jv, js) Result.put (jv, js)
else else
failed := True failed := True

View File

@@ -475,8 +475,38 @@ feature -- JSON_FROM_FILE
json_value: detachable JSON_VALUE json_value: detachable JSON_VALUE
json_file_from (fn: STRING): detachable STRING json_file_from (fn: STRING): detachable STRING
local
f: RAW_FILE
l_path: STRING
test_dir: STRING
i: INTEGER
do 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) assert ("File contains json data", Result /= Void)
end end
@@ -485,30 +515,9 @@ feature -- JSON_FROM_FILE
create Result.make_parser (a_string) create Result.make_parser (a_string)
end 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 invariant
file_reader /= Void file_reader /= Void
end end