Update test

This commit is contained in:
jvelilla
2008-05-25 18:28:40 +00:00
parent 8357bf5d72
commit 3083f378a6
3 changed files with 142 additions and 22 deletions

View File

@@ -19,8 +19,24 @@ feature
do
i := 1
if a_name /= Void then
if a_name.substring (1, a_name.count).is_equal ("TEST_JSON_OBJECTS") then
Result := create {TEST_JSON_OBJECTS}
if a_name.count >= 10 and then a_name.substring (1, 10).is_equal ("TEST_JSON_") then
i := i + 10
if a_name.count >= i then
c := a_name.item (i)
i := i + 1
inspect c
when 'S' then
if a_name.substring (12, a_name.count).is_equal ("TRING") then
Result := create {TEST_JSON_STRING}
end
when 'O' then
if a_name.substring (12, a_name.count).is_equal ("BJECTS") then
Result := create {TEST_JSON_OBJECTS}
end
else
-- Do nothing.
end
end
end
end
end
@@ -32,36 +48,89 @@ feature
do
i := 1
if a_name /= Void then
if a_name.count >= 23 and then a_name.substring (1, 23).is_equal ("TEST_JSON_OBJECTS.test_") then
i := i + 23
if a_name.count >= 10 and then a_name.substring (1, 10).is_equal ("TEST_JSON_") then
i := i + 10
if a_name.count >= i then
c := a_name.item (i)
i := i + 1
inspect c
when 'h' then
if a_name.count >= 27 and then a_name.substring (25, 27).is_equal ("as_") then
i := i + 3
when 'S' then
if a_name.substring (12, a_name.count).is_equal ("TRING.test_1") then
Result := agent {TEST_JSON_STRING}.test_1
end
when 'O' then
if a_name.count >= 23 and then a_name.substring (12, 23).is_equal ("BJECTS.test_") then
i := i + 12
if a_name.count >= i then
c := a_name.item (i)
i := i + 1
inspect c
when 'n' then
if a_name.substring (29, a_name.count).is_equal ("ot_key") then
Result := agent {TEST_JSON_OBJECTS}.test_has_not_key
when 'j' then
if a_name.count >= 28 and then a_name.substring (25, 28).is_equal ("son_") then
i := i + 4
if a_name.count >= i then
c := a_name.item (i)
i := i + 1
inspect c
when 'v' then
if a_name.substring (30, a_name.count).is_equal ("alue") then
Result := agent {TEST_JSON_OBJECTS}.test_json_value
end
when 'o' then
if a_name.substring (30, a_name.count).is_equal ("bjects_items") then
Result := agent {TEST_JSON_OBJECTS}.test_json_objects_items
end
else
-- Do nothing.
end
end
end
when 'k' then
if a_name.substring (29, a_name.count).is_equal ("ey") then
Result := agent {TEST_JSON_OBJECTS}.test_has_key
when 'c' then
if a_name.count >= i then
c := a_name.item (i)
i := i + 1
inspect c
when 'u' then
if a_name.substring (26, a_name.count).is_equal ("rrent_keys") then
Result := agent {TEST_JSON_OBJECTS}.test_current_keys
end
when 'o' then
if a_name.substring (26, a_name.count).is_equal ("nversion_to_json_object") then
Result := agent {TEST_JSON_OBJECTS}.test_conversion_to_json_object
end
else
-- Do nothing.
end
end
when 'h' then
if a_name.count >= 27 and then a_name.substring (25, 27).is_equal ("as_") then
i := i + 3
if a_name.count >= i then
c := a_name.item (i)
i := i + 1
inspect c
when 'k' then
if a_name.substring (29, a_name.count).is_equal ("ey") then
Result := agent {TEST_JSON_OBJECTS}.test_has_key
end
when 'n' then
if a_name.substring (29, a_name.count).is_equal ("ot_key") then
Result := agent {TEST_JSON_OBJECTS}.test_has_not_key
end
when 'i' then
if a_name.substring (29, a_name.count).is_equal ("tem") then
Result := agent {TEST_JSON_OBJECTS}.test_has_item
end
else
-- Do nothing.
end
end
end
else
-- Do nothing.
end
end
end
when 'c' then
if a_name.substring (25, a_name.count).is_equal ("urrent_keys") then
Result := agent {TEST_JSON_OBJECTS}.test_current_keys
end
else
-- Do nothing.
end

View File

@@ -19,7 +19,11 @@ feature {NONE} -- Initialization
create l_test_case
l_abstract_test_case := l_test_case
l_abstract_test_case.set_up
l_test_case.test_current_keys
l_test_case.test_has_item
l_test_case.test_has_key
l_test_case.test_has_not_key
l_test_case.test_json_value
l_abstract_test_case.tear_down
end

View File

@@ -25,13 +25,13 @@ feature -- Basic operations
-- Setup test case. Called by test harness
-- before each test routine invocation. Redefine
-- this routine in descendants.
local
file_reader:JSON_FILE_READER
do
create file_reader
json_file:=file_reader.read_json_from ("./json_menu_example.txt")
json_file:=file_reader.read_json_from ("/home/jvelilla/work/eiffel_work/json_test/json_menu_example.txt")
create parse_json.make_parser (json_file)
json_object ?= parse_json.parse
json_value := parse_json.parse
json_object ?= json_value
end
feature -- Tests
@@ -50,10 +50,57 @@ feature -- Tests
assert_integers_equal ("Has 1 key", 1, json_object.get_keys.count)
end
test_has_item is
do
print (json_object.item (create {JSON_STRING}.make_json ("menu")))
end
test_json_value is
--
do
assert_true ("Is a JSON_OBJECT",json_object.is_json_object)
end
test_conversion_to_json_object is
--
local
jo:JSON_OBJECT
do
jo:=json_value.to_json_object
assert ("Is a JSON_OBJECT",jo.has_key (create {JSON_STRING}.make_json ("menu")))
end
test_json_objects_items is
--
local
jo:JSON_OBJECT
do
jo:=json_value.to_json_object
json_value:=jo.item (create {JSON_STRING}.make_json ("menu"))
jo:=json_value.to_json_object
assert_true ("Has key id",jo.has_key (create {JSON_STRING}.make_json ("id")))
assert_true ("Has key value",jo.has_key (create {JSON_STRING}.make_json ("value")))
assert_true ("Has key popup",jo.has_key (create {JSON_STRING}.make_json ("popup")))
assert_true ("Item with key id is a JSON_STRING",jo.item (create{JSON_STRING}.make_json ("id")).is_json_string)
assert_true ("Item with key value is a JSON_STRING",jo.item (create{JSON_STRING}.make_json ("value")).is_json_string)
assert_true ("Item with key popup is a JSON_OBJECT",jo.item (create{JSON_STRING}.make_json ("popup")).is_json_object)
json_value:=jo.item (create{JSON_STRING}.make_json ("popup"))
jo:=json_value.to_json_object
assert_true ("Has key menuitem",jo.has_key (create {JSON_STRING}.make_json ("menuitem")))
assert_true ("Item with key menuitem is a JSON_ARRAY",jo.item (create{JSON_STRING}.make_json ("menuitem")).is_json_array)
end
feature -- JSON_FROM_FILE
json_file:STRING
parse_json:JSON_PARSER
json_object:JSON_OBJECT
file_reader:JSON_FILE_READER
json_value : JSON_VALUE
end