Merge pull request #74 from jvelilla/master
Added description to results classes. Removed unnecessary classes Clean code: removed feature out, updated corresponding test cases.
This commit is contained in:
@@ -1,23 +1,11 @@
|
|||||||
note
|
note
|
||||||
description: "Summary description for {COMMON_RESULTS}."
|
description: "Object that represents a results after parsing Charset or Encoding Accept headers."
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
COMMON_RESULTS
|
COMMON_RESULTS
|
||||||
|
|
||||||
inherit
|
|
||||||
|
|
||||||
ANY
|
|
||||||
redefine
|
|
||||||
out
|
|
||||||
end
|
|
||||||
|
|
||||||
DEBUG_OUTPUT
|
|
||||||
redefine
|
|
||||||
out
|
|
||||||
end
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -48,6 +36,12 @@ feature -- Access
|
|||||||
Result := res
|
Result := res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
params: HASH_TABLE [STRING, STRING]
|
||||||
|
--dictionary of all the parameters for the media range
|
||||||
|
|
||||||
|
feature -- Status Report
|
||||||
|
|
||||||
has_key (a_key: STRING): BOOLEAN
|
has_key (a_key: STRING): BOOLEAN
|
||||||
-- Is there an item in the table with key `a_key'?
|
-- Is there an item in the table with key `a_key'?
|
||||||
do
|
do
|
||||||
@@ -81,37 +75,13 @@ feature -- Element change
|
|||||||
|
|
||||||
feature -- Status Report
|
feature -- Status Report
|
||||||
|
|
||||||
out: STRING
|
|
||||||
-- Representation of the current object
|
|
||||||
do
|
|
||||||
create Result.make_from_string ("(")
|
|
||||||
if attached field as t then
|
|
||||||
Result.append_string ("'" + t + "',")
|
|
||||||
end
|
|
||||||
Result.append_string (" {")
|
|
||||||
from
|
|
||||||
params.start
|
|
||||||
until
|
|
||||||
params.after
|
|
||||||
loop
|
|
||||||
Result.append ("'" + params.key_for_iteration + "':'" + params.item_for_iteration + "',");
|
|
||||||
params.forth
|
|
||||||
end
|
|
||||||
Result.append ("})")
|
|
||||||
end
|
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := out
|
Result := out
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
|
||||||
|
|
||||||
params: HASH_TABLE [STRING, STRING]
|
|
||||||
--dictionary of all the parameters for the media range
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||||
|
|||||||
@@ -1,29 +1,18 @@
|
|||||||
note
|
note
|
||||||
description: "Summary description for {LANGUAGE_RESULTS}."
|
description: "Object that represents a result after parsing Language Headers."
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
LANGUAGE_RESULTS
|
LANGUAGE_RESULTS
|
||||||
|
|
||||||
inherit
|
|
||||||
|
|
||||||
ANY
|
|
||||||
redefine
|
|
||||||
out
|
|
||||||
end
|
|
||||||
|
|
||||||
DEBUG_OUTPUT
|
|
||||||
redefine
|
|
||||||
out
|
|
||||||
end
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
|
--Create an object LANGUAGE_RESULTS.
|
||||||
do
|
do
|
||||||
create params.make (2)
|
create params.make (2)
|
||||||
create mime_type.make_from_string ("*")
|
create mime_type.make_from_string ("*")
|
||||||
@@ -53,6 +42,11 @@ feature -- Access
|
|||||||
Result := res
|
Result := res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
params: HASH_TABLE [STRING, STRING]
|
||||||
|
--dictionary of all the parameters for the media range
|
||||||
|
|
||||||
|
feature -- Status Report
|
||||||
|
|
||||||
has_key (a_key: STRING): BOOLEAN
|
has_key (a_key: STRING): BOOLEAN
|
||||||
-- Is there an item in the table with key `a_key'?
|
-- Is there an item in the table with key `a_key'?
|
||||||
do
|
do
|
||||||
@@ -104,40 +98,12 @@ feature -- Element change
|
|||||||
|
|
||||||
feature -- Status Report
|
feature -- Status Report
|
||||||
|
|
||||||
out: STRING
|
|
||||||
-- Representation of the current object
|
|
||||||
do
|
|
||||||
create Result.make_from_string ("(")
|
|
||||||
if attached type as t then
|
|
||||||
Result.append_string ("'" + t + "',")
|
|
||||||
end
|
|
||||||
if attached sub_type as st then
|
|
||||||
Result.append_string (" '" + st + "',")
|
|
||||||
end
|
|
||||||
Result.append_string (" {")
|
|
||||||
from
|
|
||||||
params.start
|
|
||||||
until
|
|
||||||
params.after
|
|
||||||
loop
|
|
||||||
Result.append ("'" + params.key_for_iteration + "':'" + params.item_for_iteration + "',");
|
|
||||||
params.forth
|
|
||||||
end
|
|
||||||
Result.append ("})")
|
|
||||||
end
|
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := out
|
Result := out
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
|
||||||
|
|
||||||
params: HASH_TABLE [STRING, STRING]
|
|
||||||
--dictionary of all the parameters for the media range
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Summary description for {PARSE_RESULTS}."
|
|
||||||
date: "$Date$"
|
|
||||||
revision: "$Revision$"
|
|
||||||
|
|
||||||
class
|
|
||||||
PARSE_RESULTS
|
|
||||||
|
|
||||||
inherit
|
|
||||||
|
|
||||||
ANY
|
|
||||||
redefine
|
|
||||||
out
|
|
||||||
end
|
|
||||||
|
|
||||||
DEBUG_OUTPUT
|
|
||||||
redefine
|
|
||||||
out
|
|
||||||
end
|
|
||||||
|
|
||||||
create
|
|
||||||
make
|
|
||||||
|
|
||||||
feature -- Initialization
|
|
||||||
|
|
||||||
make
|
|
||||||
do
|
|
||||||
create params.make (2)
|
|
||||||
create mime_type.make_from_string ("*/*")
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
type: detachable STRING
|
|
||||||
|
|
||||||
sub_type: detachable STRING
|
|
||||||
|
|
||||||
mime_type: STRING
|
|
||||||
|
|
||||||
item (a_key: STRING): detachable STRING
|
|
||||||
-- Item associated with `a_key', if present
|
|
||||||
-- otherwise default value of type `STRING'
|
|
||||||
do
|
|
||||||
Result := params.item (a_key)
|
|
||||||
end
|
|
||||||
|
|
||||||
keys: LIST [STRING]
|
|
||||||
-- arrays of currents keys
|
|
||||||
local
|
|
||||||
res: ARRAYED_LIST [STRING]
|
|
||||||
do
|
|
||||||
create res.make_from_array (params.current_keys)
|
|
||||||
Result := res
|
|
||||||
end
|
|
||||||
|
|
||||||
has_key (a_key: STRING): BOOLEAN
|
|
||||||
-- Is there an item in the table with key `a_key'?
|
|
||||||
do
|
|
||||||
Result := params.has_key (a_key)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Element change
|
|
||||||
|
|
||||||
set_type (a_type: STRING)
|
|
||||||
-- Set type with `a_type'
|
|
||||||
do
|
|
||||||
type := a_type
|
|
||||||
if attached sub_type as st then
|
|
||||||
mime_type := a_type + "/" + st
|
|
||||||
else
|
|
||||||
mime_type := a_type + "/*"
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
type_assigned: type ~ a_type
|
|
||||||
end
|
|
||||||
|
|
||||||
set_sub_type (a_sub_type: STRING)
|
|
||||||
-- Set sub_type with `a_sub_type
|
|
||||||
do
|
|
||||||
sub_type := a_sub_type
|
|
||||||
if attached type as t then
|
|
||||||
mime_type := t + "/" + a_sub_type
|
|
||||||
else
|
|
||||||
mime_type := "*/" + a_sub_type
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
sub_type_assigned: sub_type ~ a_sub_type
|
|
||||||
end
|
|
||||||
|
|
||||||
put (new: STRING; key: STRING)
|
|
||||||
-- Insert `new' with `key' if there is no other item
|
|
||||||
-- associated with the same key. If present, replace
|
|
||||||
-- the old value with `new'
|
|
||||||
do
|
|
||||||
if params.has_key (key) then
|
|
||||||
params.replace (new, key)
|
|
||||||
else
|
|
||||||
params.force (new, key)
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
has_key: params.has_key (key)
|
|
||||||
has_item: params.has_item (new)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Status Report
|
|
||||||
|
|
||||||
out: STRING
|
|
||||||
-- Representation of the current object
|
|
||||||
do
|
|
||||||
create Result.make_from_string ("(")
|
|
||||||
if attached type as t then
|
|
||||||
Result.append_string ("'" + t + "',")
|
|
||||||
end
|
|
||||||
if attached sub_type as st then
|
|
||||||
Result.append_string (" '" + st + "',")
|
|
||||||
end
|
|
||||||
Result.append_string (" {")
|
|
||||||
from
|
|
||||||
params.start
|
|
||||||
until
|
|
||||||
params.after
|
|
||||||
loop
|
|
||||||
Result.append ("'" + params.key_for_iteration + "':'" + params.item_for_iteration + "',");
|
|
||||||
params.forth
|
|
||||||
end
|
|
||||||
Result.append ("})")
|
|
||||||
end
|
|
||||||
|
|
||||||
debug_output: STRING
|
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
|
||||||
do
|
|
||||||
Result := out
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
|
||||||
|
|
||||||
params: HASH_TABLE [STRING, STRING]
|
|
||||||
--dictionary of all the parameters for the media range
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
note
|
|
||||||
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -21,13 +21,35 @@ feature {NONE} -- Events
|
|||||||
create parser
|
create parser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Helpers
|
||||||
|
|
||||||
|
format (a_common: COMMON_RESULTS): STRING
|
||||||
|
-- Representation of the current object
|
||||||
|
do
|
||||||
|
create Result.make_from_string ("(")
|
||||||
|
if attached a_common.field as t then
|
||||||
|
Result.append_string ("'" + t + "',")
|
||||||
|
end
|
||||||
|
Result.append_string (" {")
|
||||||
|
from
|
||||||
|
a_common.params.start
|
||||||
|
until
|
||||||
|
a_common.params.after
|
||||||
|
loop
|
||||||
|
Result.append ("'" + a_common.params.key_for_iteration + "':'" + a_common.params.item_for_iteration + "',");
|
||||||
|
a_common.params.forth
|
||||||
|
end
|
||||||
|
Result.append ("})")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Test routines
|
feature -- Test routines
|
||||||
|
|
||||||
test_parse_charsets
|
test_parse_charsets
|
||||||
do
|
do
|
||||||
assert ("Expected ('iso-8859-5', {'q':'1.0',})", parser.parse_common("iso-8859-5").out.same_string("('iso-8859-5', {'q':'1.0',})") )
|
assert ("Expected ('iso-8859-5', {'q':'1.0',})", format (parser.parse_common("iso-8859-5")).same_string("('iso-8859-5', {'q':'1.0',})") )
|
||||||
assert ("Expected ('unicode-1-1', {'q':'0.8',})", parser.parse_common("unicode-1-1;q=0.8").out.same_string("('unicode-1-1', {'q':'0.8',})") )
|
assert ("Expected ('unicode-1-1', {'q':'0.8',})", format (parser.parse_common("unicode-1-1;q=0.8")).same_string("('unicode-1-1', {'q':'0.8',})") )
|
||||||
assert ("Expected ('*', {'q':'1.0',})", parser.parse_common("*").out.same_string("('*', {'q':'1.0',})") )
|
assert ("Expected ('*', {'q':'1.0',})", format (parser.parse_common("*")).same_string("('*', {'q':'1.0',})") )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,41 @@ feature {NONE} -- Events
|
|||||||
create parser
|
create parser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Helpers
|
||||||
|
|
||||||
|
format (a_language: LANGUAGE_RESULTS): STRING
|
||||||
|
-- Representation of the current object
|
||||||
|
do
|
||||||
|
create Result.make_from_string ("(")
|
||||||
|
if attached a_language.type as t then
|
||||||
|
Result.append_string ("'" + t + "',")
|
||||||
|
end
|
||||||
|
if attached a_language.sub_type as st then
|
||||||
|
Result.append_string (" '" + st + "',")
|
||||||
|
end
|
||||||
|
Result.append_string (" {")
|
||||||
|
if attached a_language.params as l_params then
|
||||||
|
from
|
||||||
|
l_params.start
|
||||||
|
until
|
||||||
|
l_params.after
|
||||||
|
loop
|
||||||
|
Result.append ("'" + l_params.key_for_iteration + "':'"+ l_params.item_for_iteration + "',");
|
||||||
|
l_params.forth
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Result.append ("})")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Test routines
|
feature -- Test routines
|
||||||
|
|
||||||
test_parse_media_range
|
test_parse_language
|
||||||
do
|
do
|
||||||
assert ("Expected ('da', {'q':'1.0',})", parser.parse_language_range ("da").out.same_string ("('da', {'q':'1.0',})"));
|
assert ("Expected ('da', {'q':'1.0',})", format (parser.parse_language_range ("da")).same_string ("('da', {'q':'1.0',})"));
|
||||||
assert ("Expected ('en', 'gb', {'q':'0.8',})", parser.parse_language_range ("en-gb;q=0.8").out.same_string ("('en', 'gb', {'q':'0.8',})"));
|
assert ("Expected ('en', 'gb', {'q':'0.8',})", format (parser.parse_language_range ("en-gb;q=0.8")).same_string ("('en', 'gb', {'q':'0.8',})"));
|
||||||
assert ("Expected ('en', {'q':'0.7',})", parser.parse_language_range ("en;q=0.7").out.same_string ("('en', {'q':'0.7',})"));
|
assert ("Expected ('en', {'q':'0.7',})", format (parser.parse_language_range ("en;q=0.7")).same_string ("('en', {'q':'0.7',})"));
|
||||||
assert ("Expected ('en', '*', {'q':'1.0',})", parser.parse_language_range ("en-*").out.same_string ("('en', '*', {'q':'1.0',})"));
|
assert ("Expected ('en', '*', {'q':'1.0',})", format (parser.parse_language_range ("en-*")).same_string ("('en', '*', {'q':'1.0',})"));
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user