treetop 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/Rakefile +6 -6
  2. data/doc/images/bottom_background.png +0 -0
  3. data/doc/images/middle_backgound.png +0 -0
  4. data/doc/images/middle_background.png +0 -0
  5. data/doc/images/top_background.png +0 -0
  6. data/doc/index.markdown +13 -8
  7. data/doc/screen.css +52 -0
  8. data/doc/site.html +34 -0
  9. data/doc/site.rb +41 -0
  10. data/examples/lambda_calculus/lambda_calculus.rb +2 -2
  11. data/lib/treetop/bootstrap_gen_1_metagrammar.rb +37 -0
  12. data/lib/treetop/compiler/metagrammar. +0 -0
  13. data/lib/treetop/compiler/metagrammar.rb +20 -9
  14. data/lib/treetop/compiler/metagrammar.treetop +1 -1
  15. data/lib/treetop/compiler/node_classes/declaration_sequence.rb +1 -7
  16. data/lib/treetop/compiler/node_classes/grammar.rb +2 -2
  17. data/lib/treetop/runtime/compiled_parser.rb +15 -2
  18. metadata +12 -74
  19. data/test/compilation_target/target.rb +0 -143
  20. data/test/compilation_target/target.treetop +0 -15
  21. data/test/compilation_target/target_test.rb +0 -56
  22. data/test/compiler/and_predicate_test.rb +0 -33
  23. data/test/compiler/anything_symbol_test.rb +0 -24
  24. data/test/compiler/character_class_test.rb +0 -45
  25. data/test/compiler/choice_test.rb +0 -74
  26. data/test/compiler/circular_compilation_test.rb +0 -20
  27. data/test/compiler/failure_propagation_functional_test.rb +0 -20
  28. data/test/compiler/grammar_compiler_test.rb +0 -58
  29. data/test/compiler/grammar_test.rb +0 -37
  30. data/test/compiler/nonterminal_symbol_test.rb +0 -38
  31. data/test/compiler/not_predicate_test.rb +0 -35
  32. data/test/compiler/one_or_more_test.rb +0 -30
  33. data/test/compiler/optional_test.rb +0 -32
  34. data/test/compiler/parenthesized_expression_test.rb +0 -17
  35. data/test/compiler/parsing_rule_test.rb +0 -30
  36. data/test/compiler/sequence_test.rb +0 -68
  37. data/test/compiler/terminal_symbol_test.rb +0 -35
  38. data/test/compiler/test_grammar.treetop +0 -7
  39. data/test/compiler/zero_or_more_test.rb +0 -51
  40. data/test/composition/a.treetop +0 -11
  41. data/test/composition/b.treetop +0 -11
  42. data/test/composition/c.treetop +0 -10
  43. data/test/composition/d.treetop +0 -10
  44. data/test/composition/grammar_composition_test.rb +0 -23
  45. data/test/parser/syntax_node_test.rb +0 -53
  46. data/test/parser/terminal_parse_failure_test.rb +0 -22
  47. data/test/ruby_extensions/string_test.rb +0 -33
  48. data/test/screw/Rakefile +0 -16
  49. data/test/screw/unit.rb +0 -37
  50. data/test/screw/unit/assertion_failed_error.rb +0 -14
  51. data/test/screw/unit/assertions.rb +0 -615
  52. data/test/screw/unit/auto_runner.rb +0 -227
  53. data/test/screw/unit/collector.rb +0 -45
  54. data/test/screw/unit/collector/dir.rb +0 -107
  55. data/test/screw/unit/collector/objectspace.rb +0 -28
  56. data/test/screw/unit/error.rb +0 -48
  57. data/test/screw/unit/failure.rb +0 -45
  58. data/test/screw/unit/sugar.rb +0 -25
  59. data/test/screw/unit/test_case.rb +0 -176
  60. data/test/screw/unit/test_result.rb +0 -73
  61. data/test/screw/unit/test_suite.rb +0 -70
  62. data/test/screw/unit/ui.rb +0 -4
  63. data/test/screw/unit/ui/console/test_runner.rb +0 -118
  64. data/test/screw/unit/ui/fox/test_runner.rb +0 -268
  65. data/test/screw/unit/ui/gtk/test_runner.rb +0 -416
  66. data/test/screw/unit/ui/gtk2/testrunner.rb +0 -465
  67. data/test/screw/unit/ui/test_runner_mediator.rb +0 -58
  68. data/test/screw/unit/ui/test_runner_utilities.rb +0 -46
  69. data/test/screw/unit/ui/tk/test_runner.rb +0 -260
  70. data/test/screw/unit/util.rb +0 -4
  71. data/test/screw/unit/util/backtrace_filter.rb +0 -40
  72. data/test/screw/unit/util/observable.rb +0 -82
  73. data/test/screw/unit/util/proc_wrapper.rb +0 -48
  74. data/test/test_helper.rb +0 -90
