#
# Copyright (c) 2001 by Jim Menard
#
# Released under the same license as Ruby. See
# http://www.ruby-lang.org/en/LICENSE.txt.
#
require 'singleton'
# This class holds resources that are read-only, and therefore only
# need to be created once.
class TestResource
include Singleton
attr_reader :xml, :newlineTok, :xmlDecl, :piWithArgs, :piNoArgs,
:entityTag, :element, :attlist, :notation, :doctype, :comment,
:outerStart, :textDataWithSub, :simpleTagStart, :simpleTextData,
:simpleTagEnd, :innerTagStart, :innerTagEnd, :pTagStart, :pTagEnd,
:bTagStart, :bTagEnd, :textText, :boldText, :moreTextText, :cdata,
:outerEnd
attr_reader :tricky_substitution_xml
# Each test that uses this data expects the data to be returned from a
# tokenizer or parser differently, or in a slightly different order.
# Therefore we can't set up one single array containing the expected
# result objects in order.
def initialize
@xml = '
]>
data&&foo;
more on next linetext
text bold café coffee more text
'
emptyAttrs = Hash.new()
@newlineTok = NQXML::Text.new("\n")
attrs = Hash.new()
attrs['version'] = '1.0'
@xmlDecl = NQXML::XMLDecl.new('xml', attrs, '')
src = ''
@piWithArgs =
NQXML::ProcessingInstruction.new('misc:processingInstruction',
'"with arguments"', src)
@piNoArgs = NQXML::ProcessingInstruction.new('other:piNoArgs', '',
'')
@entityTag =
NQXML::GeneralEntityTag.new('foo', 'bletch', nil, nil,
'')
@element = NQXML::Element.new('el', '', '')
@attlist = NQXML::Attlist.new('el', 'EMPTY', '')
@notation = NQXML::Notation.new('notation', 'ignored',
'')
@doctypePubid =
NQXML::PublicExternalID.new('"public id"', '"foobar"',
'PUBLIC "public id" "foobar"')
@doctype =
NQXML::Doctype.new('outer', @doctypePubid,
[@entityTag, @element, @attlist, @notation],
"\n" +
" \n" +
" \n" +
" \n" +
"]>")
@comment = NQXML::Comment.new('')
@outerStart = NQXML::Tag.new('outer', emptyAttrs, false, '')
@textDataWithSub = NQXML::Text.new("\n data&bletch\nmore on next line")
@simpleTagStart = NQXML::Tag.new('simpleTag', emptyAttrs, false,
'')
@simpleTextData = NQXML::Text.new('text')
@simpleTagEnd = NQXML::Tag.new('simpleTag', nil, true, '')
attrs = Hash.new()
attrs['a'] = 'tabs to spacesbletch'
@innerTagStart = NQXML::Tag.new('inner:tag', attrs, false,
'')
@innerTagEnd = NQXML::Tag.new('inner:tag', nil, true,
'')
@pTagStart = NQXML::Tag.new('p', emptyAttrs, false, '')
@pTagEnd = NQXML::Tag.new('p', nil, true, '
')
@bTagStart = NQXML::Tag.new('b', emptyAttrs, false, '')
@bTagEnd = NQXML::Tag.new('b', nil, true, '')
@textText = NQXML::Text.new('text ')
@boldText = NQXML::Text.new('bold café coffee')
@moreTextText = NQXML::Text.new(' more text')
@cdata = NQXML::Text.new("xx")
@outerEnd = NQXML::Tag.new('outer', nil, true, '')
@sub1_xml = '
An ampersand (&) may be escaped numerically (&) or with a general entity (&).
" >
]>
'
src = 'An ampersand (&) may be' +
' escaped numerically (&) or with a general entity' +
' (&). >'
val = "An ampersand (&) may be escaped numerically" +
" (&) or with a general entity (&).
"
@sub1Entity = NQXML::GeneralEntityTag.new('example', val, nil, nil,
src)
@sub2_xml = '
\' >
%xx;
]>
This sample shows a &tricky; method.
'
@xxEntity =
NQXML::ParameterEntityTag.new('xx', '%zz;', nil,
'')
src = '\' >'
val = ''
@zzEntity = NQXML::ParameterEntityTag.new('zz', val, nil, src)
end
end