Changeset 547:fd80af68bedc
- Timestamp:
- 04/06/08 00:29:46 (8 months ago)
- Branch:
- default
- Files:
-
- 9 modified
-
bin/info.rb (modified) (1 diff)
-
bin/install.rb (modified) (1 diff)
-
bin/repackage.rb (modified) (1 diff)
-
src/rexml/document.rb (modified) (4 diffs)
-
test/attributes.rb (modified) (1 diff)
-
test/core_test.rb (modified) (8 diffs)
-
test/pullparser.rb (modified) (1 diff)
-
test/validation_rng.rb (modified) (1 diff)
-
test/xpath_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
bin/info.rb
r378 r547 18 18 19 19 k = case ARGV[0] 20 when /^t/ :'tag'21 when /^u/ :'url'22 when /^r/ :'revision'23 when /^a/ :'author'24 when /^d/ :'date'20 when /^t/ then 'tag' 21 when /^u/ then 'url' 22 when /^r/ then 'revision' 23 when /^a/ then 'author' 24 when /^d/ then 'date' 25 25 else 26 26 puts %Q{Unrecognized command "#{ARGV[0]}"} -
bin/install.rb
r282 r547 30 30 require 'getoptlong' 31 31 require 'rbconfig' 32 require ' ftools'32 require 'FileUtils' 33 33 require 'find' 34 34 35 35 opts = GetoptLong.new( [ '--uninstall', '-u', GetoptLong::NO_ARGUMENT], 36 [ '--destdir', '-d', GetoptLong::REQUIRED_ARGUMENT ],37 [ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],38 [ '--concurrent', '-c', GetoptLong::NO_ARGUMENT],39 [ '--help', '-h', GetoptLong::NO_ARGUMENT],40 [ '--noop', '-n', GetoptLong::NO_ARGUMENT])36 [ '--destdir', '-d', GetoptLong::REQUIRED_ARGUMENT ], 37 [ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ], 38 [ '--concurrent', '-c', GetoptLong::NO_ARGUMENT], 39 [ '--help', '-h', GetoptLong::NO_ARGUMENT], 40 [ '--noop', '-n', GetoptLong::NO_ARGUMENT]) 41 41 42 42 -
bin/repackage.rb
r43 r547 3 3 Dir.chdir ".." if Dir.pwd =~ /bin.?$/ 4 4 5 require " ftools"5 require "FileUtils" 6 6 7 7 def copy_recursively( dir_name, dest ) -
src/rexml/document.rb
r546 r547 18 18 # Note that if you want to have an XML declaration written for a document 19 19 # you create, you must add one; REXML documents do not write a default 20 # declaration for you. See |DECLARATION| and |write|.21 class Document < Element22 # A convenient default XML declaration. If you want an XML declaration,23 # the easiest way to add one is mydoc << Document::DECLARATION24 # +DEPRECATED+25 # Use: mydoc << XMLDecl.default26 DECLARATION = XMLDecl.default27 28 # Constructor29 # @param source if supplied, must be a Document, String, or IO.30 # Documents have their context and Element attributes cloned.31 # Strings are expected to be valid XML documents. IOs are expected32 # to be sources of valid XML documents.33 # @param context if supplied, contains the context of the document;34 # this should be a Hash.35 def initialize( source = nil, context = {} )36 super()37 @context = context38 return if source.nil?39 if source.kind_of? Document40 @context = source.context41 super source42 else43 build( source )44 end45 end20 # declaration for you. See |DECLARATION| and |write|. 21 class Document < Element 22 # A convenient default XML declaration. If you want an XML declaration, 23 # the easiest way to add one is mydoc << Document::DECLARATION 24 # +DEPRECATED+ 25 # Use: mydoc << XMLDecl.default 26 DECLARATION = XMLDecl.default 27 28 # Constructor 29 # @param source if supplied, must be a Document, String, or IO. 30 # Documents have their context and Element attributes cloned. 31 # Strings are expected to be valid XML documents. IOs are expected 32 # to be sources of valid XML documents. 33 # @param context if supplied, contains the context of the document; 34 # this should be a Hash. 35 def initialize( source = nil, context = {} ) 36 super() 37 @context = context 38 return if source.nil? 39 if source.kind_of? Document 40 @context = source.context 41 super source 42 else 43 build( source ) 44 end 45 end 46 46 47 47 def node_type … … 49 49 end 50 50 51 # Should be obvious52 def clone53 Document.new self54 end55 56 # According to the XML spec, a root node has no expanded name57 def expanded_name58 ''59 #d = doc_type60 #d ? d.name : "UNDEFINED"61 end62 63 alias :name :expanded_name64 65 # We override this, because XMLDecls and DocTypes must go at the start66 # of the document67 def add( child )68 if child.kind_of? XMLDecl69 @children.unshift child51 # Should be obvious 52 def clone 53 Document.new self 54 end 55 56 # According to the XML spec, a root node has no expanded name 57 def expanded_name 58 '' 59 #d = doc_type 60 #d ? d.name : "UNDEFINED" 61 end 62 63 alias :name :expanded_name 64 65 # We override this, because XMLDecls and DocTypes must go at the start 66 # of the document 67 def add( child ) 68 if child.kind_of? XMLDecl 69 @children.unshift child 70 70 child.parent = self 71 elsif child.kind_of? DocType71 elsif child.kind_of? DocType 72 72 # Find first Element or DocType node and insert the decl right 73 73 # before it. If there is no such node, just insert the child at the … … 87 87 @children[insert_before_index] = child 88 88 end 89 child.parent = self90 else91 rv = super92 raise "attempted adding second root element to document" if @elements.size > 193 rv94 end95 end96 alias :<< :add97 98 def add_element(arg=nil, arg2=nil)99 rv = super100 raise "attempted adding second root element to document" if @elements.size > 1101 rv102 end103 104 # @return the root Element of the document, or nil if this document105 # has no children.106 def root89 child.parent = self 90 else 91 rv = super 92 raise "attempted adding second root element to document" if @elements.size > 1 93 rv 94 end 95 end 96 alias :<< :add 97 98 def add_element(arg=nil, arg2=nil) 99 rv = super 100 raise "attempted adding second root element to document" if @elements.size > 1 101 rv 102 end 103 104 # @return the root Element of the document, or nil if this document 105 # has no children. 106 def root 107 107 elements[1] 108 108 #self 109 109 #@children.find { |item| item.kind_of? Element } 110 end111 112 # @return the DocType child of the document, if one exists,113 # and nil otherwise.114 def doctype115 @children.find { |item| item.kind_of? DocType }116 end117 118 # @return the XMLDecl of this document; if no XMLDecl has been119 # set, the default declaration is returned.120 def xml_decl121 rv = @children[0]110 end 111 112 # @return the DocType child of the document, if one exists, 113 # and nil otherwise. 114 def doctype 115 @children.find { |item| item.kind_of? DocType } 116 end 117 118 # @return the XMLDecl of this document; if no XMLDecl has been 119 # set, the default declaration is returned. 120 def xml_decl 121 rv = @children[0] 122 122 return rv if rv.kind_of? XMLDecl 123 123 rv = @children.unshift(XMLDecl.default)[0] 124 end125 126 # @return the XMLDecl version of this document as a String.127 # If no XMLDecl has been set, returns the default version.128 def version129 xml_decl().version130 end131 132 # @return the XMLDecl encoding of this document as a String.133 # If no XMLDecl has been set, returns the default encoding.134 def encoding135 xml_decl().encoding136 end137 138 # @return the XMLDecl standalone value of this document as a String.139 # If no XMLDecl has been set, returns the default setting.140 def stand_alone?141 xml_decl().stand_alone?142 end124 end 125 126 # @return the XMLDecl version of this document as a String. 127 # If no XMLDecl has been set, returns the default version. 128 def version 129 xml_decl().version 130 end 131 132 # @return the XMLDecl encoding of this document as a String. 133 # If no XMLDecl has been set, returns the default encoding. 134 def encoding 135 xml_decl().encoding 136 end 137 138 # @return the XMLDecl standalone value of this document as a String. 139 # If no XMLDecl has been set, returns the default setting. 140 def stand_alone? 141 xml_decl().stand_alone? 142 end 143 143 144 144 # Write the XML tree out, optionally with indent. This writes out the … … 195 195 end 196 196 formatter.write( self, output ) 197 end197 end 198 198 199 199 200 def Document::parse_stream( source, listener )201 Parsers::StreamParser.new( source, listener ).parse202 end203 204 private205 def build( source )200 def Document::parse_stream( source, listener ) 201 Parsers::StreamParser.new( source, listener ).parse 202 end 203 204 private 205 def build( source ) 206 206 Parsers::TreeParser.new( source, self ).parse 207 end208 end207 end 208 end 209 209 end -
test/attributes.rb
r492 r547 92 92 # Submitted by Kou 93 93 def test_namespace_conflict 94 assert_raise s( ParseException,94 assert_raise( ParseException, 95 95 "Declaring two attributes with the same namespace should be an error" ) do 96 96 REXML::Document.new <<-XML -
test/core_test.rb
r546 r547 56 56 '<a a' + [0x0371].pack('U') + '="" />', 57 57 ].each do |src| 58 assert_raise s( ParseException, %Q{Parse #{src.inspect} should have failed!} ) do58 assert_raise( ParseException, %Q{Parse #{src.inspect} should have failed!} ) do 59 59 Document.new(src) 60 60 end … … 135 135 assert_equal(comment, comment2) 136 136 137 assert_raise s(ParseException) {137 assert_raise(ParseException) { 138 138 REXML::Document.new("<d><!- foo --></d>") 139 139 } 140 assert_raise s(ParseException) {140 assert_raise(ParseException) { 141 141 REXML::Document.new("<d><!-- foo -></d>") 142 142 } … … 287 287 assert_equal(instruction.to_s, instruction2.to_s) 288 288 289 assert_raise s(ParseException) {289 assert_raise(ParseException) { 290 290 REXML::Document.new("<d><?foo bar></d>") 291 291 } … … 856 856 857 857 def test_more_namespaces 858 assert_raise s( REXML::UndefinedNamespaceException,858 assert_raise( REXML::UndefinedNamespaceException, 859 859 %Q{Should have gotten an Undefined Namespace error} ) { 860 860 doc1 = Document.new("<r><p><n:c/></p></r>") … … 1045 1045 def test_null_element_name 1046 1046 a = REXML::Document.new 1047 assert_raise s( RuntimeError ) {1047 assert_raise( RuntimeError ) { 1048 1048 a.add_element( nil ) 1049 1049 } … … 1194 1194 def test_ticket_76 1195 1195 src = "<div>at&t" 1196 assert_raise s( ParseException, %Q{"#{src}" is invalid XML} ) {1196 assert_raise( ParseException, %Q{"#{src}" is invalid XML} ) { 1197 1197 REXML::Document.new(src) 1198 1198 } … … 1201 1201 def test_ticket_21 1202 1202 src = "<foo bar=value/>" 1203 assert_raise s( ParseException, "invalid XML should be caught" ) {1203 assert_raise( ParseException, "invalid XML should be caught" ) { 1204 1204 d = REXML::Document.new(src) 1205 1205 } … … 1325 1325 def test_ticket_14 1326 1326 # Per .2.5 Node Tests of XPath spec 1327 assert_raise s( REXML::UndefinedNamespaceException,1327 assert_raise( REXML::UndefinedNamespaceException, 1328 1328 %Q{Should have gotten an Undefined Namespace error} ) { 1329 1329 d = Document.new("<a><n:b/></a>") -
test/pullparser.rb
r390 r547 33 33 source = "<a><b></a>" 34 34 parser = REXML::Parsers::PullParser.new(source) 35 assert_raise s(ParseException, "Parsing should have failed") {35 assert_raise(ParseException, "Parsing should have failed") { 36 36 results = parser.pull while parser.has_next? 37 37 } -
test/validation_rng.rb
r441 r547 779 779 parser = REXML::Parsers::TreeParser.new( source ) 780 780 parser.add_listener( validator.reset ) 781 assert_raise s( REXML::Validation::ValidationException,781 assert_raise( REXML::Validation::ValidationException, 782 782 "Expected a validation error" ) { parser.parse } 783 783 end -
test/xpath_test.rb
r491 r547 588 588 589 589 def test_name 590 assert_raise s( UndefinedNamespaceException, "x should be undefined" ) {590 assert_raise( UndefinedNamespaceException, "x should be undefined" ) { 591 591 d = REXML::Document.new("<a x='foo'><b/><x:b/></a>") 592 592 }
