fit 1.1
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/README.txt +203 -0
- data/Rakefile +111 -0
- data/bin/FitServer.rb +6 -0
- data/bin/fit +10 -0
- data/bin/fit.cgi +36 -0
- data/doc/examples/AllCombinations.html +55 -0
- data/doc/examples/AllFiles.html +60 -0
- data/doc/examples/AllPairs/function/cosine.html +57 -0
- data/doc/examples/AllPairs/function/sine.html +57 -0
- data/doc/examples/AllPairs/magnitude/180+30.html +45 -0
- data/doc/examples/AllPairs/magnitude/30.html +33 -0
- data/doc/examples/AllPairs/magnitude/360+30.html +45 -0
- data/doc/examples/AllPairs/magnitude/90-30.html +45 -0
- data/doc/examples/AllPairs/sign/change-sign.html +27 -0
- data/doc/examples/AllPairs/sign/multiply.html +31 -0
- data/doc/examples/AllPairs/sign/no-change.html +23 -0
- data/doc/examples/AllPairs.html +51 -0
- data/doc/examples/BinaryChop.html +89 -0
- data/doc/examples/CalculatorExample.html +108 -0
- data/doc/examples/ColumnIndex.html +43 -0
- data/doc/examples/ExampleTests.html +43 -0
- data/doc/examples/FitAcceptanceTests.html +53 -0
- data/doc/examples/GeoCoordinate.html +87 -0
- data/doc/examples/MusicExample.html +143 -0
- data/doc/examples/MusicExampleWithErrors.html +128 -0
- data/doc/examples/NetworkExample.html +47 -0
- data/doc/examples/WebPageExample.html +92 -0
- data/doc/examples/arithmetic.html +211 -0
- data/doc/examples/files/hp35bk.jpg +0 -0
- data/doc/examples/logo.gif +0 -0
- data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.FixtureParameters.html +81 -0
- data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.GracefulFixtureNames.html +87 -0
- data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.GracefulMemberNames.html +73 -0
- data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.ImportFixture.html +61 -0
- data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.WaysToSpecifyaFixtureNamespace.html +81 -0
- data/doc/spec/annotation.html +3833 -0
- data/doc/spec/extensions.html +302 -0
- data/doc/spec/fixtures.html +5181 -0
- data/doc/spec/index.html +947 -0
- data/doc/spec/parse.html +3094 -0
- data/lib/eg/all_combinations.rb +44 -0
- data/lib/eg/all_files.rb +94 -0
- data/lib/eg/all_pairs.rb +172 -0
- data/lib/eg/arithmetic_column_fixture.rb +35 -0
- data/lib/eg/arithmetic_fixture.rb +29 -0
- data/lib/eg/binary_chop.rb +100 -0
- data/lib/eg/calculator.rb +69 -0
- data/lib/eg/column_index.rb +85 -0
- data/lib/eg/division.rb +13 -0
- data/lib/eg/echo_args_fixture.rb +9 -0
- data/lib/eg/example_tests.rb +84 -0
- data/lib/eg/music/Music.txt +38 -0
- data/lib/eg/music/browser.rb +60 -0
- data/lib/eg/music/display.rb +24 -0
- data/lib/eg/music/music.rb +67 -0
- data/lib/eg/music/music_library.rb +70 -0
- data/lib/eg/music/music_player.rb +77 -0
- data/lib/eg/music/realtime.rb +39 -0
- data/lib/eg/music/simulator.rb +81 -0
- data/lib/eg/nested/bob.rb +12 -0
- data/lib/eg/nested/bob_the_builder_fixture.rb +11 -0
- data/lib/eg/net/simulator.rb +69 -0
- data/lib/eg/page.rb +91 -0
- data/lib/eg/sqrt.rb +19 -0
- data/lib/fat/annotation_fixture.rb +83 -0
- data/lib/fat/color.rb +45 -0
- data/lib/fat/divide.rb +13 -0
- data/lib/fat/document_parse_fixture.rb +67 -0
- data/lib/fat/equals.rb +59 -0
- data/lib/fat/fixture_name_fixture.rb +67 -0
- data/lib/fat/html_to_text_fixture.rb +20 -0
- data/lib/fat/money.rb +18 -0
- data/lib/fat/output_fixture.rb +32 -0
- data/lib/fat/parse_fixture.rb +92 -0
- data/lib/fat/reference_fixture.rb +31 -0
- data/lib/fat/standard_annotation_fixture.rb +58 -0
- data/lib/fat/string_writer.rb +12 -0
- data/lib/fat/table.rb +23 -0
- data/lib/fat/table_parse_fixture.rb +33 -0
- data/lib/fat/text_to_html_fixture.rb +21 -0
- data/lib/fit/action_fixture.rb +65 -0
- data/lib/fit/column_fixture.rb +104 -0
- data/lib/fit/file_runner.rb +80 -0
- data/lib/fit/fit_protocol.rb +62 -0
- data/lib/fit/fit_server.rb +173 -0
- data/lib/fit/fixture.rb +309 -0
- data/lib/fit/fixture_loader.rb +75 -0
- data/lib/fit/import_fixture.rb +9 -0
- data/lib/fit/parse.rb +206 -0
- data/lib/fit/primitive_fixture.rb +52 -0
- data/lib/fit/row_fixture.rb +188 -0
- data/lib/fit/scientific_double.rb +70 -0
- data/lib/fit/summary.rb +46 -0
- data/lib/fit/timed_action_fixture.rb +35 -0
- data/lib/fit/type_adapter.rb +95 -0
- data/lib/fit/wiki_runner.rb +15 -0
- data/lib/fittask.rb +184 -0
- data/test/all_tests.rb +13 -0
- data/test/file_runner_test.rb +52 -0
- data/test/fit_server_test.rb +214 -0
- data/test/fixture_loader_test.rb +71 -0
- data/test/fixture_test.rb +41 -0
- data/test/fixtures/fail_fixture.rb +9 -0
- data/test/fixtures/pass_fixture.rb +9 -0
- data/test/framework_test.rb +51 -0
- data/test/parse_test.rb +101 -0
- data/test/row_fixture_test.rb +44 -0
- data/test/scientific_double_test.rb +35 -0
- data/test/type_adapter_test.rb +120 -0
- metadata +165 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Written by Object Mentor, Inc. 2005
|
|
2
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
3
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
4
|
+
|
|
5
|
+
# Make the test run location independent
|
|
6
|
+
$:.unshift File.dirname(__FILE__)
|
|
7
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
8
|
+
|
|
9
|
+
require 'test/unit'
|
|
10
|
+
require 'socket'
|
|
11
|
+
require 'fit/fit_server'
|
|
12
|
+
|
|
13
|
+
module Fit
|
|
14
|
+
class FitServerTest < Test::Unit::TestCase
|
|
15
|
+
|
|
16
|
+
def setup
|
|
17
|
+
@fit_server = FitServer.new
|
|
18
|
+
@read_end_of_pipe, @write_end_of_pipe = IO.pipe
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def teardown
|
|
22
|
+
@session.close if @session != nil
|
|
23
|
+
@server.close if @server != nil
|
|
24
|
+
@server_thread.kill if @server_thread != nil and @server_thread.alive?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_args
|
|
28
|
+
success = @fit_server.args(['localhost', '80', '123'])
|
|
29
|
+
assert(success);
|
|
30
|
+
check_standard_fit_server_parameters
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_args_with_verbose
|
|
34
|
+
success = @fit_server.args(['-v', 'localhost', '80', '123'])
|
|
35
|
+
assert(success)
|
|
36
|
+
assert(@fit_server.verbose)
|
|
37
|
+
check_standard_fit_server_parameters
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_bad_args
|
|
41
|
+
assert(! @fit_server.args(['-x', 'localhost', '80', '123']))
|
|
42
|
+
assert(! @fit_server.args(['-x', 'localhost', '80']))
|
|
43
|
+
assert(! @fit_server.args(['localhost', '80', '123', 'blah']))
|
|
44
|
+
assert(! @fit_server.args(['localhost', 'abc', '123']))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def check_standard_fit_server_parameters
|
|
48
|
+
assert_equal('localhost', @fit_server.host)
|
|
49
|
+
assert_equal(80, @fit_server.port)
|
|
50
|
+
assert_equal('123', @fit_server.test_ticket)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_build_request
|
|
54
|
+
@fit_server.test_ticket = "12345"
|
|
55
|
+
expected_request = "GET /?responder=socketCatcher&ticket=12345 HTTP/1.1\r\n\r\n"
|
|
56
|
+
assert_equal(expected_request, @fit_server.build_request)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_read_size
|
|
60
|
+
@write_end_of_pipe.print("0000000000")
|
|
61
|
+
assert_equal(0, FitProtocol.read_size(@read_end_of_pipe))
|
|
62
|
+
@write_end_of_pipe.print("0000000001")
|
|
63
|
+
assert_equal(1, FitProtocol.read_size(@read_end_of_pipe))
|
|
64
|
+
@write_end_of_pipe.print("00000123450000000021")
|
|
65
|
+
assert_equal(12345, FitProtocol.read_size(@read_end_of_pipe))
|
|
66
|
+
assert_equal(21, FitProtocol.read_size(@read_end_of_pipe))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_establish_connection
|
|
70
|
+
startSession do
|
|
71
|
+
@session.print('0000000000')
|
|
72
|
+
@session.flush
|
|
73
|
+
end
|
|
74
|
+
@fit_server.establish_connection()
|
|
75
|
+
assert(@fit_server.good_connection?)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_validate_connection
|
|
79
|
+
message = "This would normally be an error message"
|
|
80
|
+
message_length = '00000000' + message.length.to_s
|
|
81
|
+
startSession do
|
|
82
|
+
@session.print(message_length)
|
|
83
|
+
@session.print(message)
|
|
84
|
+
@session.flush
|
|
85
|
+
end
|
|
86
|
+
@fit_server.establish_connection()
|
|
87
|
+
assert(! @fit_server.good_connection?)
|
|
88
|
+
assert_equal(message, @fit_server.reason_for_bad_connection)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_run_one_passing_table
|
|
92
|
+
startSession do
|
|
93
|
+
FitProtocol.write_size(0, @session)
|
|
94
|
+
FitProtocol.write_document(passing_table, @session)
|
|
95
|
+
FitProtocol.write_size(0, @session)
|
|
96
|
+
end
|
|
97
|
+
@fit_server.establish_connection()
|
|
98
|
+
@fit_server.process()
|
|
99
|
+
results = FitProtocol.read_document(@session)
|
|
100
|
+
FitProtocol.read_size(@session)
|
|
101
|
+
counts = FitProtocol.read_counts(@session)
|
|
102
|
+
assert_not_nil(results.index("<td bgcolor=\"#cfffcf\">"), results)
|
|
103
|
+
check_counts(counts, 1, 0, 0, 0)
|
|
104
|
+
assert_equal(0, @fit_server.exit_code)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_run_one_failing_table
|
|
108
|
+
startSession do
|
|
109
|
+
FitProtocol.write_size(0, @session)
|
|
110
|
+
FitProtocol.write_document(failing_table, @session)
|
|
111
|
+
FitProtocol.write_size(0, @session)
|
|
112
|
+
end
|
|
113
|
+
@fit_server.establish_connection()
|
|
114
|
+
@fit_server.process()
|
|
115
|
+
results = FitProtocol.read_document(@session)
|
|
116
|
+
FitProtocol.read_size(@session)
|
|
117
|
+
counts = FitProtocol.read_counts(@session)
|
|
118
|
+
assert_not_nil(results.index("<td bgcolor=\"#ffcfcf\">"), results)
|
|
119
|
+
check_counts(counts, 0, 1, 0, 0)
|
|
120
|
+
assert_equal(1, @fit_server.exit_code)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_two_tables_in_one_document
|
|
124
|
+
startSession do
|
|
125
|
+
FitProtocol.write_size(0, @session)
|
|
126
|
+
FitProtocol.write_document(passing_table + "\n" + failing_table, @session)
|
|
127
|
+
FitProtocol.write_size(0, @session)
|
|
128
|
+
end
|
|
129
|
+
@fit_server.establish_connection()
|
|
130
|
+
@fit_server.process()
|
|
131
|
+
passing_results = FitProtocol.read_document(@session)
|
|
132
|
+
failing_results = FitProtocol.read_document(@session)
|
|
133
|
+
FitProtocol.read_size(@session)
|
|
134
|
+
counts = FitProtocol.read_counts(@session)
|
|
135
|
+
assert_not_nil(passing_results.index("<td bgcolor=\"#cfffcf\">"), passing_results)
|
|
136
|
+
assert_nil(passing_results.index("FailFixture"), "Shouldn't have second table in output")
|
|
137
|
+
assert_not_nil(failing_results.index("<td bgcolor=\"#ffcfcf\">"), failing_results)
|
|
138
|
+
check_counts(counts, 1, 1, 0, 0)
|
|
139
|
+
assert_equal(1, @fit_server.exit_code)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_processing_two_documents
|
|
143
|
+
startSession do
|
|
144
|
+
FitProtocol.write_size(0, @session)
|
|
145
|
+
FitProtocol.write_document(passing_table, @session)
|
|
146
|
+
FitProtocol.write_document(failing_table, @session)
|
|
147
|
+
FitProtocol.write_size(0, @session)
|
|
148
|
+
end
|
|
149
|
+
@fit_server.establish_connection()
|
|
150
|
+
@fit_server.process()
|
|
151
|
+
passing_results = FitProtocol.read_document(@session)
|
|
152
|
+
FitProtocol.read_size(@session)
|
|
153
|
+
passingCounts = FitProtocol.read_counts(@session)
|
|
154
|
+
failing_results = FitProtocol.read_document(@session)
|
|
155
|
+
FitProtocol.read_size(@session)
|
|
156
|
+
failingCounts = FitProtocol.read_counts(@session)
|
|
157
|
+
assert_not_nil(passing_results.index("<td bgcolor=\"#cfffcf\">"), passing_results)
|
|
158
|
+
assert_not_nil(failing_results.index("<td bgcolor=\"#ffcfcf\">"), failing_results)
|
|
159
|
+
check_counts(passingCounts, 1, 0, 0, 0)
|
|
160
|
+
check_counts(failingCounts, 0, 1, 0, 0)
|
|
161
|
+
assert_equal(1, @fit_server.exit_code)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def test_non_test_input
|
|
165
|
+
startSession do
|
|
166
|
+
FitProtocol.write_size(0, @session)
|
|
167
|
+
FitProtocol.write_document("Hey! There's no table here!'", @session)
|
|
168
|
+
FitProtocol.write_size(0, @session)
|
|
169
|
+
end
|
|
170
|
+
@fit_server.establish_connection()
|
|
171
|
+
@fit_server.process()
|
|
172
|
+
results = FitProtocol.read_document(@session)
|
|
173
|
+
FitProtocol.read_size(@session)
|
|
174
|
+
counts = FitProtocol.read_counts(@session)
|
|
175
|
+
assert_not_nil(results.index("Exception"))
|
|
176
|
+
assert_not_nil(results.index("Can't find tag: table"))
|
|
177
|
+
check_counts(counts, 0, 0, 0, 1)
|
|
178
|
+
assert_equal(1, @fit_server.exit_code)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def check_counts (counts, right, wrong, ignores, exceptions)
|
|
182
|
+
assert_equal(right, counts.right, "rights wrong")
|
|
183
|
+
assert_equal(wrong, counts.wrong, "wrongs wrong")
|
|
184
|
+
assert_equal(ignores, counts.ignores, "ignores wrong")
|
|
185
|
+
assert_equal(exceptions, counts.exceptions, "exceptions wrong")
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def startSession (&connectionAction)
|
|
189
|
+
@fit_server.args(['localhost', '9002', '123'])
|
|
190
|
+
@server_thread = Thread.new do
|
|
191
|
+
begin
|
|
192
|
+
@server = TCPServer.new('localhost', 9002)
|
|
193
|
+
@session = @server.accept
|
|
194
|
+
request = @session.readline
|
|
195
|
+
@session.readline
|
|
196
|
+
rescue => e
|
|
197
|
+
puts e
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
yield connectionAction
|
|
201
|
+
end
|
|
202
|
+
sleep(0.1)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def passing_table
|
|
206
|
+
return "<table><tr><td>fixtures::PassFixture</td></tr></table>"
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def failing_table
|
|
210
|
+
return "<table><tr><td>fixtures::FailFixture</td></tr></table>"
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
2
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
|
|
6
|
+
# Make the test run location independent
|
|
7
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
8
|
+
|
|
9
|
+
require 'fit/fixture_loader'
|
|
10
|
+
require 'fit/import_fixture'
|
|
11
|
+
require 'eg/division'
|
|
12
|
+
require 'eg/all_files'
|
|
13
|
+
require 'eg/nested/bob_the_builder_fixture'
|
|
14
|
+
require 'eg/music/browser'
|
|
15
|
+
|
|
16
|
+
module Fit
|
|
17
|
+
class FixtureLoaderTest < Test::Unit::TestCase
|
|
18
|
+
def setup
|
|
19
|
+
@loader = FixtureLoader.new
|
|
20
|
+
end
|
|
21
|
+
def test_you_can_load_a_fixture
|
|
22
|
+
assert_instance_of(Eg::Division, @loader.load('Eg.Division'))
|
|
23
|
+
end
|
|
24
|
+
def test_java_simple_fixture
|
|
25
|
+
assert_instance_of(Eg::AllFiles, @loader.load('eg.AllFiles'))
|
|
26
|
+
end
|
|
27
|
+
def test_java_nested_fixture
|
|
28
|
+
assert_instance_of(Eg::AllFiles::Expand, @loader.load('eg.AllFiles$Expand'))
|
|
29
|
+
end
|
|
30
|
+
def test_you_can_load_a_fixture_with_colons_rather_than_dots
|
|
31
|
+
assert_instance_of(Eg::Nested::BobTheBuilderFixture, @loader.load('Eg::Nested::BobTheBuilderFixture'))
|
|
32
|
+
end
|
|
33
|
+
class LookImNotInTheRightPlace < Fixture
|
|
34
|
+
end
|
|
35
|
+
def test_you_can_load_any_fixture_already_loaded_regardless_of_path
|
|
36
|
+
assert_instance_of(Fit::FixtureLoaderTest::LookImNotInTheRightPlace,
|
|
37
|
+
@loader.load('Fit.FixtureLoaderTest.LookImNotInTheRightPlace'))
|
|
38
|
+
end
|
|
39
|
+
def test_you_can_add_fixture_packages
|
|
40
|
+
FixtureLoader.add_fixture_package('Eg::Music')
|
|
41
|
+
assert_instance_of(Eg::Music::Browser, @loader.load('Browser'))
|
|
42
|
+
end
|
|
43
|
+
def test_it_finds_fixtures_in_the_fit_module
|
|
44
|
+
assert_instance_of(Fit::ImportFixture, @loader.load('ImportFixture'))
|
|
45
|
+
end
|
|
46
|
+
def test_it_adds_fixture_to_the_end_if_it_cant_find_the_class
|
|
47
|
+
assert_instance_of(Fit::ImportFixture, @loader.load('Import'))
|
|
48
|
+
end
|
|
49
|
+
def test_it_camalizes_seperated_words
|
|
50
|
+
FixtureLoader.add_fixture_package('Eg::Nested')
|
|
51
|
+
assert_instance_of(Eg::Nested::BobTheBuilderFixture, @loader.load('bob the builder fixture'))
|
|
52
|
+
assert_instance_of(Eg::Nested::BobTheBuilderFixture, @loader.load('bob the builder'))
|
|
53
|
+
end
|
|
54
|
+
def test_punctuation_seperates_words
|
|
55
|
+
FixtureLoader.add_fixture_package('Eg::Nested')
|
|
56
|
+
assert_instance_of(Eg::Nested::BobTheBuilderFixture, @loader.load('bob_the!-builder,fixture.'))
|
|
57
|
+
assert_instance_of(Eg::Nested::BobTheBuilderFixture, @loader.load('bob_the!-builder.'))
|
|
58
|
+
end
|
|
59
|
+
def test_it_raises_when_it_cant_find_the_fixture
|
|
60
|
+
@loader.load "NoSuchClass"
|
|
61
|
+
rescue StandardError => e
|
|
62
|
+
assert_equal("Fixture NoSuchClass not found.", e.to_s)
|
|
63
|
+
end
|
|
64
|
+
def test_it_only_loads_fixtures
|
|
65
|
+
@loader.load "String"
|
|
66
|
+
flunk("Should have thrown.")
|
|
67
|
+
rescue StandardError => e
|
|
68
|
+
assert_equal("String is not a fixture.", e.to_s)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
2
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
# Make the test run location independent
|
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
|
+
require 'fit/fixture'
|
|
8
|
+
require 'fit/parse'
|
|
9
|
+
|
|
10
|
+
module Fit
|
|
11
|
+
|
|
12
|
+
class FixtureTest < Test::Unit::TestCase
|
|
13
|
+
def test_escape
|
|
14
|
+
junk = "!@$%^*()_-+={}|[]\\:\";',./?`#"
|
|
15
|
+
assert_equal junk, Fixture.escape(junk)
|
|
16
|
+
|
|
17
|
+
assert_equal ' ', Fixture.escape(' ')
|
|
18
|
+
assert_equal '', Fixture.escape('')
|
|
19
|
+
assert_equal '<', Fixture.escape('<')
|
|
20
|
+
assert_equal '<<', Fixture.escape('<<')
|
|
21
|
+
assert_equal 'x<', Fixture.escape('x<')
|
|
22
|
+
assert_equal '&', Fixture.escape('&')
|
|
23
|
+
assert_equal '<&<', Fixture.escape('<&<')
|
|
24
|
+
assert_equal '&<&', Fixture.escape('&<&')
|
|
25
|
+
assert_equal 'a < b && c < d', Fixture.escape('a < b && c < d')
|
|
26
|
+
assert_equal 'a<br />b', Fixture.escape("a\nb")
|
|
27
|
+
end
|
|
28
|
+
class ArgsFixture < Fit::Fixture
|
|
29
|
+
@@args = nil
|
|
30
|
+
def do_table table
|
|
31
|
+
@@args = @args
|
|
32
|
+
end
|
|
33
|
+
def self.args; @@args; end
|
|
34
|
+
end
|
|
35
|
+
def test_it_passes_parameters
|
|
36
|
+
p = Parse.new '<table><tr><td>Fit.FixtureTest.ArgsFixture</td><td>a</td><td>b</td></tr></table>'
|
|
37
|
+
Fixture.new.do_tables p
|
|
38
|
+
assert_equal ['a', 'b'], ArgsFixture.args
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
2
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
# Make the test run location independent
|
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
|
+
require 'fit/fixture'
|
|
8
|
+
require 'fit/parse'
|
|
9
|
+
|
|
10
|
+
module Fit
|
|
11
|
+
|
|
12
|
+
class FrameworkTest < Test::Unit::TestCase
|
|
13
|
+
def test_runs
|
|
14
|
+
# The original Java version for the arithmetic fixture led to
|
|
15
|
+
# 37, 10, 0, 2 as results, but Ruby handles maths differently.
|
|
16
|
+
# Using a more strict delta in Fit::TypeAdapter could lead to
|
|
17
|
+
# worse results on the Ruby front.
|
|
18
|
+
run_page 'arithmetic', 39, 8, 0, 2
|
|
19
|
+
run_page 'BinaryChop', 95, 0, 0, 0
|
|
20
|
+
run_page 'CalculatorExample', 75, 9, 0, 0
|
|
21
|
+
run_page 'MusicExample', 95, 0, 0, 0
|
|
22
|
+
run_page 'MusicExampleWithErrors', 54, 10, 0, 0
|
|
23
|
+
run_page 'NetworkExample', 5, 0, 0, 0
|
|
24
|
+
# run_page 'SimpleExample', 5, 0, 0, 0
|
|
25
|
+
end
|
|
26
|
+
def run_page file, right, wrong, ignores, exceptions
|
|
27
|
+
input = File.open("../../examples/#{file}.html") {|f| f.read}
|
|
28
|
+
fixture = Fixture.new
|
|
29
|
+
tables = nil
|
|
30
|
+
unless input.index('<wiki>').nil?
|
|
31
|
+
tables = Parse.new input, ['wiki', 'table', 'tr', 'td']
|
|
32
|
+
fixture.do_tables tables.parts
|
|
33
|
+
else
|
|
34
|
+
tables = Parse.new input, ['table', 'tr', 'td']
|
|
35
|
+
fixture.do_tables tables
|
|
36
|
+
end
|
|
37
|
+
tables.print OutputStream.new
|
|
38
|
+
|
|
39
|
+
assert_equal right, fixture.counts.right, "#{file} right"
|
|
40
|
+
assert_equal wrong, fixture.counts.wrong, "#{file} wrong"
|
|
41
|
+
assert_equal ignores, fixture.counts.ignores, "#{file} ignores"
|
|
42
|
+
assert_equal exceptions, fixture.counts.exceptions, "#{file} exceptions"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# A dummy output stream to avoid creating output files
|
|
47
|
+
class OutputStream < String
|
|
48
|
+
def print text; end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
data/test/parse_test.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
2
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
# Make the test run location independent
|
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
|
+
require 'fit/parse'
|
|
8
|
+
|
|
9
|
+
module Fit
|
|
10
|
+
|
|
11
|
+
class ParseTest < Test::Unit::TestCase
|
|
12
|
+
def test_parsing
|
|
13
|
+
p = Parse.new 'leader<Table foo=2>body</table>trailer', ['table']
|
|
14
|
+
assert_equal 'leader', p.leader
|
|
15
|
+
assert_equal '<Table foo=2>', p.tag
|
|
16
|
+
assert_equal 'body', p.body
|
|
17
|
+
assert_equal 'trailer', p.trailer
|
|
18
|
+
end
|
|
19
|
+
def test_recursing
|
|
20
|
+
p = Parse.new 'leader<table><TR><Td>body</tD></TR></table>trailer'
|
|
21
|
+
assert_nil p.body
|
|
22
|
+
assert_nil p.parts.body
|
|
23
|
+
assert_equal 'body', p.parts.parts.body
|
|
24
|
+
end
|
|
25
|
+
def test_iterating
|
|
26
|
+
p = Parse.new 'leader<table><tr><td>one</td><td>two</td><td>three</td></tr></table>trailer'
|
|
27
|
+
assert_equal 'one', p.parts.parts.body
|
|
28
|
+
assert_equal 'two', p.parts.parts.more.body
|
|
29
|
+
assert_equal 'three', p.parts.parts.more.more.body
|
|
30
|
+
end
|
|
31
|
+
def test_indexing
|
|
32
|
+
p = Parse.new 'leader<table><tr><td>one</td><td>two</td><td>three</td></tr><tr><td>four</td></tr></table>trailer'
|
|
33
|
+
assert_equal 'one', p.at(0, 0, 0).body
|
|
34
|
+
assert_equal 'two', p.at(0,0,1).body
|
|
35
|
+
assert_equal 'three', p.at(0,0,2).body
|
|
36
|
+
assert_equal 'three', p.at(0,0,3).body
|
|
37
|
+
assert_equal 'three', p.at(0,0,4).body
|
|
38
|
+
assert_equal 'four', p.at(0,1,0).body
|
|
39
|
+
assert_equal 'four', p.at(0,1,1).body
|
|
40
|
+
assert_equal 'four', p.at(0,2,0).body
|
|
41
|
+
assert_equal 1, p.size()
|
|
42
|
+
assert_equal 2, p.parts.size()
|
|
43
|
+
assert_equal 3, p.parts.parts.size()
|
|
44
|
+
assert_equal 'one', p.leaf().body
|
|
45
|
+
assert_equal 'four', p.parts.last().leaf().body
|
|
46
|
+
end
|
|
47
|
+
def test_parse_exception
|
|
48
|
+
begin
|
|
49
|
+
p = Parse.new 'leader<table><tr><th>one</th><th>two</th><th>three</th></tr><tr><td>four</td></tr></table>trailer'
|
|
50
|
+
fail 'Expected ParseException not thrown.'
|
|
51
|
+
rescue ParseException => e
|
|
52
|
+
assert_equal 17, e.error_offset
|
|
53
|
+
assert_equal "Can't find tag: td", e.message
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
def test_text
|
|
57
|
+
tags = ['td']
|
|
58
|
+
p = Parse.new '<td>a<b</td>', tags
|
|
59
|
+
assert_equal 'a<b', p.body
|
|
60
|
+
assert_equal 'a<b', p.text
|
|
61
|
+
p = Parse.new "<td>\ta>b & b>c &&<</td>", tags
|
|
62
|
+
assert_equal 'a>b & b>c &&<', p.text
|
|
63
|
+
p = Parse.new "<td>\ta>b & b>c &<</td>", tags
|
|
64
|
+
assert_equal 'a>b & b>c &<', p.text
|
|
65
|
+
p = Parse.new '<TD><P><FONT FACE="Arial" SIZE=2>GroupTestFixture</FONT></TD>', tags
|
|
66
|
+
assert_equal 'GroupTestFixture', p.text()
|
|
67
|
+
end
|
|
68
|
+
def test_html_to_text
|
|
69
|
+
assert_equal '', Parse.html_to_text(' ')
|
|
70
|
+
assert_equal 'a b', Parse.html_to_text('a <tag /> b')
|
|
71
|
+
assert_equal 'a', Parse.html_to_text('a ')
|
|
72
|
+
assert_equal ' ', Parse.html_to_text('&nbsp;')
|
|
73
|
+
assert_equal '1 2', Parse.html_to_text('1 2')
|
|
74
|
+
assert_equal '1 2', Parse.html_to_text("1 \xa0\xa0\xa0\xa02")
|
|
75
|
+
assert_equal 'a', Parse.html_to_text(' <tag />a')
|
|
76
|
+
assert_equal "a\nb", Parse.html_to_text('a<br />b')
|
|
77
|
+
assert_equal 'ab', Parse.html_to_text('<font size=+1>a</font>b')
|
|
78
|
+
assert_equal 'ab', Parse.html_to_text('a<font size=+1>b</font>')
|
|
79
|
+
assert_equal 'a<b', Parse.html_to_text('a<b')
|
|
80
|
+
assert_equal "a\nb\nc\nd", Parse.html_to_text('a<br>b<br/>c< br / >d')
|
|
81
|
+
assert_equal "a\nb", Parse.html_to_text('a</p><p>b')
|
|
82
|
+
assert_equal "a\nb", Parse.html_to_text('a< / p > < p >b')
|
|
83
|
+
end
|
|
84
|
+
def test_unescape
|
|
85
|
+
assert_equal 'a<b', Parse.unescape('a<b')
|
|
86
|
+
assert_equal 'a>b & b>c &&', Parse.unescape('a>b & b>c &&')
|
|
87
|
+
assert_equal '&&', Parse.unescape('&amp;&amp;')
|
|
88
|
+
assert_equal 'a>b & b>c &&', Parse.unescape('a>b & b>c &&')
|
|
89
|
+
assert_equal "'\"\"'", Parse.unescape("\221��\222")
|
|
90
|
+
end
|
|
91
|
+
def test_whitespace_is_condensed
|
|
92
|
+
assert_equal 'a b', Parse.condense_whitespace(' a b ')
|
|
93
|
+
assert_equal 'a b', Parse.condense_whitespace(" a \n\tb ")
|
|
94
|
+
assert_equal '', Parse.condense_whitespace(' ')
|
|
95
|
+
assert_equal '', Parse.condense_whitespace(' ')
|
|
96
|
+
assert_equal '', Parse.condense_whitespace(' ')
|
|
97
|
+
assert_equal '', Parse.condense_whitespace("\240")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
2
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
# Make the test run location independent
|
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
|
+
require 'fit/row_fixture'
|
|
8
|
+
|
|
9
|
+
module Fit
|
|
10
|
+
|
|
11
|
+
class RowFixtureTest < Test::Unit::TestCase
|
|
12
|
+
|
|
13
|
+
def test_match
|
|
14
|
+
fixture = TestRowFixture.new
|
|
15
|
+
adapter = TypeAdapter.for(fixture, 'get_strings', false)
|
|
16
|
+
fixture.column_bindings = [adapter]
|
|
17
|
+
computed = [BusinessObject.new(["1"])]
|
|
18
|
+
expected = [ParseHolder.create('tr', '', ParseHolder.create('td', '1', nil, nil), nil)]
|
|
19
|
+
fixture.match expected, computed, 0
|
|
20
|
+
|
|
21
|
+
puts fixture.counts.to_s # 0, 0, 0, 0 (!!!)
|
|
22
|
+
puts fixture.missing.size # 1
|
|
23
|
+
puts fixture.surplus.size # 1
|
|
24
|
+
assert_equal 1, fixture.counts.right, 'right'
|
|
25
|
+
assert_equal 0, fixture.counts.exceptions, 'exceptions'
|
|
26
|
+
assert_equal 0, fixture.missing.size, 'missing'
|
|
27
|
+
assert_equal 0, fixture.surplus.size, 'surplus'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class BusinessObject
|
|
31
|
+
def initialize strings
|
|
32
|
+
@strings = strings
|
|
33
|
+
end
|
|
34
|
+
def get_strings
|
|
35
|
+
@strings
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class TestRowFixture < RowFixture
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
|
|
2
|
+
# Released under the terms of the GNU General Public License version 2 or later.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
# Make the test run location independent
|
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
|
+
require 'fit/scientific_double'
|
|
8
|
+
|
|
9
|
+
module Fit
|
|
10
|
+
|
|
11
|
+
class ScientificDoubleTest < Test::Unit::TestCase
|
|
12
|
+
def test_pi_number
|
|
13
|
+
pi = 3.141592653
|
|
14
|
+
assert_equal pi, ScientificDouble.value_of('3.14')
|
|
15
|
+
assert_equal pi, ScientificDouble.value_of('3.142')
|
|
16
|
+
assert_equal pi, ScientificDouble.value_of('3.1416')
|
|
17
|
+
assert_equal pi, ScientificDouble.value_of('3.14159')
|
|
18
|
+
assert_equal pi, ScientificDouble.value_of('3.141592653')
|
|
19
|
+
|
|
20
|
+
assert_not_equal pi, ScientificDouble.value_of('3.140')
|
|
21
|
+
assert_not_equal pi, ScientificDouble.value_of('3.144')
|
|
22
|
+
assert_not_equal pi, ScientificDouble.value_of('3.1414')
|
|
23
|
+
assert_not_equal pi, ScientificDouble.value_of('3.141492651')
|
|
24
|
+
end
|
|
25
|
+
def test_avogadro_number
|
|
26
|
+
assert_equal 6.02e23, ScientificDouble.value_of('6.02e23')
|
|
27
|
+
assert_equal 6.024E23, ScientificDouble.value_of('6.02E23')
|
|
28
|
+
assert_equal 6.016e23, ScientificDouble.value_of('6.02e23')
|
|
29
|
+
|
|
30
|
+
assert_not_equal 6.026e23, ScientificDouble.value_of('6.02e23')
|
|
31
|
+
assert_not_equal 6.014e23, ScientificDouble.value_of('6.02e23')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|