chirp 0.2.0 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +44 -2
- data/README.txt +10 -2
- data/Rakefile +1 -1
- data/bin/chirp +6 -4
- data/lib/chirp.rb +7 -3
- data/lib/chirp/application.rb +248 -159
- data/lib/chirp/context.rb +101 -0
- data/lib/chirp/fs_expression.rb +180 -0
- data/lib/chirp/path_filter.rb +58 -0
- data/lib/chirp/pathmap.rb +200 -0
- data/lib/chirp/span.rb +38 -0
- data/test/account.dir/input +0 -0
- data/test/account.dir/output +0 -0
- data/test/account.dir/program.chirp +7 -4
- data/test/action.dir/input +0 -0
- data/test/action.dir/output +0 -0
- data/test/action.dir/program.chirp +2 -2
- data/test/beforeafter.dir/input +0 -0
- data/test/beforeafter.dir/output +0 -0
- data/test/beforeafter.dir/program.chirp +3 -3
- data/test/copy1.dir/input +0 -0
- data/test/copy1.dir/output +5 -0
- data/test/copy1.dir/program.chirp +9 -0
- data/test/copy1.dir/source +2 -0
- data/test/copy2.dir/input +0 -0
- data/test/copy2.dir/output +5 -0
- data/test/copy2.dir/program.chirp +9 -0
- data/test/copy2.dir/source +2 -0
- data/test/copy3.dir/input +0 -0
- data/test/copy3.dir/output +5 -0
- data/test/copy3.dir/program.chirp +7 -0
- data/test/copy3.dir/source +2 -0
- data/test/copy_file.dir/a.txt +1 -0
- data/test/copy_file.dir/b.txt +1 -0
- data/test/copy_file.dir/c.txt +1 -0
- data/test/copy_file.dir/input +0 -0
- data/test/copy_file.dir/output +2 -0
- data/test/copy_file.dir/program.chirp +5 -0
- data/test/fields.dir/input +0 -0
- data/test/fields.dir/output +0 -0
- data/test/fields.dir/program.chirp +2 -2
- data/test/fields_sep.dir/input +0 -0
- data/test/fields_sep.dir/output +0 -0
- data/test/fields_sep.dir/program.chirp +1 -2
- data/test/files.dir/a.ignore +0 -0
- data/test/files.dir/a.txt +0 -0
- data/test/files.dir/b.txt +0 -0
- data/test/files.dir/c.stuff +0 -0
- data/test/files.dir/input +0 -0
- data/test/files.dir/output +3 -0
- data/test/files.dir/program.chirp +7 -3
- data/test/fs_expr.dir/aa.txt +1 -0
- data/test/fs_expr.dir/bb.txt +9 -0
- data/test/fs_expr.dir/cc.txt +0 -0
- data/test/fs_expr.dir/dir1/dir2/dir3/a.txt +1 -0
- data/test/fs_expr.dir/input +0 -0
- data/test/fs_expr.dir/output +7 -0
- data/test/fs_expr.dir/program.chirp +17 -0
- data/test/inplace.dir/a.txt +0 -0
- data/test/inplace.dir/b.txt +0 -0
- data/test/inplace.dir/input +0 -0
- data/test/inplace.dir/output +0 -0
- data/test/inplace.dir/program.chirp +4 -6
- data/test/line_no.dir/input +0 -0
- data/test/line_no.dir/output +1 -0
- data/test/line_no.dir/program.chirp +5 -1
- data/test/match.dir/input +0 -0
- data/test/match.dir/output +0 -0
- data/test/match.dir/program.chirp +1 -1
- data/test/path.dir/dir1/dir2/dir3/a.txt +1 -0
- data/test/path.dir/input +0 -0
- data/test/path.dir/new +5 -0
- data/test/path.dir/output +20 -0
- data/test/path.dir/program.chirp +44 -0
- data/test/proc.dir/input +0 -0
- data/test/proc.dir/output +0 -0
- data/test/proc.dir/program.chirp +2 -2
- data/test/rename_file.dir/a.txt +4 -0
- data/test/rename_file.dir/b.txt +4 -0
- data/test/rename_file.dir/c.txt +4 -0
- data/test/rename_file.dir/input +0 -0
- data/test/rename_file.dir/output +2 -0
- data/test/rename_file.dir/program.chirp +7 -0
- data/test/requires.rb +6 -0
- data/test/span.dir/input +0 -0
- data/test/span.dir/output +0 -0
- data/test/span.dir/program.chirp +1 -1
- data/test/span2.dir/input +0 -0
- data/test/span2.dir/output +0 -0
- data/test/span2.dir/program.chirp +3 -1
- data/test/string.dir/input +0 -0
- data/test/string.dir/output +0 -0
- data/test/string.dir/program.chirp +1 -1
- data/test/test_application.rb +14 -9
- data/test/test_fs_expression.rb +99 -0
- data/test/test_span.rb +36 -0
- metadata +64 -7
- data/lib/chirp/statement.rb +0 -91
- data/test/test_statement.rb +0 -118
File without changes
|
data/test/requires.rb
ADDED
data/test/span.dir/input
CHANGED
File without changes
|
data/test/span.dir/output
CHANGED
File without changes
|
data/test/span.dir/program.chirp
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
each_line :path=>'input', :start=>/start/, :end=>/end/
|
data/test/span2.dir/input
CHANGED
File without changes
|
data/test/span2.dir/output
CHANGED
File without changes
|
data/test/string.dir/input
CHANGED
File without changes
|
data/test/string.dir/output
CHANGED
File without changes
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
each_line :path=>'input', :match=>'abc'
|
data/test/test_application.rb
CHANGED
@@ -3,8 +3,12 @@
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'stringio'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'set'
|
7
|
+
require 'find'
|
8
|
+
require 'requires'
|
6
9
|
|
7
|
-
|
10
|
+
|
11
|
+
TEST_DIR=File.dirname(__FILE__) unless self.class.const_defined?(:TEST_DIR)
|
8
12
|
TEMP_DIR=File.join(TEST_DIR, 'temp')
|
9
13
|
|
10
14
|
class TestApplication < Test::Unit::TestCase
|
@@ -22,16 +26,17 @@ class TestApplication < Test::Unit::TestCase
|
|
22
26
|
FileUtils.cp_r(dir, TEMP_DIR)
|
23
27
|
|
24
28
|
program = File.read(File.join(TEMP_DIR, 'program.chirp'))
|
25
|
-
|
26
|
-
expected_output = File.read(File.join(TEMP_DIR, 'output'))
|
27
|
-
|
28
|
-
app = Application.new(program)
|
29
|
-
in_stream = StringIO.new(input)
|
30
|
-
out_stream = StringIO.new
|
29
|
+
output_stream = StringIO.new
|
31
30
|
|
32
|
-
|
31
|
+
app = Application.new
|
32
|
+
|
33
|
+
FileUtils.chdir(TEMP_DIR) do
|
34
|
+
app.program(File.read('program.chirp'))
|
35
|
+
app.execute($stdin, output_stream)
|
36
|
+
expected_output = File.read('output')
|
37
|
+
assert_equal(expected_output, output_stream.string)
|
38
|
+
end
|
33
39
|
|
34
|
-
assert_equal(expected_output, out_stream.string)
|
35
40
|
end
|
36
41
|
|
37
42
|
Dir.glob("#{TEST_DIR}/*.dir").each do |dir|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'chirp/fs_expression'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
|
8
|
+
TEST_DIR=File.dirname(__FILE__) unless self.class.const_defined?(:TEST_DIR)
|
9
|
+
|
10
|
+
def File.write(path, string='')
|
11
|
+
File.open(path, 'w') {|f| f.print(string)}
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
class TestFSExpression < Test::Unit::TestCase
|
17
|
+
|
18
|
+
include Chirp::FSSugar
|
19
|
+
|
20
|
+
def setup
|
21
|
+
FileUtils.chdir(TEST_DIR) do
|
22
|
+
File.write('empty_file')
|
23
|
+
File.write('one_byte', 'x')
|
24
|
+
File.write('one_line', "hello out there\n")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_length
|
29
|
+
assert eval_fs_expression(length(0), 'empty_file')
|
30
|
+
assert !eval_fs_expression(length(1), 'empty_file')
|
31
|
+
assert !eval_fs_expression(length(2), 'empty_file')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_bigger
|
35
|
+
assert !eval_fs_expression(bigger(0), 'empty_file')
|
36
|
+
assert eval_fs_expression(bigger(0), 'one_byte')
|
37
|
+
assert !eval_fs_expression(bigger(1), 'one_byte')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_smaller
|
41
|
+
assert !eval_fs_expression(smaller(0), 'empty_file')
|
42
|
+
assert eval_fs_expression(smaller(1), 'empty_file')
|
43
|
+
assert !eval_fs_expression(smaller(0), 'one_byte')
|
44
|
+
assert !eval_fs_expression(smaller(1), 'one_byte')
|
45
|
+
assert eval_fs_expression(smaller(10), 'one_byte')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_file
|
49
|
+
assert eval_fs_expression(file?, 'empty_file')
|
50
|
+
assert eval_fs_expression(file?, 'one_line')
|
51
|
+
assert !eval_fs_expression(file?, '.')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_dir
|
55
|
+
assert !eval_fs_expression(dir?, 'empty_file')
|
56
|
+
assert !eval_fs_expression(dir?, 'one_line')
|
57
|
+
assert eval_fs_expression(dir?, '.')
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_and
|
61
|
+
assert eval_fs_expression( all & all, 'empty_file')
|
62
|
+
assert ! eval_fs_expression( all & none, 'empty_file')
|
63
|
+
assert eval_fs_expression( file? & file?, 'empty_file')
|
64
|
+
assert ! eval_fs_expression( file? & dir?, 'empty_file')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_or
|
68
|
+
assert eval_fs_expression( all | all, 'empty_file')
|
69
|
+
assert eval_fs_expression( all | none, 'empty_file')
|
70
|
+
assert ! eval_fs_expression( none | none, 'empty_file')
|
71
|
+
assert eval_fs_expression( file? | file?, 'empty_file')
|
72
|
+
assert ! eval_fs_expression( none | dir?, 'empty_file')
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_contains
|
76
|
+
assert eval_fs_expression( contains(/hello/), 'one_line')
|
77
|
+
assert eval_fs_expression( contains(/out/), 'one_line')
|
78
|
+
assert eval_fs_expression( contains(/t[hH].*e/), 'one_line')
|
79
|
+
|
80
|
+
assert !eval_fs_expression( contains(/XX/), 'one_line')
|
81
|
+
assert !eval_fs_expression( contains(/foo/), 'one_line')
|
82
|
+
assert !eval_fs_expression( contains(/bar/), 'one_line')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_not
|
86
|
+
assert !eval_fs_expression( except(all), 'empty_file')
|
87
|
+
assert eval_fs_expression( except(none), 'empty_file')
|
88
|
+
assert eval_fs_expression( except(named('foo')), 'empty_file')
|
89
|
+
assert !eval_fs_expression( except(named('empty_file')), 'empty_file')
|
90
|
+
assert !eval_fs_expression( ~(named('empty_file')), 'empty_file')
|
91
|
+
end
|
92
|
+
|
93
|
+
def eval_fs_expression(expr, path)
|
94
|
+
FileUtils.chdir(TEST_DIR) do
|
95
|
+
return expr.evaluate(path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/test/test_span.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'chirp/context'
|
5
|
+
require 'chirp/span'
|
6
|
+
|
7
|
+
class TestSpan < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_span
|
10
|
+
|
11
|
+
c = Chirp::Context.new()
|
12
|
+
sp = Chirp::Span.new(10, /abc/)
|
13
|
+
c.line = 'junk'
|
14
|
+
|
15
|
+
0.upto(9) do |n|
|
16
|
+
c.line_no = n
|
17
|
+
assert ! sp.evaluate(c)
|
18
|
+
end
|
19
|
+
|
20
|
+
c.line_no = 10
|
21
|
+
assert sp.evaluate(c)
|
22
|
+
|
23
|
+
10.times do
|
24
|
+
c.line += 'X'
|
25
|
+
assert sp.evaluate(c)
|
26
|
+
end
|
27
|
+
|
28
|
+
c.line = 'this line matches abc 123'
|
29
|
+
assert sp.evaluate(c)
|
30
|
+
|
31
|
+
10.times do |n|
|
32
|
+
c.line = 'foo' + n.to_s
|
33
|
+
assert ! sp.evaluate(c)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: chirp
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: "0.3"
|
7
|
+
date: 2007-12-19 00:00:00 -05:00
|
8
8
|
summary: Chirp is a Ruby based text processing DSL similar to awk
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: russ@russolsen.com
|
12
12
|
homepage: http://www.zenspider.com/ZSS/Products/chirp/
|
13
13
|
rubyforge_project: chirp
|
14
|
-
description:
|
14
|
+
description: "== FEATURES/PROBLEMS: Chirp is a DSL for manipulating file systems. In the same way that rake is aimed at making system buildig easy, chirp is designed to make doing things to entire file systems easy. Chirp is still very much in development and you should be very careful with it: since chirp does operate on whole directory trees, it is capable of doing a lot of damage. == SYNOPSIS: FIX (code sample of usage)"
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -23,6 +23,9 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
23
23
|
version: 0.0.0
|
24
24
|
version:
|
25
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
26
29
|
authors:
|
27
30
|
- Russ Olsen
|
28
31
|
files:
|
@@ -33,8 +36,17 @@ files:
|
|
33
36
|
- bin/chirp
|
34
37
|
- lib/chirp.rb
|
35
38
|
- lib/chirp/application.rb
|
36
|
-
- lib/chirp/
|
37
|
-
-
|
39
|
+
- lib/chirp/pathmap.rb
|
40
|
+
- lib/chirp/context.rb
|
41
|
+
- lib/chirp/fs_expression.rb
|
42
|
+
- lib/chirp/span.rb
|
43
|
+
- lib/chirp/path_filter.rb
|
44
|
+
- test/copy_file.dir/output
|
45
|
+
- test/copy_file.dir/input
|
46
|
+
- test/copy_file.dir/program.chirp
|
47
|
+
- test/copy_file.dir/a.txt
|
48
|
+
- test/copy_file.dir/b.txt
|
49
|
+
- test/copy_file.dir/c.txt
|
38
50
|
- test/test_application.rb
|
39
51
|
- test/span.dir/output
|
40
52
|
- test/span.dir/input
|
@@ -81,9 +93,43 @@ files:
|
|
81
93
|
- test/account.dir/program.chirp
|
82
94
|
- test/account.dir/output
|
83
95
|
- test/account.dir/input
|
96
|
+
- test/path.dir/output
|
97
|
+
- test/path.dir/input
|
98
|
+
- test/path.dir/program.chirp
|
99
|
+
- test/path.dir/new
|
100
|
+
- test/path.dir/dir1/dir2/dir3/a.txt
|
101
|
+
- test/test_span.rb
|
102
|
+
- test/rename_file.dir/output
|
103
|
+
- test/rename_file.dir/input
|
104
|
+
- test/rename_file.dir/program.chirp
|
105
|
+
- test/rename_file.dir/a.txt
|
106
|
+
- test/rename_file.dir/b.txt
|
107
|
+
- test/rename_file.dir/c.txt
|
108
|
+
- test/copy1.dir/program.chirp
|
109
|
+
- test/copy1.dir/source
|
110
|
+
- test/copy1.dir/input
|
111
|
+
- test/copy1.dir/output
|
112
|
+
- test/copy2.dir/program.chirp
|
113
|
+
- test/copy2.dir/source
|
114
|
+
- test/copy2.dir/input
|
115
|
+
- test/copy2.dir/output
|
116
|
+
- test/copy3.dir/program.chirp
|
117
|
+
- test/copy3.dir/source
|
118
|
+
- test/copy3.dir/input
|
119
|
+
- test/copy3.dir/output
|
120
|
+
- test/test_fs_expression.rb
|
121
|
+
- test/fs_expr.dir/output
|
122
|
+
- test/fs_expr.dir/input
|
123
|
+
- test/fs_expr.dir/program.chirp
|
124
|
+
- test/fs_expr.dir/dir1/dir2/dir3/a.txt
|
125
|
+
- test/fs_expr.dir/bb.txt
|
126
|
+
- test/fs_expr.dir/aa.txt
|
127
|
+
- test/fs_expr.dir/cc.txt
|
128
|
+
- test/requires.rb
|
84
129
|
test_files:
|
85
|
-
- test/test_statement.rb
|
86
130
|
- test/test_application.rb
|
131
|
+
- test/test_fs_expression.rb
|
132
|
+
- test/test_span.rb
|
87
133
|
rdoc_options:
|
88
134
|
- --main
|
89
135
|
- README.txt
|
@@ -91,10 +137,21 @@ extra_rdoc_files:
|
|
91
137
|
- History.txt
|
92
138
|
- Manifest.txt
|
93
139
|
- README.txt
|
140
|
+
- test/copy_file.dir/a.txt
|
141
|
+
- test/copy_file.dir/b.txt
|
142
|
+
- test/copy_file.dir/c.txt
|
94
143
|
- test/inplace.dir/a.txt
|
95
144
|
- test/inplace.dir/b.txt
|
96
145
|
- test/files.dir/b.txt
|
97
146
|
- test/files.dir/a.txt
|
147
|
+
- test/path.dir/dir1/dir2/dir3/a.txt
|
148
|
+
- test/rename_file.dir/a.txt
|
149
|
+
- test/rename_file.dir/b.txt
|
150
|
+
- test/rename_file.dir/c.txt
|
151
|
+
- test/fs_expr.dir/dir1/dir2/dir3/a.txt
|
152
|
+
- test/fs_expr.dir/bb.txt
|
153
|
+
- test/fs_expr.dir/aa.txt
|
154
|
+
- test/fs_expr.dir/cc.txt
|
98
155
|
executables:
|
99
156
|
- chirp
|
100
157
|
extensions: []
|
data/lib/chirp/statement.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2006-2007 Russell Olsen
|
3
|
-
# Chirp is distributed under the same license as Ruby itself.
|
4
|
-
#
|
5
|
-
|
6
|
-
module Chirp
|
7
|
-
|
8
|
-
class StringPredicate
|
9
|
-
def initialize(string)
|
10
|
-
@string = string
|
11
|
-
end
|
12
|
-
|
13
|
-
def evaluate(context)
|
14
|
-
context.line == @string
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class LambdaPredicate
|
19
|
-
def initialize(proc)
|
20
|
-
@proc = proc
|
21
|
-
end
|
22
|
-
|
23
|
-
def evaluate(context)
|
24
|
-
context.execute(@proc)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class LineNumberPredicate
|
29
|
-
def initialize(line_no)
|
30
|
-
@line_no = line_no
|
31
|
-
end
|
32
|
-
|
33
|
-
def evaluate(context)
|
34
|
-
context.line_no == @line_no
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class MatchPredicate
|
39
|
-
def initialize(regex)
|
40
|
-
@regex = regex
|
41
|
-
end
|
42
|
-
|
43
|
-
def evaluate(context)
|
44
|
-
context.line =~ @regex
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class RangePredicate
|
49
|
-
def initialize(range)
|
50
|
-
@range = range
|
51
|
-
end
|
52
|
-
|
53
|
-
def evaluate(context)
|
54
|
-
@range.===(context.line_no)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class SpanPredicate
|
59
|
-
BEFORE_SPAN = 0
|
60
|
-
IN_SPAN = 1
|
61
|
-
AFTER_SPAN = 2
|
62
|
-
|
63
|
-
def initialize(p1, p2)
|
64
|
-
@p1 = p1
|
65
|
-
@p2 = p2
|
66
|
-
@state = BEFORE_SPAN
|
67
|
-
end
|
68
|
-
|
69
|
-
def evaluate(context)
|
70
|
-
if @state == BEFORE_SPAN
|
71
|
-
@state = IN_SPAN if @p1.evaluate(context)
|
72
|
-
end
|
73
|
-
ret = @state == IN_SPAN
|
74
|
-
if @state == IN_SPAN
|
75
|
-
@state = AFTER_SPAN if @p2.evaluate(context)
|
76
|
-
end
|
77
|
-
ret
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class Statement
|
82
|
-
def initialize(predicate, action)
|
83
|
-
@predicate = predicate
|
84
|
-
@action = action
|
85
|
-
end
|
86
|
-
|
87
|
-
def evaluate(context)
|
88
|
-
context.execute(@action) if @predicate.evaluate(context)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/test/test_statement.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'chirp/statement'
|
5
|
-
require 'chirp/application'
|
6
|
-
|
7
|
-
class TestContext
|
8
|
-
attr_accessor :line_no, :file, :line, :fields
|
9
|
-
attr_accessor :action
|
10
|
-
|
11
|
-
def initialize(line_no = nil, file=nil, line=nil, fields=nil)
|
12
|
-
@line_no = line_no
|
13
|
-
@file = file
|
14
|
-
@line = line
|
15
|
-
@fields = fields
|
16
|
-
end
|
17
|
-
|
18
|
-
def execute(action)
|
19
|
-
@action = action
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class TestStatement < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
end
|
27
|
-
|
28
|
-
def teardown
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_line_number_predicate
|
32
|
-
c = TestContext.new(10)
|
33
|
-
lnp = Chirp::LineNumberPredicate.new(10)
|
34
|
-
assert lnp.evaluate(c)
|
35
|
-
|
36
|
-
c.line_no = 88
|
37
|
-
assert ! lnp.evaluate(c)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_match_predicate
|
41
|
-
c = TestContext.new()
|
42
|
-
mp = Chirp::MatchPredicate.new(/abc/)
|
43
|
-
|
44
|
-
%w{ abc abcdef xyzabc }.each do |s|
|
45
|
-
c.line = s
|
46
|
-
assert mp.evaluate(c)
|
47
|
-
end
|
48
|
-
|
49
|
-
%w{ abXc axbxc x }.each do |s|
|
50
|
-
c.line = s
|
51
|
-
assert !mp.evaluate(c)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_span_predicate
|
56
|
-
|
57
|
-
c = TestContext.new()
|
58
|
-
p1 = Chirp::LineNumberPredicate.new(10)
|
59
|
-
p2 = Chirp::MatchPredicate.new(/abc/)
|
60
|
-
|
61
|
-
sp = Chirp::SpanPredicate.new(p1, p2)
|
62
|
-
c.line = 'junk'
|
63
|
-
|
64
|
-
0.upto(9) do |n|
|
65
|
-
c.line_no = n
|
66
|
-
assert ! sp.evaluate(c)
|
67
|
-
end
|
68
|
-
|
69
|
-
c.line_no = 10
|
70
|
-
assert sp.evaluate(c)
|
71
|
-
|
72
|
-
10.times do
|
73
|
-
c.line += 'X'
|
74
|
-
assert sp.evaluate(c)
|
75
|
-
end
|
76
|
-
|
77
|
-
c.line = 'this line matches abc 123'
|
78
|
-
assert sp.evaluate(c)
|
79
|
-
|
80
|
-
10.times do |n|
|
81
|
-
c.line = 'foo' + n.to_s
|
82
|
-
assert ! sp.evaluate(c)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_range_predicate
|
87
|
-
c = TestContext.new(10)
|
88
|
-
p = Chirp::RangePredicate.new(5..10)
|
89
|
-
|
90
|
-
0.upto(4) do |n|
|
91
|
-
c.line_no = n
|
92
|
-
assert ! p.evaluate(c)
|
93
|
-
end
|
94
|
-
|
95
|
-
5.upto(10) do |n|
|
96
|
-
c.line_no = n
|
97
|
-
assert p.evaluate(c)
|
98
|
-
end
|
99
|
-
|
100
|
-
11.upto(20) do |n|
|
101
|
-
c.line_no = n
|
102
|
-
assert ! p.evaluate(c)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_statement
|
107
|
-
c = TestContext.new(0)
|
108
|
-
|
109
|
-
s = Chirp::Statement.new( Chirp::LineNumberPredicate.new(10), 'action')
|
110
|
-
s.evaluate(c)
|
111
|
-
assert_nil c.action
|
112
|
-
|
113
|
-
c.line_no = 10
|
114
|
-
s.evaluate(c)
|
115
|
-
assert_equal 'action', c.action
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|