chirp 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/History.txt +10 -3
  2. data/Manifest.txt +49 -1
  3. data/README.txt +4 -4
  4. data/Rakefile +3 -3
  5. data/bin/chirp +42 -0
  6. data/lib/chirp.rb +5 -223
  7. data/lib/chirp/application.rb +252 -0
  8. data/lib/chirp/statement.rb +91 -0
  9. data/test/account.dir/input +7 -0
  10. data/test/account.dir/output +1 -0
  11. data/test/account.dir/program.chirp +20 -0
  12. data/test/action.dir/input +7 -0
  13. data/test/action.dir/output +1 -0
  14. data/test/action.dir/program.chirp +3 -0
  15. data/test/beforeafter.dir/input +7 -0
  16. data/test/beforeafter.dir/output +11 -0
  17. data/test/beforeafter.dir/program.chirp +7 -0
  18. data/test/fields.dir/input +3 -0
  19. data/test/fields.dir/output +3 -0
  20. data/test/fields.dir/program.chirp +5 -0
  21. data/test/fields_sep.dir/input +7 -0
  22. data/test/fields_sep.dir/output +7 -0
  23. data/test/fields_sep.dir/program.chirp +6 -0
  24. data/test/files.dir/a.ignore +1 -0
  25. data/test/files.dir/a.txt +1 -0
  26. data/test/files.dir/b.txt +1 -0
  27. data/test/files.dir/c.stuff +1 -0
  28. data/test/files.dir/input +7 -0
  29. data/test/files.dir/output +2 -0
  30. data/test/files.dir/program.chirp +6 -0
  31. data/test/inplace.dir/a.txt +1 -0
  32. data/test/inplace.dir/b.txt +1 -0
  33. data/test/inplace.dir/input +7 -0
  34. data/test/inplace.dir/output +3 -0
  35. data/test/inplace.dir/program.chirp +9 -0
  36. data/test/line_no.dir/input +7 -0
  37. data/test/line_no.dir/output +1 -0
  38. data/test/line_no.dir/program.chirp +1 -0
  39. data/test/match.dir/input +14 -0
  40. data/test/match.dir/output +6 -0
  41. data/test/match.dir/program.chirp +1 -0
  42. data/test/proc.dir/input +8 -0
  43. data/test/proc.dir/output +3 -0
  44. data/test/proc.dir/program.chirp +3 -0
  45. data/test/span.dir/input +13 -0
  46. data/test/span.dir/output +7 -0
  47. data/test/span.dir/program.chirp +1 -0
  48. data/test/span2.dir/input +7 -0
  49. data/test/span2.dir/output +5 -0
  50. data/test/span2.dir/program.chirp +1 -0
  51. data/test/string.dir/input +14 -0
  52. data/test/string.dir/output +6 -0
  53. data/test/string.dir/program.chirp +1 -0
  54. data/test/test_application.rb +42 -0
  55. data/test/test_statement.rb +118 -0
  56. metadata +60 -7
  57. data/test/test_chirp.rb +0 -0
@@ -0,0 +1,118 @@
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
metadata CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: chirp
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-11-09
8
- summary: The author was too lazy to write a summary
6
+ version: 0.2.0
7
+ date: 2007-11-25
8
+ summary: Chirp is a Ruby based text processing DSL similar to awk
9
9
  require_paths:
10
10
  - lib
11
- email: ryand-ruby@zenspider.com
11
+ email: russ@russolsen.com
12
12
  homepage: http://www.zenspider.com/ZSS/Products/chirp/
13
13
  rubyforge_project: chirp
14
14
  description: The author was too lazy to write a description
@@ -24,7 +24,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
24
24
  version:
25
25
  platform: ruby
26
26
  authors:
27
- - Ryan Davis
27
+ - Russ Olsen
28
28
  files:
29
29
  - History.txt
30
30
  - Manifest.txt
@@ -32,9 +32,58 @@ files:
32
32
  - Rakefile
33
33
  - bin/chirp
34
34
  - lib/chirp.rb
35
- - test/test_chirp.rb
35
+ - lib/chirp/application.rb
36
+ - lib/chirp/statement.rb
37
+ - test/test_statement.rb
38
+ - test/test_application.rb
39
+ - test/span.dir/output
40
+ - test/span.dir/input
41
+ - test/span.dir/program.chirp
42
+ - test/match.dir/output
43
+ - test/match.dir/program.chirp
44
+ - test/match.dir/input
45
+ - test/span2.dir/output
46
+ - test/span2.dir/input
47
+ - test/span2.dir/program.chirp
48
+ - test/line_no.dir/output
49
+ - test/line_no.dir/input
50
+ - test/line_no.dir/program.chirp
51
+ - test/inplace.dir/output
52
+ - test/inplace.dir/input
53
+ - test/inplace.dir/program.chirp
54
+ - test/inplace.dir/a.txt
55
+ - test/inplace.dir/b.txt
56
+ - test/beforeafter.dir/output
57
+ - test/beforeafter.dir/input
58
+ - test/beforeafter.dir/program.chirp
59
+ - test/action.dir/output
60
+ - test/action.dir/input
61
+ - test/action.dir/program.chirp
62
+ - test/fields.dir/output
63
+ - test/fields.dir/input
64
+ - test/fields.dir/program.chirp
65
+ - test/fields_sep.dir/output
66
+ - test/fields_sep.dir/input
67
+ - test/fields_sep.dir/program.chirp
68
+ - test/string.dir/output
69
+ - test/string.dir/input
70
+ - test/string.dir/program.chirp
71
+ - test/files.dir/output
72
+ - test/files.dir/input
73
+ - test/files.dir/program.chirp
74
+ - test/files.dir/b.txt
75
+ - test/files.dir/a.txt
76
+ - test/files.dir/c.stuff
77
+ - test/files.dir/a.ignore
78
+ - test/proc.dir/output
79
+ - test/proc.dir/input
80
+ - test/proc.dir/program.chirp
81
+ - test/account.dir/program.chirp
82
+ - test/account.dir/output
83
+ - test/account.dir/input
36
84
  test_files:
37
- - test/test_chirp.rb
85
+ - test/test_statement.rb
86
+ - test/test_application.rb
38
87
  rdoc_options:
39
88
  - --main
40
89
  - README.txt
@@ -42,6 +91,10 @@ extra_rdoc_files:
42
91
  - History.txt
43
92
  - Manifest.txt
44
93
  - README.txt
94
+ - test/inplace.dir/a.txt
95
+ - test/inplace.dir/b.txt
96
+ - test/files.dir/b.txt
97
+ - test/files.dir/a.txt
45
98
  executables:
46
99
  - chirp
47
100
  extensions: []
File without changes