PageRenderTime 29ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/test/rexml/test_order.rb

https://gitlab.com/MichelZuniga/ruby
Ruby | 109 lines | 105 code | 3 blank | 1 comment | 1 complexity | fc2ea90fe1d2eb98f388d1e6e401be37 MD5 | raw file
  1. require_relative 'rexml_test_utils'
  2. require 'rexml/document'
  3. begin
  4. require 'zlib'
  5. rescue LoadError
  6. end
  7. module REXMLTests
  8. class OrderTester < Test::Unit::TestCase
  9. include REXMLTestUtils
  10. TESTDOC = <<END
  11. <a>
  12. <b/>
  13. <x id='1'/>
  14. <c/>
  15. <d>
  16. <x id='2'/>
  17. </d>
  18. <x id='3'/>
  19. </a>
  20. END
  21. def setup
  22. @doc = REXML::Document.new(TESTDOC)
  23. @items = REXML::XPath.match(@doc,'//x')
  24. end
  25. def test_first_element
  26. assert_equal '1', @items[0].attributes['id']
  27. end
  28. def test_second_element
  29. assert_equal '2', @items[1].attributes['id']
  30. end
  31. def test_third_element
  32. assert_equal '3', @items[2].attributes['id']
  33. end
  34. def test_order
  35. d = REXML::Document.new( "<a><x id='1'/><x id='2'/><x id='3'/>
  36. <x id='4'/><x id='5'/></a>" )
  37. items = REXML::XPath.match( d, '//x' )
  38. assert_equal( %w{1 2 3 4 5}, items.collect{|e| e.attributes['id']} )
  39. d = REXML::Document.new( "<a>
  40. <x><z><y id='1'/><y id='2'/></z><y id='3'/></x>
  41. <x><y id='4'/></x></a>" )
  42. items = REXML::XPath.match( d, '//y' )
  43. assert_equal( %w{1 2 3 4}, items.collect{|e| e.attributes['id']} )
  44. end
  45. # Provided by Tom Talbott
  46. def test_more_ordering
  47. doc = Zlib::GzipReader.open(fixture_path('LostineRiver.kml.gz'), encoding: 'utf-8') do |f|
  48. REXML::Document.new(f)
  49. end
  50. actual = [
  51. "Head south from Phinney Ave N",
  52. "Turn left at N 36th St",
  53. "Turn right at Fremont Ave N",
  54. "Continue on 4th Ave N",
  55. "Turn left at Westlake Ave N",
  56. "Bear right at 9th Ave N",
  57. "Turn left at Mercer St",
  58. "Take the I-5 ramp",
  59. "Take the I-5 S ramp",
  60. "Take the I-90 E exit #164 to Bellevue/Spokane/4th Ave S.",
  61. "Take the I-90 E ramp to Bellevue/Spokane",
  62. "Take exit #137 to Wanapum Dam/Richland",
  63. "Bear right at WA-26",
  64. "Bear right and head toward WA-243",
  65. "Continue on WA-243",
  66. "Bear right at WA-24",
  67. "Continue on WA-240",
  68. "Turn right at WA-240 E",
  69. "Take the I-182 W ramp to Yakima (I-82)/Pendleton",
  70. "Take the I-82 E ramp to Umatilla/Pendleton",
  71. "Take the I-84 E ramp to Pendleton",
  72. "Take the OR-82 exit #261 to La Grande/Elgin",
  73. "Turn right at Island Ave",
  74. "Continue on W 1st St",
  75. "Turn left at N McAlister Rd",
  76. "Bear right at OR-82",
  77. "Continue on Wallowa Lake Hwy",
  78. "Continue on OR-82",
  79. "Continue on Ruckman Ave",
  80. "Continue on OR-82",
  81. "Continue on S 8th Ave",
  82. "Turn right at Albany St",
  83. "Continue on OR-82",
  84. "Continue on Wallowa Lake Hwy",
  85. "Continue on N Madison St",
  86. "Bear left at W 1st St",
  87. "Continue on Wallowa Lake Hwy",
  88. "Continue on Water St",
  89. "Bear right at Lostine River Rd",
  90. "Bear right and head toward Lostine River Rd",
  91. "Turn right at Lostine River Rd",
  92. "Continue on NF-8210",
  93. "Turn right and head toward NF-8210",
  94. "Turn right at NF-8210",
  95. "",
  96. "Route"
  97. ]
  98. count = 0
  99. REXML::XPath.each( doc, "//Placemark") { |element|
  100. n = element.elements["name"].text.squeeze(" ")
  101. assert_equal( actual[count], n ) unless n =~ /Arrive at/
  102. count += 1
  103. }
  104. end if defined?(Zlib::GzipReader)
  105. end
  106. end