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.
Files changed (110) hide show
  1. data/README.txt +203 -0
  2. data/Rakefile +111 -0
  3. data/bin/FitServer.rb +6 -0
  4. data/bin/fit +10 -0
  5. data/bin/fit.cgi +36 -0
  6. data/doc/examples/AllCombinations.html +55 -0
  7. data/doc/examples/AllFiles.html +60 -0
  8. data/doc/examples/AllPairs/function/cosine.html +57 -0
  9. data/doc/examples/AllPairs/function/sine.html +57 -0
  10. data/doc/examples/AllPairs/magnitude/180+30.html +45 -0
  11. data/doc/examples/AllPairs/magnitude/30.html +33 -0
  12. data/doc/examples/AllPairs/magnitude/360+30.html +45 -0
  13. data/doc/examples/AllPairs/magnitude/90-30.html +45 -0
  14. data/doc/examples/AllPairs/sign/change-sign.html +27 -0
  15. data/doc/examples/AllPairs/sign/multiply.html +31 -0
  16. data/doc/examples/AllPairs/sign/no-change.html +23 -0
  17. data/doc/examples/AllPairs.html +51 -0
  18. data/doc/examples/BinaryChop.html +89 -0
  19. data/doc/examples/CalculatorExample.html +108 -0
  20. data/doc/examples/ColumnIndex.html +43 -0
  21. data/doc/examples/ExampleTests.html +43 -0
  22. data/doc/examples/FitAcceptanceTests.html +53 -0
  23. data/doc/examples/GeoCoordinate.html +87 -0
  24. data/doc/examples/MusicExample.html +143 -0
  25. data/doc/examples/MusicExampleWithErrors.html +128 -0
  26. data/doc/examples/NetworkExample.html +47 -0
  27. data/doc/examples/WebPageExample.html +92 -0
  28. data/doc/examples/arithmetic.html +211 -0
  29. data/doc/examples/files/hp35bk.jpg +0 -0
  30. data/doc/examples/logo.gif +0 -0
  31. data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.FixtureParameters.html +81 -0
  32. data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.GracefulFixtureNames.html +87 -0
  33. data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.GracefulMemberNames.html +73 -0
  34. data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.ImportFixture.html +61 -0
  35. data/doc/fitnesse/FitNesse.RubY.AcceptanceTests.WaysToSpecifyaFixtureNamespace.html +81 -0
  36. data/doc/spec/annotation.html +3833 -0
  37. data/doc/spec/extensions.html +302 -0
  38. data/doc/spec/fixtures.html +5181 -0
  39. data/doc/spec/index.html +947 -0
  40. data/doc/spec/parse.html +3094 -0
  41. data/lib/eg/all_combinations.rb +44 -0
  42. data/lib/eg/all_files.rb +94 -0
  43. data/lib/eg/all_pairs.rb +172 -0
  44. data/lib/eg/arithmetic_column_fixture.rb +35 -0
  45. data/lib/eg/arithmetic_fixture.rb +29 -0
  46. data/lib/eg/binary_chop.rb +100 -0
  47. data/lib/eg/calculator.rb +69 -0
  48. data/lib/eg/column_index.rb +85 -0
  49. data/lib/eg/division.rb +13 -0
  50. data/lib/eg/echo_args_fixture.rb +9 -0
  51. data/lib/eg/example_tests.rb +84 -0
  52. data/lib/eg/music/Music.txt +38 -0
  53. data/lib/eg/music/browser.rb +60 -0
  54. data/lib/eg/music/display.rb +24 -0
  55. data/lib/eg/music/music.rb +67 -0
  56. data/lib/eg/music/music_library.rb +70 -0
  57. data/lib/eg/music/music_player.rb +77 -0
  58. data/lib/eg/music/realtime.rb +39 -0
  59. data/lib/eg/music/simulator.rb +81 -0
  60. data/lib/eg/nested/bob.rb +12 -0
  61. data/lib/eg/nested/bob_the_builder_fixture.rb +11 -0
  62. data/lib/eg/net/simulator.rb +69 -0
  63. data/lib/eg/page.rb +91 -0
  64. data/lib/eg/sqrt.rb +19 -0
  65. data/lib/fat/annotation_fixture.rb +83 -0
  66. data/lib/fat/color.rb +45 -0
  67. data/lib/fat/divide.rb +13 -0
  68. data/lib/fat/document_parse_fixture.rb +67 -0
  69. data/lib/fat/equals.rb +59 -0
  70. data/lib/fat/fixture_name_fixture.rb +67 -0
  71. data/lib/fat/html_to_text_fixture.rb +20 -0
  72. data/lib/fat/money.rb +18 -0
  73. data/lib/fat/output_fixture.rb +32 -0
  74. data/lib/fat/parse_fixture.rb +92 -0
  75. data/lib/fat/reference_fixture.rb +31 -0
  76. data/lib/fat/standard_annotation_fixture.rb +58 -0
  77. data/lib/fat/string_writer.rb +12 -0
  78. data/lib/fat/table.rb +23 -0
  79. data/lib/fat/table_parse_fixture.rb +33 -0
  80. data/lib/fat/text_to_html_fixture.rb +21 -0
  81. data/lib/fit/action_fixture.rb +65 -0
  82. data/lib/fit/column_fixture.rb +104 -0
  83. data/lib/fit/file_runner.rb +80 -0
  84. data/lib/fit/fit_protocol.rb +62 -0
  85. data/lib/fit/fit_server.rb +173 -0
  86. data/lib/fit/fixture.rb +309 -0
  87. data/lib/fit/fixture_loader.rb +75 -0
  88. data/lib/fit/import_fixture.rb +9 -0
  89. data/lib/fit/parse.rb +206 -0
  90. data/lib/fit/primitive_fixture.rb +52 -0
  91. data/lib/fit/row_fixture.rb +188 -0
  92. data/lib/fit/scientific_double.rb +70 -0
  93. data/lib/fit/summary.rb +46 -0
  94. data/lib/fit/timed_action_fixture.rb +35 -0
  95. data/lib/fit/type_adapter.rb +95 -0
  96. data/lib/fit/wiki_runner.rb +15 -0
  97. data/lib/fittask.rb +184 -0
  98. data/test/all_tests.rb +13 -0
  99. data/test/file_runner_test.rb +52 -0
  100. data/test/fit_server_test.rb +214 -0
  101. data/test/fixture_loader_test.rb +71 -0
  102. data/test/fixture_test.rb +41 -0
  103. data/test/fixtures/fail_fixture.rb +9 -0
  104. data/test/fixtures/pass_fixture.rb +9 -0
  105. data/test/framework_test.rb +51 -0
  106. data/test/parse_test.rb +101 -0
  107. data/test/row_fixture_test.rb +44 -0
  108. data/test/scientific_double_test.rb +35 -0
  109. data/test/type_adapter_test.rb +120 -0
  110. metadata +165 -0
