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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
begin
require 'ripper'
require 'test/unit'
ripper_test = true
module TestRipper; end
rescue LoadError
end
class TestRipper::Filter < Test::Unit::TestCase
class Filter < Ripper::Filter
def on_default(event, token, data)
if data.empty?
data[:filename] = filename rescue nil
data[:lineno] = lineno
data[:column] = column
data[:token] = token
end
data
end
end
def filename
File.expand_path(__FILE__)
end
def test_filter_filename_unset
data = {}
filter = Filter.new(File.read(filename))
filter.parse(data)
assert_equal('-', data[:filename], "[ruby-dev:37856]")
assert_equal('-', filter.filename)
end
def test_filter_filename
data = {}
filter = Filter.new(File.read(filename), filename)
assert_equal(filename, filter.filename)
filter.parse(data)
assert_equal(filename, data[:filename])
assert_equal(filename, filter.filename)
end
def test_filter_lineno
data = {}
src = File.read(filename)
src_lines = src.count("\n")
filter = Filter.new(src)
assert_equal(nil, filter.lineno)
filter.parse(data)
assert_equal(1, data[:lineno])
assert_equal(src_lines, filter.lineno)
end
def test_filter_lineno_set
data = {}
src = File.read(filename)
src_lines = src.count("\n")
filter = Filter.new(src, '-', 100)
assert_equal(nil, filter.lineno)
filter.parse(data)
assert_equal(100, data[:lineno])
assert_equal(src_lines+100-1, filter.lineno)
end
def test_filter_column
data = {}
src = File.read(filename)
last_columns = src[/(.*)\Z/].size
filter = Filter.new(src)
assert_equal(nil, filter.column)
filter.parse(data)
assert_equal(0, data[:column])
assert_equal(last_columns, filter.column)
end
def test_filter_token
data = {}
filter = Filter.new(File.read(filename))
filter.parse(data)
assert_equal("begin", data[:token])
end
end if ripper_test
|