ruport 0.4.9 → 0.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/tc_state.rb DELETED
@@ -1,142 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- # tc_state.rb
4
- #
5
- # Created by James Edward Gray II on 2005-08-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
7
-
8
- require "test/unit"
9
-
10
- require "ruport/parser"
11
-
12
- class TestState < Test::Unit::TestCase
13
- def test_single_skips
14
- path = File.join(File.dirname(__FILE__), "samples/five_lines.txt")
15
- lines = File.readlines(path).values_at(0..2, 4)
16
- test = self
17
-
18
- Ruport::Parser.new(path) do
19
- skip(?u)
20
-
21
- read { |line| test.assert_equal(lines.shift, line) }
22
- end
23
- end
24
-
25
- def test_skipping_range
26
- path = File.join(File.dirname(__FILE__), "samples/five_lines.txt")
27
- lines = File.readlines(path).values_at(0, 3..4)
28
- test = self
29
-
30
- Ruport::Parser.new(path) do
31
- start_skipping_at("two")
32
- stop_skipping_at("three")
33
-
34
- read { |line| test.assert_equal(lines.shift, line) }
35
- end
36
- end
37
-
38
- def test_searching_skipped
39
- path = File.join(File.dirname(__FILE__), "samples/five_lines.txt")
40
-
41
- data = Ruport::Parser.new(path) do
42
- @state = :skip
43
- stop_skipping_at("four")
44
- find_in_skipped(/ou/) { |line| @found_in_skip = line }
45
-
46
- read { |line| (@lines ||= Array.new) << line }
47
- end
48
-
49
- assert_equal("This is line four.\n", data.found_in_skip)
50
- assert_equal(["This is line five.\n"], data.lines)
51
- end
52
-
53
- def test_stop
54
- path = File.join(File.dirname(__FILE__), "samples/five_lines.txt")
55
-
56
- data = Ruport::Parser.new(path) do
57
- stop_at("three")
58
-
59
- read { |line| @last_line = line }
60
- end
61
-
62
- assert_equal("This is line two.\n", data.last_line)
63
-
64
- data = Ruport::Parser.new(path) do
65
- read do |line|
66
- @last_line = line
67
-
68
- @state = :stop if @read.index("three")
69
- end
70
- end
71
-
72
- assert_equal("This is line three.\n", data.last_line)
73
- end
74
-
75
- def test_pre_and_post
76
- path = File.join(File.dirname(__FILE__), "samples/five_lines.txt")
77
-
78
- data = Ruport::Parser.new(path) do
79
- @pre = @post = 0
80
-
81
- pre do
82
- @pre += 1
83
- @post = 0
84
- end
85
- read { |line| (@lines ||= Array.new) << line }
86
- read(/\w+\./) { |number| (@numbers ||= Array.new) << number }
87
- post { @post += 1 }
88
- end
89
-
90
- assert_equal(5, data.pre)
91
- assert_equal(1, data.post)
92
- end
93
-
94
- def test_complex
95
- path = File.join(File.dirname(__FILE__), "samples/ross_report.txt")
96
- test = self
97
-
98
- Ruport::Parser.new(path) do
99
- @state = :skip
100
- start_skipping_at("\f")
101
- stop_skipping_at(/\A-[- ]+-\Z/)
102
- skip(/\A\s*\Z/)
103
- skip(/--\Z/)
104
-
105
- find_in_skipped(/((?:Period|Week)\s+\d.+?)\s*\Z/) do |period|
106
- test.assert_equal("Period 02/2002", period)
107
- end
108
-
109
- stop_at("*** Selection Criteria ***")
110
-
111
- read do |line|
112
- test.assert_match(/\A\s+(?:Sales|Cust|SA)|\A[-\w]+\s+/, line)
113
- end
114
- end
115
-
116
- path = File.join(File.dirname(__FILE__), "samples/car_ads.txt")
117
-
118
- data = Ruport::Parser.new(path, "") do
119
- @state = :skip
120
- stop_skipping_at("Save Ad")
121
- skip(/\A\s*\Z/)
122
-
123
- pre { @price = @miles = nil }
124
- read(/\$([\d,]+\d)/) { |price| @price = price.delete(",").to_i }
125
- read(/([\d,]*\d)\s*m/) { |miles| @miles = miles.delete(",").to_i }
126
-
127
- read do |ad|
128
- if @price and @price < 20_000 and @miles and @miles < 40_000
129
- (@ads ||= Array.new) << ad.strip
130
- end
131
- end
132
- end
133
-
134
- assert_equal([<<END_AD.strip], data.ads)
135
- 2003 Chrysler Town & Country LX
136
- $16,990, green, 21,488 mi, air, pw, power locks, ps, power mirrors,
137
- dual air bags, keyless entry, intermittent wipers, rear defroster, alloy,
138
- pb, abs, cruise, am/fm stereo, CD, cassette, tinted glass
139
- VIN:2C4GP44363R153238, Stock No:C153238, CALL DAN PERKINS AT 1-800-432-6326
140
- END_AD
141
- end
142
- end
data/test/ts_parser.rb DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- # ts_all.rb
4
- #
5
- # Created by James Edward Gray II on 2005-08-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
7
-
8
- require "test/unit"
9
- require "tc_reading"
10
- require "tc_state"