note
description: "Summary description for {TEST_PARSER}."
date: "$Date$"
revision: "$Revision$"
deferred class
TEST_PARSER
inherit
EXECUTION_ENVIRONMENT
feature -- Access
file_as_string_mode: BOOLEAN
do
Result := attached get ("TEST_XML_PARSER_KIND") as e and then e.is_case_insensitive_equal ("string")
end
get_parser_mode
do
print ("Executing: " + command_line.command_line + "%N")
parser_mode := null_mode
if attached get ("TEST_XML_PARSER") as m then
m.to_lower
if m ~ "debug" then
parser_mode := debug_mode
elseif m ~ "tree" then
parser_mode := tree_mode
elseif m ~ "xml_tree" then
parser_mode := xml_tree_mode
elseif m ~ "xml_tree_vis" then
parser_mode := xml_tree_vis_mode
end
end
print ("Test xml Parser mode: " + parser_mode_meaning + "%N")
print ("%TSet environment variable TEST_XML_PARSER to change behavior.%N")
print ("%Tavailable values: null (default), debug, tree, xml_tree, xml_tree_vis%N")
print ("Xml Parser kind: " + file_as_string_mode_meaning + "%N")
print ("%TSet environment variable TEST_XML_PARSER_KIND to change behavior.%N")
print ("%Tavailable values: string, file (default)%N")
print ("%N")
end
short_description: STRING
local
s: STRING
do
create Result.make_empty
s := command_line.command_name.string
Result.append_string (s)
Result.append_character (':')
Result.append_character (' ')
if file_as_string_mode then
s := "STRING"
else
s := "FILE"
end
Result.append_string (s)
Result.append_character ('+')
inspect
parser_mode
when null_mode then
s := "NULL"
when debug_mode then
s := "DEBUG"
when tree_mode then
s := "TREE"
when xml_tree_mode then
s := "XML_TREE"
when xml_tree_vis_mode then
s := "XML_TREE_VIS"
else
s := "NULL"
end
Result.append_string (s)
end
file_as_string_mode_meaning: STRING
do
if file_as_string_mode then
Result := "string: read content of file, then parse string"
else
Result := "file: parse file directly"
end
end
parser_mode: INTEGER
parser_mode_meaning: STRING
do
inspect
parser_mode
when null_mode then
Result := "NULL: only parser, no callbacks"
when debug_mode then
Result := "DEBUG: callbacks with debug output"
when tree_mode then
Result := "TREE: building a tree (document)"
when xml_tree_mode then
Result := "XML_TREE: building a (xml_dom) tree (document)"
when xml_tree_vis_mode then
Result := "XML_TREE_VIS: building a (xml_dom) tree (document) + print via Visitor"
else
Result := "NULL: only parser, no callbacks"
end
end
null_mode: INTEGER = 0
debug_mode: INTEGER = 1
tree_mode: INTEGER = 2
xml_tree_mode: INTEGER = 3
xml_tree_vis_mode: INTEGER = 4
filename: detachable STRING
local
args: ARGUMENTS
ht: HASH_TABLE [STRING, INTEGER]
s: STRING
i: INTEGER
dn: DIRECTORY_NAME
do
create args
if args.argument_count > 0 then
Result := args.argument (1)
else
create ht.make (10)
ht.force ("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\en\mscorlib.xml", 1)
ht.force ("C:\temp\test.xml", 2)
if attached get ("EIFFEL_SRC") as eiffel_src then
ht.force (eiffel_src + "\Eiffel\Ace\ec.ecf", 3)
end
create dn.make_from_string (current_working_directory)
dn.extend ("data")
ht.force (dn.string, 4)
-- ht.force ("C:\_dev\trunk\Src\framework\xml\tests\data\xmlconf\xmltest\valid\sa\087.xml", 5)
from
ht.start
until
ht.after
loop
print (ht.key_for_iteration.out + ": " + ht.item_for_iteration + "%N")
ht.forth
end
from
i := 0
until
i /= 0
loop
print (" Choice? ")
io.read_line
s := io.last_string
if s.is_integer then
i := s.to_integer
if ht.has (i) then
Result := ht.item (i)
else
i := 0
end
end
end
end
end
file_content (fn: STRING): STRING
local
f: RAW_FILE
p: INTEGER
do
create f.make (fn)
f.open_read
f.read_stream (f.count)
Result := f.last_string
f.close
p := Result.index_of ('<', 1)
Result := Result.substring (p, Result.count)
end
t1, t2: detachable TIME
report_chrono
local
duration: TIME_DURATION
do
if attached t1 as l_t1 and attached t2 as l_t2 then
duration := l_t2.relative_duration (l_t1)
print ("CHRONO " + short_description + " " + duration.minute.out + " minutes " + duration.fine_second.out + " fine seconds.%N")
end
end
start_chrono
do
create t1.make_now
t2 := Void
end
stop_chrono
do
create t2.make_now
end
feature -- Test
test (fn: STRING)
local
dir: DIRECTORY
do
create dir.make (fn)
if dir.exists then
if attached xml_files (fn) as filenames then
from
filenames.start
until
filenames.after
loop
test_entry (filenames.item)
filenames.forth
end
end
else
test_entry (fn)
end
end
test_entry (fn: STRING)
local
vis: detachable XML_NODE_VISITOR_PRINT
do
if file_as_string_mode then
test_file_content (fn)
else
test_file (fn)
end
after_test_entry (fn)
report_chrono
end
after_test_entry (fn: STRING)
deferred
end
test_file (fn: STRING)
deferred
end
test_file_content (fn: STRING)
deferred
end
feature -- Files
xml_files (n: STRING): ARRAYED_LIST [STRING]
local
d: DIRECTORY
fn: FILE_NAME
do
create d.make (n)
if d.exists then
create Result.make (10)
d.open_read
from
d.start
d.readentry
until
d.lastentry = Void
loop
if
attached d.lastentry as i and then
not i.is_empty and then
i.item (1) /= '.'
then
create fn.make_from_string (n)
fn.set_file_name (i)
Result.append (xml_files (fn.string))
end
d.readentry
end
d.close
elseif n.substring (n.count - 3, n.count).same_string_general (".xml") then
create Result.make (1)
Result.extend (n)
else
create Result.make (0)
end
end
feature -- Access
char (c: INTEGER): CHARACTER
do
Result := c.to_character_8
end
html_entity_mapping: HASH_TABLE [CHARACTER, STRING]
local
map: like html_entity_mapping
once
create map.make (101)
-- Required
map.force ('&', "&")
map.force ('"', """)
map.force ('<', "<")
map.force ('>', ">")
-- Optional
map.force (char(128), "€")
map.force (char(156), "œ")
map.force (char(159), "Ÿ")
map.force (char(160), "&nbps;")
map.force (char(161), "¡")
map.force (char(162), "¢")
map.force (char(163), "£")
map.force (char(164), "¤")
map.force (char(165), "¥")
map.force (char(166), "¦")
map.force (char(167), "§")
map.force (char(168), "¨")
map.force (char(169), "©")
map.force (char(170), "ª")
map.force (char(171), "«")
map.force (char(172), "¬")
map.force (char(173), "")
map.force (char(174), "®")
map.force (char(175), "&masr;")
map.force (char(176), "°")
map.force (char(177), "±")
map.force (char(178), "²")
map.force (char(179), "³")
map.force (char(180), "´")
map.force (char(181), "µ")
map.force (char(182), "¶")
map.force (char(183), "·")
map.force (char(184), "¸")
map.force (char(185), "¹")
map.force (char(186), "º")
map.force (char(187), "»")
map.force (char(188), "¼")
map.force (char(189), "½")
map.force (char(190), "¾")
map.force (char(191), "¿")
map.force (char(192), "À")
map.force (char(193), "Á")
map.force (char(194), "Â")
map.force (char(195), "Ã")
map.force (char(196), "Ä")
map.force (char(197), "Å")
map.force (char(198), "Æ")
map.force (char(199), "Ç")
map.force (char(200), "È")
map.force (char(201), "É")
map.force (char(202), "Ê")
map.force (char(203), "Ë")
map.force (char(204), "Ì")
map.force (char(205), "Í")
map.force (char(206), "Î")
map.force (char(207), "Ï")
map.force (char(208), "ð")
map.force (char(209), "Ñ")
map.force (char(210), "Ò")
map.force (char(211), "Ó")
map.force (char(212), "Ô")
map.force (char(213), "Õ")
map.force (char(214), "Ö")
map.force (char(215), "×")
map.force (char(216), "Ø")
map.force (char(217), "Ù")
map.force (char(218), "Ú")
map.force (char(219), "Û")
map.force (char(220), "Ü")
map.force (char(221), "Ý")
map.force (char(222), "þ")
map.force (char(223), "ß")
map.force (char(224), "à")
map.force (char(225), "á")
map.force (char(226), "â")
map.force (char(227), "ã")
map.force (char(228), "ä")
map.force (char(229), "å")
map.force (char(230), "æ")
map.force (char(231), "ç")
map.force (char(232), "è")
map.force (char(233), "é")
map.force (char(234), "ê")
map.force (char(235), "ë")
map.force (char(236), "ì")
map.force (char(237), "í")
map.force (char(238), "î")
map.force (char(239), "ï")
map.force (char(240), "ð")
map.force (char(241), "ñ")
map.force (char(242), "ò")
map.force (char(243), "ó")
map.force (char(244), "ô")
map.force (char(245), "õ")
map.force (char(246), "ö")
map.force (char(247), "÷")
map.force (char(248), "ø")
map.force (char(249), "ù")
map.force (char(250), "ú")
map.force (char(251), "û")
map.force (char(252), "ü")
map.force (char(253), "ý")
map.force (char(254), "þ")
map.force (char(255), "ÿ")
Result := map
end
text: STRING = "[
This is a title & "nothing" else !
]"
text_entity: STRING = "[
This is a title & "nothing" else !
]"
text_ecf: STRING = "[
]"
note
copyright: "Copyright (c) 1984-2010, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end