root / test / test_order.rb

Revision 549:e07d72733cae, 3.1 kB (checked in by Sean Russell <ser@…>, 5 months ago)

Moved and renamed files to conform to Ruby's test suite.

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