Class: ParseTreeTestCase

### Home Classes Methods

### In Files

- lib/pt_testcase.rb

### Parent

Minitest::Test

### Methods

- ::add_18tests
- ::add_19edgecases
- ::add_19tests
- ::add_test
- ::add_tests
- ::clone_same
- ::copy_test_case
- ::generate_test
- ::generate_tests
- ::inherited
- ::install_missing_reporter
- ::previous
- ::testcase_order
- ::testcases
- ::unsupported_tests
- #after_process_hook
- #before_process_hook
- #setup

### Files

- History.txt
- Manifest.txt
- README.txt

### Class/Module Index

Quicksearch

- SexpProcessor
- SexpProcessor::Environment
- CompositeSexpProcessor
- Examples
- MethodBasedSexpProcessor
- NotEmptyError
- Object
- ParseTreeTestCase
- Sexp
- SexpAny
- SexpInterpreter
- SexpMatchSpecial
- SexpMatchSpecials
- SexpProcessorError
- SexpTypeError
- Unique
- UnknownNodeError
- UnsupportedNodeError

No matching classes.

# ParseTreeTestCase

### Constants

VER_RE

### Attributes

processor[RW]

### Public Class Methods

add_18tests(name, hash) click to toggle source

    # File lib/pt_testcase.rb, line 73
    def self.add_18tests name, hash
      add_tests "#{name}__18", hash
    end

add_19edgecases(ruby, sexp, cases) click to toggle source

    # File lib/pt_testcase.rb, line 81
    def self.add_19edgecases ruby, sexp, cases
      cases.each do |name, code|
        add_19tests name, "Ruby" => code, "ParseTree" => sexp, "Ruby2Ruby" => ruby
      end
    end

add_19tests(name, hash) click to toggle source

    # File lib/pt_testcase.rb, line 77
    def self.add_19tests name, hash
      add_tests "#{name}__19_20_21_22", hash # HACK?
    end

add_test(name, data, klass = self.name[4..-1]) click to toggle source

    # File lib/pt_testcase.rb, line 48
    def self.add_test name, data, klass = self.name[4..-1]
      name = name.to_s
      klass = klass.to_s

      if testcases.has_key? name then
        if testcases[name].has_key? klass then
          warn "testcase #{klass}##{name} already has data"
        else
          testcases[name][klass] = data
        end
      else
        warn "testcase #{name} does not exist"
      end
    end

add_tests(name, hash) click to toggle source

    # File lib/pt_testcase.rb, line 63
    def self.add_tests name, hash
      name = name.to_s

      hash.each do |klass, data|
        warn "testcase #{klass}##{name} already has data" if
          testcases[name].has_key? klass
        testcases[name][klass] = data
      end
    end

clone_same() click to toggle source

    # File lib/pt_testcase.rb, line 87
    def self.clone_same
      @@testcases.each do |node, data|
        data.each do |key, val|
          if val == :same then
            prev_key = self.previous(key)
            data[key] = data[prev_key].deep_clone
          end
        end
      end
    end

copy_test_case(nonverbose, klass) click to toggle source

    # File lib/pt_testcase.rb, line 98
    def self.copy_test_case nonverbose, klass
      verbose = nonverbose + "_mri_verbose_flag"
      testcases[verbose][klass] = testcases[nonverbose][klass]
    end

