[前][次][番号順一覧][スレッド一覧]

ruby-changes:33062

From: kou <ko1@a...>
Date: Sat, 22 Feb 2014 23:03:46 +0900 (JST)
Subject: [ruby-changes:33062] kou:r45141 (trunk): * test/rexml/xpath/test_attribute.rb: Simplify.

kou	2014-02-22 23:03:25 +0900 (Sat, 22 Feb 2014)

  New Revision: 45141

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45141

  Log:
    * test/rexml/xpath/test_attribute.rb: Simplify.

  Modified files:
    trunk/ChangeLog
    trunk/test/rexml/xpath/test_attribute.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45140)
+++ ChangeLog	(revision 45141)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+2014-02-22  Kouhei Sutou  <kou@c...>
+
+        * test/rexml/xpath/test_attribute.rb: Simplify.
+
 Sat Feb 22 20:28:47 2014  NAKAMURA Usaku  <usa@r...>
 
 	* tool/redmine-backporter.rb: more friendly.
Index: test/rexml/xpath/test_attribute.rb
===================================================================
--- test/rexml/xpath/test_attribute.rb	(revision 45140)
+++ test/rexml/xpath/test_attribute.rb	(revision 45141)
@@ -2,84 +2,26 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/rexml/xpath/test_attribute.rb#L2
 require 'rexml/document'
 
 class TestXPathAttribute < Test::Unit::TestCase
-
-  # xmlstr1 and xmlstr2 only differ in the second line - namespaces in the root element
-  @@xmlstr1 = '<?xml version="1.0" encoding="UTF-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gCal="http://schemas.google.com/gCal/2005">
-  <id>http://www.google.com/calendar/feeds/me%40gmail.com</id>
-  <entry>
-    <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id>
-    <published>2007-05-16T13:42:27.942Z</published>
-    <updated>2007-05-15T03:29:28.000Z</updated>
-    <title type="text">My Calendar</title>
-    <link rel="alternate" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/private/full"/>
-    <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/acl/full"/>
-    <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/>
-    <author>
-      <name>Me</name>
-      <email>me@g...</email>
-    </author>
-  </entry>
-</feed>'
-
-
-  @@xmlstr2 = '<?xml version="1.0" encoding="UTF-8"?>
-<feed>
-  <id>http://www.google.com/calendar/feeds/me%40gmail.com</id>
-  <entry>
-    <id>http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com</id>
-    <published>2007-05-16T13:42:27.942Z</published>
-    <updated>2007-05-15T03:29:28.000Z</updated>
-    <title type="text">My Calendar</title>
-    <link rel="alternate" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/private/full"/>
-    <link rel="http://schemas.google.com/acl/2007#accessControlList" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/acl/full"/>
-    <link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"/>
-    <author>
-      <name>Me</name>
-      <email>me@g...</email>
-    </author>
-  </entry>
-</feed>'
-
-  # Fails
-  def test_xpath_query
-    do_test @@xmlstr1
+  def setup
+    @xml = <<-XML
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+  <child name="one">child1</child>
+  <child name="two">child2</child>
+  <child name="three">child3</child>
+</root>
+    XML
+    @document = REXML::Document.new(@xml)
   end
 
-  # Passes
-  def test_xpath_query_no_namespace
-    do_test @@xmlstr2
+  def test_elements
+    root = @document.elements["root"]
+    second_child = root.elements["child[@name='two']"]
+    assert_equal("child2", second_child.text)
   end
 
-  def do_test(xmlString)
-    hrefs = [
-      "http://www.google.com/calendar/feeds/me%40gmail.com/private/full",
-      "http://www.google.com/calendar/feeds/me%40gmail.com/acl/full",
-      "http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"
-    ]
-    ctr=0
-    REXML::Document.new(xmlString).elements.each("feed/entry") do |element|
-      @alternate_link = element.elements["link[@rel='alternate']"]
-      assert_not_nil( @alternate_link )
-      assert_equal( hrefs[ctr], @alternate_link.attributes['href'])
-      ctr += 1
-    end
-  end
-
-
-  def test_another_way
-    doc = REXML::Document.new(@@xmlstr1)
-    hrefs = [
-      "http://www.google.com/calendar/feeds/me%40gmail.com/private/full",
-      "http://www.google.com/calendar/feeds/me%40gmail.com/acl/full",
-      "http://www.google.com/calendar/feeds/me%40gmail.com/me%40gmail.com"
-    ]
-    ctr=0
-    REXML::XPath.each(doc, "//link[@rel='alternate']") do |element|
-      @alternate_link = element
-      assert_not_nil @alternate_link
-      assert_equal( hrefs[ctr], @alternate_link.attributes['href'])
-      ctr += 1
-    end
+  def test_xpath_each
+    children = REXML::XPath.each(@document, "/root/child[@name='two']")
+    assert_equal(["child2"], children.collect(&:text))
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]