File: extension_test.rb

package info (click to toggle)
ruby-citrus 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 420 kB
  • sloc: ruby: 3,417; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 848 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.expand_path('../helper', __FILE__)

class ExtensionTest < Test::Unit::TestCase
  module MatchModule
    def a_test
      :test
    end
  end

  module NumericModule
    def add_one
      to_str.to_i + 1
    end
  end

  NumericProcBare = Proc.new {
    to_str.to_i + 1
  }

  def test_match_module
    rule = StringTerminal.new('abc')
    rule.extension = MatchModule
    match = rule.parse('abc')
    assert(match)
    assert_equal(:test, match.a_test)
  end

  def test_numeric_module
    rule = StringTerminal.new('1')
    rule.extension = NumericModule
    match = rule.parse('1')
    assert(match)
    assert_equal(2, match.add_one)
  end

  def test_numeric_proc_bare
    rule = StringTerminal.new('1')
    rule.extension = NumericProcBare
    match = rule.parse('1')
    assert(match)
    assert_equal(2, match.value)
  end
end