generate_test(klass, node, data, input_name, output_name) click to toggle source

    # File lib/pt_testcase.rb, line 105
    def self.generate_test klass, node, data, input_name, output_name
      klass.send :define_method, "test_#{node}" do
        flunk "Processor is nil" if processor.nil?

        tversions = node[/(?:_#{VER_RE})+$/]
        if tversions then
          cversion = self.class.name[/#{VER_RE}/]

          # can't push this up because it may be generating into an
          # abstract test class and the actual subclass is versioned.
          return "version specific test" unless tversions.include? cversion if cversion
        end

        assert data.has_key?(input_name), "Unknown input data"
        assert data.has_key?(output_name), "Missing test data"

        $missing[node] << output_name unless data.has_key? output_name

        input    = data[input_name].deep_clone
        expected = data[output_name].deep_clone

        case expected
        when :unsupported then
          assert_raises(UnsupportedNodeError) do
            processor.process(input)
          end
        else
          extra_expected = []
          extra_input = []

          _, expected, extra_expected = *expected if
            Array === expected and expected.first == :defx
          _, input, extra_input = *input if
            Array === input and input.first == :defx

          # OMG... I can't believe I have to do this this way.  these
          # hooks are here instead of refactoring this define_method
          # body into an assertion. It'll allow subclasses to hook in
          # and add behavior before or after the processor does it's
          # thing. If you go the body refactor route, some of the
          # RawParseTree test cases fail for completely bogus reasons.

          before_process_hook klass, node, data, input_name, output_name
          refute_nil data[input_name], "testcase does not exist?"
          @result = processor.process input
          assert_equal(expected, @result,
                       "failed on input: #{data[input_name].inspect}")
          after_process_hook klass, node, data, input_name, output_name

          extra_input.each do |extra|
            processor.process(extra)
          end
          extra = processor.extra_methods rescue []
          assert_equal extra_expected, extra
        end
      end
    end

generate_tests(klass) click to toggle source

    # File lib/pt_testcase.rb, line 163
    def self.generate_tests klass
      install_missing_reporter
      clone_same

      output_name = klass.name.to_s.sub(/^Test/, '')

      input_name = self.previous(output_name)

      @@testcases.each do |node, data|
        next if [:skip, :unsupported].include? data[input_name]
        next if data[output_name] == :skip

        generate_test klass, node, data, input_name, output_name
      end
    end

inherited(klass) click to toggle source

    # File lib/pt_testcase.rb, line 179
    def self.inherited klass
      super

      generate_tests klass unless klass.name =~ /TestCase/
    end

install_missing_reporter() click to toggle source

    # File lib/pt_testcase.rb, line 185
    def self.install_missing_reporter
      unless defined? $missing then
        $missing = Hash.new { |h,k| h[k] = [] }
        at_exit {
          at_exit {
            warn ""
            $missing.sort.each do |name, klasses|
              warn "add_tests(#{name.inspect},"
              klasses.map! { |klass| "          #{klass.inspect} => :same" }
              warn klasses.join("\n") + ")"
            end
            warn ""
          }
        }
      end
    end

previous(key, extra=0) click to toggle source

    # File lib/pt_testcase.rb, line 202
    def self.previous(key, extra=0) # FIX: remove R2C code
      idx = @@testcase_order.index(key)

      raise "Unknown class #{key} in @@testcase_order" if idx.nil?

      case key
      when "RubyToRubyC" then
        idx -= 1
      end
      @@testcase_order[idx - 1 - extra]
    end

testcase_order() click to toggle source

    # File lib/pt_testcase.rb, line 214
    def self.testcase_order; @@testcase_order; end

testcases() click to toggle source

    # File lib/pt_testcase.rb, line 215
    def self.testcases; @@testcases; end

unsupported_tests(*tests) click to toggle source

    # File lib/pt_testcase.rb, line 217
    def self.unsupported_tests *tests
      tests.flatten.each do |name|
        add_test name, :unsupported
      end
    end

### Public Instance Methods

after_process_hook(klass, node, data, input_name, output_name) click to toggle source

    # File lib/pt_testcase.rb, line 42
    def after_process_hook klass, node, data, input_name, output_name
    end

before_process_hook(klass, node, data, input_name, output_name) click to toggle source

    # File lib/pt_testcase.rb, line 45
    def before_process_hook klass, node, data, input_name, output_name
    end

setup() click to toggle source

    # File lib/pt_testcase.rb, line 37
    def setup
      super
      @processor = nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.