data/lib/eg/page.rb ADDED
@@ -0,0 +1,91 @@
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 'fit/parse'
5
+ require 'fit/row_fixture'
6
+
7
+ require 'open-uri'
8
+ require 'uri'
9
+
10
+ module Eg
11
+
12
+ class Page < Fit::RowFixture
13
+
14
+ @@url = nil
15
+ @@text = ''
16
+
17
+ # Actions
18
+
19
+ def location url
20
+ @@url = URI.parse url
21
+ @@text = open(@@url) {|stream| stream.read}
22
+ end
23
+
24
+ def title
25
+ Fit::Parse.new(@@text, ['title']).text
26
+ end
27
+
28
+ def link label
29
+ links = Fit::Parse.new @@text, ['a']
30
+ until links.text =~ /^#{label}/
31
+ links = links.more
32
+ end
33
+ links.tag =~ /href\s*=\s*"(.*)"\s*>?/i
34
+ if $1.nil?
35
+ links.tag =~ /href\s*=\s*(.*)\s*>/i
36
+ end
37
+ link = $1
38
+ if link =~ /^(http:)?\/\//
39
+ @@url = URI.parse($1.nil? ? "http:#{link}" : link)
40
+ else
41
+ @@url = URI.parse(context(@@url) + link)
42
+ end
43
+ @@text = open(@@url) {|stream| stream.read}
44
+ end
45
+
46
+ def context url
47
+ u = "#{url.scheme}://#{url.host}"
48
+ u += (url.port == 80 ? '' : ":#{url.port}") + '/'
49
+ u
50
+ end
51
+
52
+ # Rows
53
+
54
+ def query
55
+ tags = ['wiki', 'table', 'tr', 'td']
56
+ rows = Fit::Parse.new(@@text, tags).at(0, 0, 2)
57
+ result = [nil] * rows.size
58
+ 0.upto(rows.size - 1) do |i|
59
+ result[i] = Row.new rows
60
+ rows = rows.more
61
+ end
62
+ result
63
+ end
64
+
65
+ # Utility
66
+
67
+ def get url
68
+ response = Net::HTTP.get_response url
69
+ response.body
70
+ end
71
+
72
+ class Row
73
+ attr_accessor :cells
74
+ def initialize row
75
+ @cells = row.parts
76
+ end
77
+ def numerator; to_number(@cells.at(0).text); end
78
+ def denominator; to_number(@cells.at(1).text); end
79
+ # An hack to get the right type of number
80
+ def to_number string
81
+ begin
82
+ return Integer(string)
83
+ rescue
84
+ return Float(string)
85
+ end
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
data/lib/eg/sqrt.rb ADDED
@@ -0,0 +1,19 @@
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 'fit/column_fixture'
5
+
6
+ module Eg
7
+
8
+ class Sqrt < Fit::ColumnFixture
9
+ attr_accessor :value
10
+ def sqrt
11
+ # But Math.sqrt already raise an error if its parameter is less than zero...
12
+ # and in fact this guard clause is present because the java.lang.Math method
13
+ # for sqare radix would return NaN if its argument is negative.
14
+ raise "negative sqrt" if @value < 0
15
+ Math.sqrt @value
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,83 @@
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 'fat/string_writer'
5
+ require 'fit/column_fixture'
6
+
7
+ module Fat
8
+
9
+ class AnnotationFixture < Fit::ColumnFixture
10
+
11
+ attr_accessor :original_html, :row, :column,
12
+ :overwrite_cell_body, :add_to_cell_body,
13
+ :overwrite_cell_tag, :overwrite_end_cell_tag, :add_to_cell_tag,
14
+ :overwrite_row_tag, :overwrite_end_row_tag, :add_to_row_tag,
15
+ :overwrite_table_tag, :overwrite_end_table_tag, :add_to_table_tag,
16
+ :add_cell_following, :remove_following_cell,
17
+ :add_row_following, :remove_following_row,
18
+ :add_table_following
19
+
20
+ def initialize
21
+ super
22
+ @row = @column = 0
23
+ end
24
+
25
+ def resulting_html
26
+ table = Fit::Parse.new original_html
27
+ row = table.at 0, @row - 1
28
+ cell = row.at 0, @column - 1
29
+
30
+ cell.body = @overwrite_cell_body unless @overwrite_cell_body.nil?
31
+ cell.add_to_body(@add_to_cell_body) unless @add_to_cell_body.nil?
32
+
33
+ cell.tag = @overwrite_cell_tag unless @overwrite_cell_tag.nil?
34
+ cell.end = @overwrite_end_cell_tag unless @overwrite_end_cell_tag.nil?
35
+ cell.add_to_tag(strip_delimiters(@add_to_cell_tag)) unless @add_to_cell_tag.nil?
36
+
37
+ row.tag = @overwrite_row_tag unless @overwrite_row_tag.nil?
38
+ row.end = @overwrite_end_row_tag unless @overwrite_end_row_tag.nil?
39
+ row.add_to_tag(strip_delimiters(@add_to_row_tag)) unless @add_to_row_tag.nil?
40
+
41
+ table.tag = @overwrite_table_tag unless @overwrite_table_tag.nil?
42
+ table.end = @overwrite_end_table_tag unless @overwrite_end_table_tag.nil?
43
+ table.add_to_tag(strip_delimiters(@add_to_table_tag)) unless @add_to_table_tag.nil?
44
+
45
+ add_parse(cell, @add_cell_following, ['td']) unless @add_cell_following.nil?
46
+ remove_parse(cell) unless @remove_following_cell.nil?
47
+
48
+ add_parse(row, @add_row_following, ['tr', 'td']) unless @add_row_following.nil?
49
+ remove_parse(row) unless @remove_following_row.nil?
50
+
51
+ add_parse(table, @add_table_following, ['table', 'tr', 'td']) unless @add_table_following.nil?
52
+
53
+ generate_output table
54
+ end
55
+
56
+ def add_parse parse, new_string, tags
57
+ new_parse = Fit::Parse.new new_string, tags
58
+ new_parse.more = parse.more
59
+ new_parse.trailer = parse.trailer
60
+ parse.more = new_parse
61
+ parse.trailer = nil
62
+ end
63
+
64
+ def remove_parse parse
65
+ parse.trailer = parse.more.trailer
66
+ parse.more = parse.more.more
67
+ end
68
+
69
+ def strip_delimiters string
70
+ string.gsub(/^\[/, '').gsub(/\]$/, '')
71
+ end
72
+
73
+ # Code smell note: copied from Fat::ParseFixture
74
+ def generate_output parse
75
+ result = StringWriter.new
76
+ parse.print result
77
+ result.to_s.strip
78
+ end
79
+
80
+ private :generate_output
81
+ end
82
+
83
+ end
data/lib/fat/color.rb ADDED
@@ -0,0 +1,45 @@
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 'fit/primitive_fixture'
5
+ require 'fat/table'
6
+
7
+ module Fat
8
+
9
+ class Color < Fit::PrimitiveFixture
10
+ def do_rows rows
11
+ @actual_row = Table.table.parts
12
+ raise "wrong size table" if not rows.size == @actual_row.size
13
+ super
14
+ end
15
+ def do_row row
16
+ super
17
+ @actual_row = @actual_row.more
18
+ end
19
+ def do_cell cell, column_index
20
+ check_value cell, color(@actual_row.parts.at(column_index))
21
+ end
22
+ def color cell
23
+ b = extract cell.tag, 'bgcolor="', 'white'
24
+ f = extract cell.body, '<font color="', 'black'
25
+ f == 'black' ? b : "#{f}/#{b}"
26
+ end
27
+ def extract text, pattern, default_color
28
+ index = text.index pattern
29
+ return default_color if index.nil?
30
+ index += pattern.size
31
+ decode text[index..(index + 6)]
32
+ end
33
+ def decode code
34
+ case code
35
+ when Fit::Fixture::RED then 'red'
36
+ when Fit::Fixture::GREEN then 'green'
37
+ when Fit::Fixture::YELLOW then 'yellow'
38
+ when Fit::Fixture::GRAY then 'gray'
39
+ when '#808080' then 'gray'
40
+ else code
41
+ end
42
+ end
43
+ end
44
+
45
+ end
data/lib/fat/divide.rb ADDED
@@ -0,0 +1,13 @@
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 'fit/column_fixture'
5
+
6
+ module Fat
7
+
8
+ class Divide < Fit::ColumnFixture
9
+ attr_accessor :x, :y
10
+ def divide; x / y; end
11
+ end
12
+
13
+ end
@@ -0,0 +1,67 @@
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 'fit/column_fixture'
5
+ require 'fat/string_writer'
6
+
7
+ module Fat
8
+
9
+ class DocumentParseFixture < Fit::ColumnFixture
10
+ attr_accessor :html
11
+ attr_accessor :note # non-functional
12
+
13
+ def output
14
+ generate_output(Fit::Parse.new(@html))
15
+ end
16
+
17
+ def structure
18
+ dump_tables(Fit::Parse.new(@html))
19
+ end
20
+
21
+ def dump_tables(table)
22
+ result = ""
23
+ separator = ""
24
+ while (table)
25
+ result += separator
26
+ result += dump_rows(table.parts)
27
+ separator = "\n----\n"
28
+ table = table.more
29
+ end
30
+ result
31
+ end
32
+
33
+ def dump_rows(row)
34
+ result = ""
35
+ separator = ""
36
+ while (row)
37
+ result += separator
38
+ result += dump_cells(row.parts)
39
+ separator = "\n"
40
+ row = row.more
41
+ end
42
+ result
43
+ end
44
+
45
+ def dump_cells(cell)
46
+ result = ""
47
+ separator = ""
48
+ while (cell)
49
+ result += separator
50
+ result += "[" + cell.body + "]"
51
+ separator = " "
52
+ cell = cell.more
53
+ end
54
+ result
55
+ end
56
+
57
+ def generate_output parse
58
+ result = StringWriter.new
59
+ parse.print result
60
+ result.to_s
61
+ end
62
+
63
+ private :dump_tables, :dump_rows, :dump_cells, :generate_output
64
+
65
+ end
66
+
67
+ end
data/lib/fat/equals.rb ADDED
@@ -0,0 +1,59 @@
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 'fit/primitive_fixture'
5
+ require 'fit/scientific_double'
6
+ require 'fit/type_adapter'
7
+
8
+ require 'fat/money'
9
+
10
+ module Fat
11
+
12
+ class Equals < Fit::PrimitiveFixture
13
+
14
+ attr_accessor :heads, :adapter, :x, :y
15
+
16
+ def do_rows rows
17
+ @heads = rows.parts
18
+ super rows.more
19
+ end
20
+
21
+ def do_cell cell, column_index
22
+ begin
23
+ head = @heads.at(column_index).text[0..0]
24
+ case head
25
+ when 't' then @adapter = type(cell.text)
26
+ when 'x' then @x = @adapter.parse(cell.text)
27
+ when 'y' then @y = @adapter.parse(cell.text)
28
+ when '=' then check_boolean(cell, @adapter.equals(@x, @y))
29
+ when '?' then cell.add_to_body(Fit::Fixture.gray("x: #{print(@x)} y: #{print(@y)}"))
30
+ else raise "Don't do #{head}"
31
+ end
32
+ rescue Exception => e
33
+ exception cell, e
34
+ end
35
+ end
36
+
37
+ def type name;
38
+ case name
39
+ when 'date' then Fit::TypeAdapter.on(self, ParseDate)
40
+ when 'integer' then Fit::TypeAdapter.on(self, Integer)
41
+ when 'real' then Fit::TypeAdapter.on(self, Float)
42
+ when 'scientific' then Fit::TypeAdapter.on(self, Fit::ScientificDouble)
43
+ when 'money' then Fit::TypeAdapter.on(self, Money)
44
+ else Fit::TypeAdapter.for(self, '', false)
45
+ end
46
+ end
47
+
48
+ def parse string, klass
49
+ return Money.new(string) if klass == Money
50
+ return Float(string) if klass == Float
51
+ return Integer(string) if klass == Integer
52
+ super
53
+ end
54
+
55
+ def print value; @adapter.to_s value; end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,67 @@
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 'fit/column_fixture'
5
+
6
+ module Fat
7
+
8
+ class FixtureNameFixture < Fit::ColumnFixture
9
+ attr_accessor :table
10
+ def fixture_name
11
+ table_parse = generate_table_parse(@table)
12
+ dump_tables generate_table_parse(@table)
13
+ end
14
+ def dump_tables table
15
+ result = ''
16
+ separator = ''
17
+ until table.nil?
18
+ result += separator
19
+ result += dump_rows table.parts
20
+ separator = "\n----\n"
21
+ table = table.more
22
+ end
23
+ result
24
+ end
25
+ def dump_rows row
26
+ result = ''
27
+ separator = ''
28
+ until row.nil?
29
+ result += separator
30
+ result += dump_cells row.parts
31
+ separator = "\n"
32
+ row = row.more
33
+ end
34
+ result
35
+ end
36
+ def dump_cells cell
37
+ result = ''
38
+ separator = ''
39
+ until cell.nil?
40
+ result += separator
41
+ result += "[#{cell.text}]"
42
+ separator = ' '
43
+ cell = cell.more
44
+ end
45
+ result
46
+ end
47
+ def valid_fixture; 'not implemented'; end
48
+ def error; 'not implemented'; end
49
+ def generate_table_parse table
50
+ rows = table.split(/\n/)
51
+ Fit::ParseHolder.create 'table', nil, generate_row_parses(rows, 0), nil
52
+ end
53
+ def generate_row_parses rows, row_index
54
+ return nil if row_index >= rows.size
55
+ md = /\[(.*?)\]/.match(rows[row_index])
56
+ cells = md[1..-1]
57
+ Fit::ParseHolder.create 'tr', nil, generate_cell_parses(cells, 0), generate_row_parses(rows, row_index + 1)
58
+ end
59
+ def generate_cell_parses cells, cell_index
60
+ return nil if cell_index >= cells.size
61
+ Fit::ParseHolder.create 'td', cells[cell_index], nil, generate_cell_parses(cells, cell_index + 1)
62
+ end
63
+ private :dump_tables, :dump_rows, :dump_cells
64
+ private :generate_table_parse, :generate_row_parses, :generate_cell_parses
65
+ end
66
+
67
+ end
@@ -0,0 +1,20 @@
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 'fit/column_fixture'
5
+
6
+ module Fat
7
+
8
+ class HtmlToTextFixture < Fit::ColumnFixture
9
+ @@metadata = {'html' => String}
10
+ attr_writer :html
11
+ def text
12
+ html = @html.gsub(/\\u00a0/, "\240")
13
+ escape_ascii(Fit::Parse.html_to_text(html))
14
+ end
15
+ def escape_ascii text
16
+ text.gsub("\x0a", "\\n").gsub("\x0d", "\\r").gsub("\xa0", " ")
17
+ end
18
+ end
19
+
20
+ end
data/lib/fat/money.rb ADDED
@@ -0,0 +1,18 @@
1
+ # Copyright (c) 2002 Cunningham & Cunningham, Inc.
2
+ # Released under the terms of the GNU General Public License version 2 or later.
3
+
4
+ module Fat
5
+
6
+ class Money
7
+ attr_accessor :cents
8
+ def initialize string
9
+ stripped = ''
10
+ string.each {|char| stripped += char if char.between?('0', '9') or char == '.'}
11
+ @cents = (100 * stripped.to_f).to_i
12
+ end
13
+ def == money
14
+ @cents == money.cents
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,32 @@
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 'fit/column_fixture'
5
+
6
+ module Fat
7
+
8
+ class OutputFixture < Fit::ColumnFixture
9
+ attr_accessor :text
10
+ def cell_output
11
+ cell = Fit::ParseHolder.create 'td', '', nil, nil
12
+ cell.leader = ''
13
+ cell.body = Fit::Fixture.escape unescape(@text)
14
+ generate_output cell
15
+ end
16
+ def unescape text
17
+ text.gsub(/\\n/, "\n").gsub(/\\r/, "\r")
18
+ end
19
+ def generate_output parse
20
+ result = StringWriter.new
21
+ parse.print result
22
+ result.to_s
23
+ end
24
+ private :unescape, :generate_output
25
+ class StringWriter
26
+ def initialize; @s = ''; end
27
+ def print s; @s += s; end
28
+ def to_s; @s; end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,92 @@
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 'fat/string_writer'
5
+ require 'fit/column_fixture'
6
+
7
+ module Fat
8
+
9
+ # A fixture to discuss parsing specification.
10
+ class ParseFixture < Fit::ColumnFixture
11
+
12
+ attr_accessor :html, :table_cell, :entity
13
+ attr_accessor :note # unused
14
+
15
+ def generate_parse
16
+ input_columns = 0
17
+ html = nil
18
+ unless @html.nil?
19
+ input_columns += 1
20
+ html = @html
21
+ end
22
+ unless @table_cell.nil?
23
+ input_columns += 1
24
+ html = "<table><tr>#@table_cell</tr></table>"
25
+ end
26
+ unless @entity.nil?
27
+ input_columns += 1
28
+ html = "<table><tr><td>#@entity</td></tr></table>"
29
+ end
30
+
31
+ raise "Exactly ONE of the following columns is needed: 'Html', 'TableCell', or 'Entity'" if input_columns != 1
32
+
33
+ html.gsub!(/\\u00a0/, "\240")
34
+ Fit::Parse.new html
35
+ end
36
+
37
+ def output; generate_output(generate_parse); end
38
+
39
+ def generate_output parse
40
+ result = StringWriter.new
41
+ parse.print result
42
+ result.to_s
43
+ end
44
+
45
+ def parse; dump_tables(generate_parse); end
46
+
47
+ def dump_tables table
48
+ result = ''
49
+ separator = ''
50
+ until table.nil?
51
+ result += separator
52
+ result += dump_rows(table.parts)
53
+ separator = "\n----\n"
54
+ table = table.more
55
+ end
56
+ result
57
+ end
58
+
59
+ def dump_rows row
60
+ result = ''
61
+ separator = ''
62
+ until row.nil?
63
+ result += separator
64
+ result += dump_cells(row.parts)
65
+ separator = "\n"
66
+ row = row.more
67
+ end
68
+ result
69
+ end
70
+
71
+ def dump_cells cell
72
+ result = ''
73
+ separator = ''
74
+ until cell.nil?
75
+ result += separator
76
+ result += "[#{escape_ascii(cell.text)}]"
77
+ separator = ' '
78
+ cell = cell.more
79
+ end
80
+ result
81
+ end
82
+
83
+ def escape_ascii text
84
+ text.gsub("\x0a", "\\n").gsub("\x0d", "\\r").gsub("\xa0", " ")
85
+ end
86
+
87
+ private :generate_parse, :generate_output
88
+ private :dump_tables, :dump_rows, :dump_cells, :escape_ascii
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,31 @@
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 'fit/column_fixture'
5
+
6
+ module Fat
7
+
8
+ class ReferenceFixture < Fit::ColumnFixture
9
+ attr_accessor :description, :location
10
+ def result
11
+ input_name = "spec/#@location"
12
+ output_name = "spec/results_#@location"
13
+ begin
14
+ runner = Fit::FileRunner.new
15
+ runner.process_args [input_name, output_name]
16
+ runner.process
17
+ runner.output.close
18
+
19
+ counts = runner.fixture.counts
20
+ if counts.total_errors.zero?
21
+ return 'pass'
22
+ else
23
+ return "fail: #{counts.to_s}"
24
+ end
25
+ rescue Exception => e
26
+ return "file not found: #{input_name}"
27
+ end
28
+ end
29
+ end
30
+
31
+ end