glark 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/bin/glark +2 -2
  2. data/lib/glark.rb +1 -1
  3. data/lib/glark/app/app.rb +48 -0
  4. data/lib/glark/app/help.rb +103 -0
  5. data/lib/glark/app/info/options.rb +84 -0
  6. data/lib/glark/app/options.rb +201 -0
  7. data/lib/glark/app/rcfile.rb +49 -0
  8. data/lib/glark/app/runner.rb +140 -0
  9. data/lib/glark/app/spec.rb +19 -0
  10. data/lib/glark/input/filter/criteria_opts.rb +41 -0
  11. data/lib/glark/input/filter/dir_criteria_opts.rb +37 -0
  12. data/lib/glark/input/filter/file_criteria_opts.rb +33 -0
  13. data/lib/glark/input/filter/filter.rb +59 -0
  14. data/lib/glark/input/filter/options.rb +171 -0
  15. data/lib/glark/input/options.rb +120 -0
  16. data/lib/glark/input/range.rb +104 -0
  17. data/lib/glark/input/spec.rb +39 -0
  18. data/lib/glark/io/file/archive_file.rb +64 -0
  19. data/lib/glark/io/file/binary_file.rb +19 -0
  20. data/lib/glark/io/file/file.rb +57 -0
  21. data/lib/glark/io/file/gz_file.rb +21 -0
  22. data/lib/glark/io/file/tar_file.rb +35 -0
  23. data/lib/glark/io/file/tar_gz_file.rb +52 -0
  24. data/lib/glark/io/file/zip_file.rb +39 -0
  25. data/lib/glark/match/and.rb +83 -0
  26. data/lib/glark/match/and_distance.rb +58 -0
  27. data/lib/glark/match/compound.rb +34 -0
  28. data/lib/glark/match/expression.rb +63 -0
  29. data/lib/glark/match/factory.rb +173 -0
  30. data/lib/glark/match/ior.rb +20 -0
  31. data/lib/glark/match/options.rb +74 -0
  32. data/lib/glark/match/or.rb +41 -0
  33. data/lib/glark/match/re.rb +81 -0
  34. data/lib/glark/match/re_factory.rb +44 -0
  35. data/lib/glark/match/spec.rb +59 -0
  36. data/lib/glark/match/xor.rb +20 -0
  37. data/lib/glark/output/binary_file_summary.rb +17 -0
  38. data/lib/glark/output/common.rb +43 -0
  39. data/lib/glark/output/context.rb +57 -0
  40. data/lib/glark/output/count.rb +26 -0
  41. data/lib/glark/output/file_header.rb +20 -0
  42. data/lib/glark/output/file_name_only.rb +35 -0
  43. data/lib/glark/output/formatted.rb +22 -0
  44. data/lib/glark/output/glark_count.rb +23 -0
  45. data/lib/glark/output/glark_format.rb +62 -0
  46. data/lib/glark/output/glark_lines.rb +36 -0
  47. data/lib/glark/output/grep_count.rb +18 -0
  48. data/lib/glark/output/grep_lines.rb +42 -0
  49. data/lib/glark/output/line_status.rb +46 -0
  50. data/lib/glark/output/lines.rb +100 -0
  51. data/lib/glark/output/match_list.rb +15 -0
  52. data/lib/glark/output/options.rb +103 -0
  53. data/lib/glark/output/results.rb +23 -0
  54. data/lib/glark/output/spec.rb +105 -0
  55. data/lib/glark/output/unfiltered_lines.rb +28 -0
  56. data/lib/glark/util/colors/options.rb +143 -0
  57. data/lib/glark/util/colors/spec.rb +21 -0
  58. data/lib/glark/util/highlight.rb +108 -0
  59. data/lib/glark/util/io/depth.rb +29 -0
  60. data/lib/glark/util/io/fileset.rb +162 -0
  61. data/lib/glark/util/io/filter/criteria.rb +49 -0
  62. data/lib/glark/util/io/filter/filter.rb +10 -0
  63. data/lib/glark/util/io/lines.rb +117 -0
  64. data/lib/glark/util/option.rb +34 -0
  65. data/lib/glark/util/options.rb +12 -0
  66. data/lib/glark/util/optutil.rb +69 -0
  67. data/lib/glark/util/timestamper.rb +18 -0
  68. data/man/glark.1 +1134 -0
  69. data/test/glark/app/and_test.rb +82 -0
  70. data/test/glark/app/compound_test.rb +33 -0
  71. data/test/glark/app/context_test.rb +43 -0
  72. data/test/glark/app/count_test.rb +89 -0
  73. data/test/glark/app/dump_test.rb +16 -0
  74. data/test/glark/app/expression_file_test.rb +22 -0
  75. data/test/glark/app/extended_regexp_test.rb +17 -0
  76. data/test/glark/app/extract_matches_test.rb +27 -0
  77. data/test/glark/app/files_with_match_test.rb +32 -0
  78. data/test/glark/app/files_without_match_test.rb +26 -0
  79. data/test/glark/app/filter_test.rb +118 -0
  80. data/test/glark/app/highlight_test.rb +78 -0
  81. data/test/glark/app/ignore_case_test.rb +22 -0
  82. data/test/glark/app/invert_test.rb +49 -0
  83. data/test/glark/app/ior_test.rb +21 -0
  84. data/test/glark/app/label_test.rb +28 -0
  85. data/test/glark/app/line_number_color_test.rb +42 -0
  86. data/test/glark/app/line_numbers_test.rb +42 -0
  87. data/test/glark/app/match_limit_test.rb +49 -0
  88. data/test/glark/app/options_test.rb +722 -0
  89. data/test/glark/app/range_test.rb +101 -0
  90. data/test/glark/app/rcfile_test.rb +113 -0
  91. data/test/glark/app/record_separator_test.rb +32 -0
  92. data/test/glark/app/regexp_test.rb +48 -0
  93. data/test/glark/app/tc.rb +92 -0
  94. data/test/glark/app/text_color_test.rb +31 -0
  95. data/test/glark/app/whole_lines_test.rb +17 -0
  96. data/test/glark/app/whole_words_test.rb +42 -0
  97. data/test/glark/app/xor_test.rb +19 -0
  98. data/test/glark/input/binary_file_test.rb +0 -0
  99. data/test/glark/input/directory_test.rb +202 -0
  100. data/test/glark/input/dirname_test.rb +69 -0
  101. data/test/glark/input/exclude_matching_test.rb +20 -0
  102. data/test/glark/input/ext_test.rb +65 -0
  103. data/test/glark/input/filter/criteria_test.rb +91 -0
  104. data/test/glark/input/filter/filter_spec_test.rb +27 -0
  105. data/test/glark/input/filter/filter_test.rb +21 -0
  106. data/test/glark/input/name_test.rb +75 -0
  107. data/test/glark/input/path_test.rb +72 -0
  108. data/test/glark/input/range_test.rb +82 -0
  109. data/test/glark/input/size_limit_test.rb +51 -0
  110. data/test/glark/input/split_as_path_test.rb +28 -0
  111. data/test/glark/match_test.rb +192 -0
  112. data/test/glark/resources.rb +21 -0
  113. data/test/glark/tc.rb +37 -0
  114. data/test/resources/add.rb +10 -0
  115. data/test/resources/echo.rb +2 -0
  116. data/test/resources/greet.rb +13 -0
  117. metadata +198 -28
  118. data/README +0 -0
  119. data/bin/jlark +0 -63
  120. data/lib/glark/expression.rb +0 -440
  121. data/lib/glark/exprfactory.rb +0 -248
  122. data/lib/glark/glark.rb +0 -297
  123. data/lib/glark/help.rb +0 -85
  124. data/lib/glark/input.rb +0 -183
  125. data/lib/glark/options.rb +0 -757
  126. data/lib/glark/output.rb +0 -266
  127. data/test/lib/glark/glark_test.rb +0 -317
  128. data/test/lib/glark/options_test.rb +0 -891
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'glark/app/tc'
5
+
6
+ module Glark
7
+ class ExclusiveOrTestCase < AppTestCase
8
+ def test_simple
9
+ fname = '/proj/org/incava/glark/test/resources/textfile.txt'
10
+ expected = [
11
+ " 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
12
+ " 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
13
+ " 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
14
+ " 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
15
+ ]
16
+ run_app_test expected, [ '--xor', '\b6\d{4}\b', 'TheM.*Tale' ], fname
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'glark/app/tc'
5
+
6
+ module Glark
7
+ class DirectoryTestCase < AppTestCase
8
+ def run_directory_list_test args
9
+ dirname = '/proj/org/incava/glark/test/resources'
10
+ expected = [
11
+ '/proj/org/incava/glark/test/resources/filelist.txt',
12
+ ' 9 08-The_Sompnours_Tale.txt',
13
+ ' 12 11-The_Squires_Tale.txt',
14
+ ' 16 15-The_Shipmans_Tale.txt',
15
+ ' 22 21-The_Second_Nuns_Tale.txt',
16
+ '/proj/org/incava/glark/test/resources/spaces.txt',
17
+ ' 9 08 The Sompnours Tale.txt',
18
+ ' 12 11 The Squires Tale.txt',
19
+ ' 16 15 The Shipmans Tale.txt',
20
+ ' 22 21 The Second Nuns Tale.txt',
21
+ '/proj/org/incava/glark/test/resources/textfile.txt',
22
+ ' 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt',
23
+ ' 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt',
24
+ ' 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt',
25
+ ' 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt',
26
+ ]
27
+ run_app_test expected, args + [ 'The.*S.*Tale' ], dirname
28
+ end
29
+
30
+ def test_default
31
+ run_directory_list_test Array.new
32
+ end
33
+
34
+ def test_list
35
+ run_directory_list_test %w{ --directories=list }
36
+ end
37
+
38
+ def test_recurse_as_option
39
+ dirname = '/proj/org/incava/glark/test/resources'
40
+ expected = [
41
+ "/proj/org/incava/glark/test/resources/add.rb",
42
+ " 5 def initialize x, y",
43
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
44
+ " 298 For th' horizon had reft the sun his light",
45
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
46
+ " 248 Of yeddings he bare utterly the prize.",
47
+ " 253 Better than a lazar or a beggere,",
48
+ " 256 To have with such lazars acquaintance.",
49
+ " 330 Justice he was full often in assize,",
50
+ " 605 Of which there was a dozen in that house,",
51
+ "/proj/org/incava/glark/test/resources/greet.rb",
52
+ " 8 def initialize name",
53
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
54
+ " 8 size-limit: 1000",
55
+ "/proj/org/incava/glark/test/resources/zfile.txt",
56
+ " 1 zaffres",
57
+ " 2 zoaea",
58
+ " 3 zoaea's",
59
+ " 4 zoea",
60
+ " 5 zoeas",
61
+ " 6 zonulae",
62
+ " 7 zooea",
63
+ " 8 zooeae",
64
+ " 9 zooeal",
65
+ " 10 zooeas",
66
+ " 11 zooecia",
67
+ " 12 zooecium",
68
+ " 13 zoogloeae",
69
+ " 14 zoogloeal",
70
+ " 15 zoogloeas",
71
+ " 16 zygaenid",
72
+ ]
73
+ run_app_test expected, [ '--directories=recurse', 'z.*e' ], dirname
74
+ end
75
+
76
+ def run_recurse_ellipses_all_expected dirname
77
+ expected = [
78
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/prologue.txt",
79
+ " 60 Have me excused of my rude speech.",
80
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
81
+ " 530 Phoebus wax'd old, and hued like latoun,",
82
+ " 560 Neither his collect, nor his expanse years,",
83
+ " 567 From the head of that fix'd Aries above,",
84
+ " 706 Why should I more examples hereof sayn?",
85
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
86
+ " 187 He gave not of the text a pulled hen,",
87
+ " 192 This ilke text held he not worth an oyster;",
88
+ " 291 Betwixte Middleburg and Orewell",
89
+ " 292 Well could he in exchange shieldes sell",
90
+ " 300 A CLERK there was of Oxenford also,",
91
+ " 327 There was also, full rich of excellence.",
92
+ " 417 From Bourdeaux-ward, while that the chapmen sleep;",
93
+ " 578 His beard as any sow or fox was red,",
94
+ " 604 That were of law expert and curious:",
95
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
96
+ " 10 text-color-3: underline magenta",
97
+ ]
98
+ run_app_test expected, [ 'x.*e\w' ], dirname
99
+ end
100
+
101
+ def test_recurse_ellipses_no_limit
102
+ dirname = '/proj/org/incava/glark/test/resources/...'
103
+ run_recurse_ellipses_all_expected dirname
104
+ end
105
+
106
+ def test_recurse_ellipses_limit_zero
107
+ dirname = '/proj/org/incava/glark/test/resources/...0'
108
+ expected = [
109
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
110
+ " 10 text-color-3: underline magenta",
111
+ ]
112
+ run_app_test expected, [ 'x.*e\w' ], dirname
113
+ end
114
+
115
+ def test_recurse_ellipses_limit_one
116
+ dirname = '/proj/org/incava/glark/test/resources/...1'
117
+ expected = [
118
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
119
+ " 187 He gave not of the text a pulled hen,",
120
+ " 192 This ilke text held he not worth an oyster;",
121
+ " 291 Betwixte Middleburg and Orewell",
122
+ " 292 Well could he in exchange shieldes sell",
123
+ " 300 A CLERK there was of Oxenford also,",
124
+ " 327 There was also, full rich of excellence.",
125
+ " 417 From Bourdeaux-ward, while that the chapmen sleep;",
126
+ " 578 His beard as any sow or fox was red,",
127
+ " 604 That were of law expert and curious:",
128
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
129
+ " 10 text-color-3: underline magenta",
130
+ ]
131
+ run_app_test expected, [ 'x.*e\w' ], dirname
132
+ end
133
+
134
+ def test_recurse_ellipses_limit_two
135
+ dirname = '/proj/org/incava/glark/test/resources/...2'
136
+ run_recurse_ellipses_all_expected dirname
137
+ end
138
+
139
+ def test_skip
140
+ dirname = '/proj/org/incava/glark/test/resources'
141
+ expected = [ ]
142
+ run_app_test expected, [ '--directories=skip', 'The.*Tale' ], dirname
143
+ end
144
+
145
+ def test_list_no_files_in_directory
146
+ dirname = '/proj/org/incava/glark/test'
147
+ expected = [ ]
148
+ run_app_test expected, [ '--directories=list', 'The.*Tale' ], dirname
149
+ end
150
+
151
+ def test_recurse_from_current_dir
152
+ origdir = Dir.pwd
153
+ Dir.chdir '/proj/org/incava/glark/test/resources'
154
+ dirname = '.'
155
+ expected = [
156
+ "filelist.txt",
157
+ " 23 22-The_Canons_Yeomans_Tale.txt",
158
+ "spaces.txt",
159
+ " 23 22 The Canons Yeomans Tale.txt",
160
+ "textfile.txt",
161
+ " 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
162
+ ]
163
+ run_app_test expected, [ '-r', 'The.*Y.*Tale' ], dirname
164
+ Dir.chdir origdir
165
+ end
166
+
167
+ def test_list_with_binaries_read_skip_unreadable
168
+ dirname = '/proj/org/incava/glark/test/resources/...'
169
+ expected = [
170
+ '/proj/org/incava/glark/test/resources/filelist.txt',
171
+ ' 23 22-The_Canons_Yeomans_Tale.txt',
172
+ '/proj/org/incava/glark/test/resources/spaces.txt',
173
+ ' 23 22 The Canons Yeomans Tale.txt',
174
+ '/proj/org/incava/glark/test/resources/textfile.txt',
175
+ ' 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt',
176
+ '/proj/org/incava/glark/test/resources/textfile.txt.gz',
177
+ ' 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt',
178
+ 'filelist.txt (in /proj/org/incava/glark/test/resources/txt.tgz)',
179
+ ' 23 22-The_Canons_Yeomans_Tale.txt',
180
+ ]
181
+ run_app_test expected, [ '-r', '--binary-files=read', 'The.*Y.*Tale' ], dirname
182
+ end
183
+
184
+ def test_list_with_binaries_list_skip_unreadable
185
+ dirname = '/proj/org/incava/glark/test/resources/...'
186
+ expected = [
187
+ '/proj/org/incava/glark/test/resources/aaa.zip',
188
+ ' 1 abcfile.txt',
189
+ '/proj/org/incava/glark/test/resources/rc.tar',
190
+ ' 1 rcext.txt',
191
+ ' 2 rcfile.txt',
192
+ ' 3 rcgrep.txt',
193
+ ' 4 rcmatch.txt',
194
+ ' 5 rcpath.txt',
195
+ '/proj/org/incava/glark/test/resources/txt.tgz',
196
+ ' 1 filelist.txt',
197
+ ' 2 rcext.txt',
198
+ ]
199
+ run_app_test expected, [ '-r', '--binary-files=list', '^\w+\.txt$' ], dirname
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'glark/app/tc'
5
+
6
+ module Glark
7
+ class DirNameTestCase < AppTestCase
8
+ def test_skip_svn
9
+ dirname = '/proj/org/incava/glark/test/resources'
10
+ expected = [
11
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
12
+ " 10 That well unnethes durst this knight for dread,",
13
+ " 149 Why have ye wrought this work unreasonable?",
14
+ " 366 Let I this woeful creature lie;",
15
+ ]
16
+ run_app_test expected, [ '--directories=recurse', 'this.*rea' ], dirname
17
+ end
18
+
19
+ def test_match_basename
20
+ dirnames = [ '/proj/org/incava/glark/test/resources/canterbury', '/proj/org/incava/glark/test/glark' ]
21
+ expected = [
22
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
23
+ " 187 He gave not of the text a pulled hen,",
24
+ " 192 This ilke text held he not worth an oyster;",
25
+ " 291 Betwixte Middleburg and Orewell",
26
+ ]
27
+ run_app_test expected, [ '-r', '--match-dirname=canterbury', 'xt.*e' ], *dirnames
28
+ end
29
+
30
+ def test_not_basename
31
+ dirnames = [ '/proj/org/incava/glark/test' ]
32
+ expected = [
33
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
34
+ " 80 That is betwixt a husband and his wife?",
35
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
36
+ " 187 He gave not of the text a pulled hen,",
37
+ " 192 This ilke text held he not worth an oyster;",
38
+ " 291 Betwixte Middleburg and Orewell",
39
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
40
+ " 10 text-color-3: underline magenta",
41
+ ]
42
+ run_app_test expected, [ '-r', '--skip-dirname=glark', 'xt.*e' ], *dirnames
43
+ end
44
+
45
+ def test_match_pathname
46
+ dirnames = [ '/proj/org/incava/glark/test/glark', '/proj/org/incava/glark/test/resources' ]
47
+ expected = [
48
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
49
+ " 10 text-color-3: underline magenta",
50
+ ]
51
+ run_app_test expected, [ '-r', '--match-dirpath', '^.*es$', 'xt.*e' ], *dirnames
52
+ end
53
+
54
+ def test_not_pathname
55
+ dirnames = [ '/proj/org/incava/glark/test/glark', '/proj/org/incava/glark/test/resources' ]
56
+ expected = [
57
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
58
+ " 80 That is betwixt a husband and his wife?",
59
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
60
+ " 187 He gave not of the text a pulled hen,",
61
+ " 192 This ilke text held he not worth an oyster;",
62
+ " 291 Betwixte Middleburg and Orewell",
63
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
64
+ " 10 text-color-3: underline magenta",
65
+ ]
66
+ run_app_test expected, [ '-r', '--skip-dirpath', 'test/glark', 'xt.*e' ], *dirnames
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'glark/app/tc'
5
+
6
+ module Glark
7
+ class ExcludeMatchingTestCase < AppTestCase
8
+ def test_simple
9
+ dirname = '/proj/org/incava/glark/test/resources'
10
+ expected = [
11
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
12
+ " 187 He gave not of the text a pulled hen,",
13
+ " 192 This ilke text held he not worth an oyster;",
14
+ "/proj/org/incava/glark/test/resources/rcfile.txt",
15
+ " 10 text-color-3: underline magenta",
16
+ ]
17
+ run_app_test expected, [ '-r', '--exclude-matching', 'text' ], dirname
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'glark/app/tc'
5
+
6
+ module Glark
7
+ class ExtTestCase < AppTestCase
8
+ def test_match_single
9
+ dirname = '/proj/org/incava/glark/test/resources'
10
+ expected = [
11
+ "/proj/org/incava/glark/test/resources/add.rb",
12
+ " 5 def initialize x, y",
13
+ "/proj/org/incava/glark/test/resources/greet.rb",
14
+ " 8 def initialize name",
15
+ " 9 puts \"hello, \" + name",
16
+ " 13 Greet.new ARGV.shift || \"world\"",
17
+ ]
18
+ run_app_test expected, [ '-r', '--match-ext', 'rb', 't.*e' ], dirname
19
+ end
20
+
21
+ def test_not_single
22
+ dirname = '/proj/org/incava/glark/test/resources'
23
+ expected = [
24
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/prologue.txt",
25
+ " 60 Have me excused of my rude speech.",
26
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
27
+ " 184 And this was on the sixth morrow of May,",
28
+ " 560 Neither his collect, nor his expanse years,",
29
+ " 706 Why should I more examples hereof sayn?",
30
+ " 813 Than to depart the love betwixt you two.",
31
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
32
+ " 192 This ilke text held he not worth an oyster;",
33
+ ]
34
+ run_app_test expected, [ '-r', '--skip-ext', 'rb', 'x.*y' ], dirname
35
+ end
36
+
37
+ def test_match_multiple
38
+ dirname = '/proj/org/incava/glark/test/resources'
39
+ expected = [
40
+ "/proj/org/incava/glark/test/resources/add.rb",
41
+ " 5 def initialize x, y",
42
+ " 6 puts x.to_s + \" + \" + y.to_s + \" = \" + (x.to_i + y.to_i).to_s",
43
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/prologue.txt",
44
+ " 60 Have me excused of my rude speech.",
45
+ "/proj/org/incava/glark/test/resources/canterbury/franklin/tale.txt",
46
+ " 184 And this was on the sixth morrow of May,",
47
+ " 560 Neither his collect, nor his expanse years,",
48
+ " 706 Why should I more examples hereof sayn?",
49
+ " 813 Than to depart the love betwixt you two.",
50
+ "/proj/org/incava/glark/test/resources/canterbury/prologue.txt",
51
+ " 192 This ilke text held he not worth an oyster;",
52
+ ]
53
+ run_app_test expected, [ '-r', '--match-ext', 'rb', '--match-ext', 'txt', 'x.*y' ], dirname
54
+ end
55
+
56
+ def test_not_multiple
57
+ dirname = '/proj/org/incava/glark/test/resources'
58
+ expected = [
59
+ "/proj/org/incava/glark/test/resources/cat.pl",
60
+ " 6 print <>;",
61
+ ]
62
+ run_app_test expected, [ '-r', '--skip-ext', 'rb', '--not-ext', 'txt', 'p.*t' ], dirname
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'glark/app/tc'
5
+ require 'glark/util/io/filter/criteria'
6
+ require 'glark/input/filter/filter'
7
+
8
+ module Glark
9
+ class CriteriaTestCase < AppTestCase
10
+ def test_positive_one_match
11
+ crit = Criteria.new
12
+ crit.add :name, :positive, BaseNameFilter.new('foo.txt')
13
+
14
+ assert crit.match?(Pathname.new '/path/to/foo.txt')
15
+ end
16
+
17
+ def test_positive_one_nomatch
18
+ crit = Criteria.new
19
+ crit.add :name, :positive, BaseNameFilter.new('foo.txt')
20
+
21
+ assert !crit.match?(Pathname.new '/path/to/bar.txt')
22
+ end
23
+
24
+ def test_negative_one_match
25
+ crit = Criteria.new
26
+ crit.add :name, :negative, BaseNameFilter.new('foo.txt')
27
+
28
+ assert !crit.match?(Pathname.new '/path/to/foo.txt')
29
+ end
30
+
31
+ def test_negative_one_nomatch
32
+ crit = Criteria.new
33
+ crit.add :name, :negative, BaseNameFilter.new('foo.txt')
34
+
35
+ assert crit.match?(Pathname.new '/path/to/bar.txt')
36
+ end
37
+
38
+ def test_positive_two_match
39
+ crit = Criteria.new
40
+ crit.add :name, :positive, BaseNameFilter.new(%r{foo.*})
41
+ crit.add :ext, :positive, ExtFilter.new('txt')
42
+
43
+ assert crit.match?(Pathname.new '/path/to/foo.txt')
44
+ end
45
+
46
+ def test_positive_two_nomatch
47
+ crit = Criteria.new
48
+ crit.add :name, :positive, BaseNameFilter.new(%r{foo.*})
49
+ crit.add :ext, :positive, ExtFilter.new('rb')
50
+
51
+ assert crit.match?(Pathname.new '/path/to/foo.rb')
52
+ end
53
+
54
+ def test_positive_negative_match
55
+ crit = Criteria.new
56
+ crit.add :name, :positive, BaseNameFilter.new(%r{foo.*})
57
+ crit.add :ext, :negative, ExtFilter.new('txt')
58
+
59
+ assert crit.match?(Pathname.new '/path/to/foo.rb')
60
+ end
61
+
62
+ def test_positive_negative_nomatch
63
+ crit = Criteria.new
64
+ crit.add :name, :positive, BaseNameFilter.new(%r{foo.*})
65
+ crit.add :ext, :negative, ExtFilter.new('rb')
66
+
67
+ assert !crit.match?(Pathname.new '/path/to/foo.rb')
68
+ end
69
+
70
+ def test_find_by_class
71
+ fl = Criteria.new
72
+ bnf = BaseNameFilter.new '.svn'
73
+ fl.add :name, :negative, bnf
74
+ assert_equal bnf.object_id, fl.find_by_class(:name, :negative, BaseNameFilter).object_id
75
+ end
76
+
77
+ def test_add
78
+ fl = Criteria.new
79
+ svnbnf = BaseNameFilter.new '.svn'
80
+ fl.add :name, :negative, svnbnf
81
+ bldbnf = BaseNameFilter.new 'build'
82
+ fl.add :name, :negative, bldbnf
83
+
84
+ slf = SizeLimitFilter.new 1000
85
+ fl.add :size, :negative, slf
86
+
87
+ extf = ExtFilter.new 'rb'
88
+ fl.add :ext, :positive, extf
89
+ end
90
+ end
91
+ end