@@ -1,45 +0,0 @@
1
- module Screw
2
- module Unit
3
-
4
- # Encapsulates a test failure. Created by Screw::Unit::TestCase
5
- # when an assertion fails.
6
- class Failure
7
- attr_reader :test_name, :location, :message
8
-
9
- SINGLE_CHARACTER = 'F'
10
-
11
- # Creates a new Failure with the given location and
12
- # message.
13
- def initialize(test_name, location, message)
14
- @test_name = test_name
15
- @location = location
16
- @message = message
17
- end
18
-
19
- # Returns a single character representation of a failure.
20
- def single_character_display
21
- SINGLE_CHARACTER
22
- end
23
-
24
- # Returns a brief version of the error description.
25
- def short_display
26
- "#@test_name: #{@message.split("\n")[0]}"
27
- end
28
-
29
- # Returns a verbose version of the error description.
30
- def long_display
31
- location_display = if(location.size == 1)
32
- location[0].sub(/\A(.+:\d+).*/, ' [\\1]')
33
- else
34
- "\n [#{location.join("\n ")}]"
35
- end
36
- "Failure:\n#@test_name#{location_display}:\n#@message"
37
- end
38
-
39
- # Overridden to return long_display.
40
- def to_s
41
- long_display
42
- end
43
- end
44
- end
45
- end
@@ -1,25 +0,0 @@
1
- class Object
2
- def context(description, options = {}, &block)
3
- superclass = options[:extend] || Screw::Unit::TestCase
4
- test_case_class = Class.new(superclass, &block)
5
- test_case_class.test_case_description = description
6
- Object.send(:const_set, unique_test_case_name(description.sanitize.camelize), test_case_class)
7
- end
8
-
9
- def unique_test_case_name(name, n=1)
10
- candidate_name = (n > 1 ? "#{name}#{n}" : name).to_sym
11
- if Object.const_defined?(candidate_name)
12
- unique_test_case_name(name, n + 1)
13
- else
14
- candidate_name
15
- end
16
- end
17
-
18
- alias :describe :context
19
- end
20
-
21
- class String
22
- def sanitize
23
- self.gsub(/[^\w]+/, "_")
24
- end
25
- end
@@ -1,176 +0,0 @@
1
- module Screw
2
- module Unit
3
-
4
- # Ties everything together. If you subclass and add your own
5
- # test methods, it takes care of making them into tests and
6
- # wrapping those tests into a suite. It also does the
7
- # nitty-gritty of actually running an individual test and
8
- # collecting its results into a Screw::Unit::TestResult object.
9
- class TestCase
10
- class << self
11
-
12
- attr_writer :test_case_description
13
-
14
- def test_case_description
15
- @test_case_description || self.to_s
16
- end
17
-
18
- # Rolls up all of the test* methods in the fixture into
19
- # one suite, creating a new instance of the fixture for
20
- # each method.
21
- def suite
22
- method_names = public_instance_methods(true)
23
- tests = method_names.delete_if {|method_name| method_name !~ /^test./}
24
- suite = TestSuite.new(name)
25
- tests.sort.each do
26
- |test|
27
- catch(:invalid_test) do
28
- suite << new(test)
29
- end
30
- end
31
- return suite
32
- end
33
-
34
- def test_names
35
- @test_names ||= Hash.new
36
- end
37
-
38
- # Creates a test method by prefixing string with 'test_' and replacing non word characters with underbars
39
- def test(name_string, &block)
40
- method_name = unique_test_name("test_" + name_string.sanitize)
41
- test_names[method_name] = name_string
42
- define_method(method_name, &block)
43
- end
44
-
45
- def unique_test_name(name, n=1)
46
- candidate_name = (n > 1 ? "#{name}#{n}" : name).to_sym
47
- if method_defined?(candidate_name)
48
- unique_test_name(name, n + 1)
49
- else
50
- candidate_name
51
- end
52
- end
53
-
54
-
55
- alias :it :test
56
- end
57
-
58
-
59
- include Assertions
60
- include Spec::Matchers
61
- include Util::BacktraceFilter
62
-
63
- attr_reader :method_name
64
-
65
- STARTED = name + "::STARTED"
66
- FINISHED = name + "::FINISHED"
67
-
68
- ##
69
- # These exceptions are not caught by #run.
70
-
71
- PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, Interrupt,
72
- SystemExit]
73
-
74
- # Creates a new instance of the fixture for running the
75
- # test represented by test_method_name.
76
- def initialize(test_method_name)
77
- unless(respond_to?(test_method_name) and
78
- (method(test_method_name).arity == 0 ||
79
- method(test_method_name).arity == -1))
80
- throw :invalid_test
81
- end
82
- @method_name = test_method_name
83
- @test_passed = true
84
- end
85
-
86
- # Runs the individual test method represented by this
87
- # instance of the fixture, collecting statistics, failures
88
- # and errors in result.
89
- def run(result)
90
- yield(STARTED, name)
91
- @_result = result
92
- begin
93
- setup
94
- __send__(@method_name)
95
- rescue AssertionFailedError => e
96
- add_failure(e.message, e.backtrace)
97
- rescue Exception
98
- raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
99
- add_error($!)
100
- ensure
101
- begin
102
- teardown
103
- rescue AssertionFailedError => e
104
- add_failure(e.message, e.backtrace)
105
- rescue Exception
106
- raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
107
- add_error($!)
108
- end
109
- end
110
- result.add_run
111
- yield(FINISHED, name)
112
- end
113
-
114
- # Called before every test method runs. Can be used
115
- # to set up fixture information.
116
- def setup
117
- end
118
-
119
- # Called after every test method runs. Can be used to tear
120
- # down fixture information.
121
- def teardown
122
- end
123
-
124
- def default_test
125
- flunk("No tests were specified")
126
- end
127
-
128
- # Returns whether this individual test passed or
129
- # not. Primarily for use in teardown so that artifacts
130
- # can be left behind if the test fails.
131
- def passed?
132
- return @test_passed
133
- end
134
- private :passed?
135
-
136
- def size
137
- 1
138
- end
139
-
140
- def add_assertion
141
- @_result.add_assertion
142
- end
143
- private :add_assertion
144
-
145
- def add_failure(message, all_locations=caller())
146
- @test_passed = false
147
- @_result.add_failure(Failure.new(name, filter_backtrace(all_locations), message))
148
- end
149
- private :add_failure
150
-
151
- def add_error(exception)
152
- @test_passed = false
153
- @_result.add_error(Error.new(name, exception))
154
- end
155
- private :add_error
156
-
157
- # Returns a human-readable name for the specific test that
158
- # this instance of TestCase represents.
159
- def name
160
- "#{self.class.test_case_description}: #{self.class.test_names[@method_name] || @method_name}"
161
- end
162
-
163
- # Overridden to return #name.
164
- def to_s
165
- name
166
- end
167
-
168
- # It's handy to be able to compare TestCase instances.
169
- def ==(other)
170
- return false unless(other.kind_of?(self.class))
171
- return false unless(@method_name == other.method_name)
172
- self.class == other.class
173
- end
174
- end
175
- end
176
- end
@@ -1,73 +0,0 @@
1
- module Screw
2
- module Unit
3
-
4
- # Collects Screw::Unit::Failure and Screw::Unit::Error so that
5
- # they can be displayed to the user. To this end, observers
6
- # can be added to it, allowing the dynamic updating of, say, a
7
- # UI.
8
- class TestResult
9
- include Util::Observable
10
-
11
- CHANGED = "CHANGED"
12
- FAULT = "FAULT"
13
-
14
- attr_reader(:run_count, :assertion_count)
15
-
16
- # Constructs a new, empty TestResult.
17
- def initialize
18
- @run_count, @assertion_count = 0, 0
19
- @failures, @errors = Array.new, Array.new
20
- end
21
-
22
- # Records a test run.
23
- def add_run
24
- @run_count += 1
25
- notify_listeners(CHANGED, self)
26
- end
27
-
28
- # Records a Screw::Unit::Failure.
29
- def add_failure(failure)
30
- @failures << failure
31
- notify_listeners(FAULT, failure)
32
- notify_listeners(CHANGED, self)
33
- end
34
-
35
- # Records a Screw::Unit::Error.
36
- def add_error(error)
37
- @errors << error
38
- notify_listeners(FAULT, error)
39
- notify_listeners(CHANGED, self)
40
- end
41
-
42
- # Records an individual assertion.
43
- def add_assertion
44
- @assertion_count += 1
45
- notify_listeners(CHANGED, self)
46
- end
47
-
48
- # Returns a string contain the recorded runs, assertions,
49
- # failures and errors in this TestResult.
50
- def to_s
51
- "#{run_count} tests, #{assertion_count} assertions, #{failure_count} failures, #{error_count} errors"
52
- end
53
-
54
- # Returns whether or not this TestResult represents
55
- # successful completion.
56
- def passed?
57
- return @failures.empty? && @errors.empty?
58
- end
59
-
60
- # Returns the number of failures this TestResult has
61
- # recorded.
62
- def failure_count
63
- return @failures.size
64
- end
65
-
66
- # Returns the number of errors this TestResult has
67
- # recorded.
68
- def error_count
69
- return @errors.size
70
- end
71
- end
72
- end
73
- end
@@ -1,70 +0,0 @@
1
- module Screw
2
- module Unit
3
-
4
- # A collection of tests which can be #run.
5
- #
6
- # Note: It is easy to confuse a TestSuite instance with
7
- # something that has a static suite method; I know because _I_
8
- # have trouble keeping them straight. Think of something that
9
- # has a suite method as simply providing a way to get a
10
- # meaningful TestSuite instance.
11
- class TestSuite
12
- attr_reader :name, :tests
13
-
14
- STARTED = name + "::STARTED"
15
- FINISHED = name + "::FINISHED"
16
-
17
- # Creates a new TestSuite with the given name.
18
- def initialize(name="Unnamed TestSuite")
19
- @name = name
20
- @tests = []
21
- end
22
-
23
- # Runs the tests and/or suites contained in this
24
- # TestSuite.
25
- def run(result, &progress_block)
26
- yield(STARTED, name)
27
- @tests.each do |test|
28
- test.run(result, &progress_block)
29
- end
30
- yield(FINISHED, name)
31
- end
32
-
33
- # Adds the test to the suite.
34
- def <<(test)
35
- @tests << test
36
- self
37
- end
38
-
39
- def delete(test)
40
- @tests.delete(test)
41
- end
42
-
43
- # Retuns the rolled up number of tests in this suite;
44
- # i.e. if the suite contains other suites, it counts the
45
- # tests within those suites, not the suites themselves.
46
- def size
47
- total_size = 0
48
- @tests.each { |test| total_size += test.size }
49
- total_size
50
- end
51
-
52
- def empty?
53
- tests.empty?
54
- end
55
-
56
- # Overridden to return the name given the suite at
57
- # creation.
58
- def to_s
59
- @name
60
- end
61
-
62
- # It's handy to be able to compare TestSuite instances.
63
- def ==(other)
64
- return false unless(other.kind_of?(self.class))
65
- return false unless(@name == other.name)
66
- @tests == other.tests
67
- end
68
- end
69
- end
70
- end
@@ -1,4 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require File.join(dir, 'ui', 'test_runner_mediator')
3
- require File.join(dir, 'ui', 'test_runner_utilities')
4
- #require File.join(dir, 'ui', 'console', 'test_runner')
@@ -1,118 +0,0 @@
1
- module Screw
2
- module Unit
3
- module UI
4
- module Console
5
-
6
- # Runs a Screw::Unit::TestSuite on the console.
7
- class TestRunner
8
- extend TestRunnerUtilities
9
-
10
- # Creates a new TestRunner for running the passed
11
- # suite. If quiet_mode is true, the output while
12
- # running is limited to progress dots, errors and
13
- # failures, and the final result. io specifies
14
- # where runner output should go to; defaults to
15
- # STDOUT.
16
- def initialize(suite, output_level=NORMAL, io=STDOUT)
17
- if (suite.respond_to?(:suite))
18
- @suite = suite.suite
19
- else
20
- @suite = suite
21
- end
22
- @output_level = output_level
23
- @io = io
24
- @already_outputted = false
25
- @faults = []
26
- end
27
-
28
- # Begins the test run.
29
- def start
30
- setup_mediator
31
- attach_to_mediator
32
- return start_mediator
33
- end
34
-
35
- private
36
- def setup_mediator
37
- @mediator = create_mediator(@suite)
38
- suite_name = @suite.to_s
39
- if ( @suite.kind_of?(Module) )
40
- suite_name = @suite.name
41
- end
42
- output("Loaded suite #{suite_name}")
43
- end
44
-
45
- def create_mediator(suite)
46
- return TestRunnerMediator.new(suite)
47
- end
48
-
49
- def attach_to_mediator
50
- @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
51
- @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
52
- @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
53
- @mediator.add_listener(TestCase::STARTED, &method(:test_started))
54
- @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
55
- end
56
-
57
- def start_mediator
58
- return @mediator.run_suite
59
- end
60
-
61
- def add_fault(fault)
62
- @faults << fault
63
- output_single(fault.single_character_display, PROGRESS_ONLY)
64
- @already_outputted = true
65
- end
66
-
67
- def started(result)
68
- @result = result
69
- output("Started")
70
- end
71
-
72
- def finished(elapsed_time)
73
- nl
74
- output("Finished in #{elapsed_time} seconds.")
75
- @faults.each_with_index do |fault, index|
76
- nl
77
- output("%3d) %s" % [index + 1, fault.long_display])
78
- end
79
- nl
80
- output(@result)
81
- end
82
-
83
- def test_started(name)
84
- output_single(name + ": ", VERBOSE)
85
- end
86
-
87
- def test_finished(name)
88
- output_single(".", PROGRESS_ONLY) unless (@already_outputted)
89
- nl(VERBOSE)
90
- @already_outputted = false
91
- end
92
-
93
- def nl(level=NORMAL)
94
- output("", level)
95
- end
96
-
97
- def output(something, level=NORMAL)
98
- @io.puts(something) if (output?(level))
99
- @io.flush
100
- end
101
-
102
- def output_single(something, level=NORMAL)
103
- @io.write(something) if (output?(level))
104
- @io.flush
105
- end
106
-
107
- def output?(level)
108
- level <= @output_level
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
115
-
116
- if __FILE__ == $0
117
- Screw::Unit::UI::Console::TestRunner.start_command_line_test
118
- end