glark 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/glark +2 -2
- data/lib/glark.rb +1 -1
- data/lib/glark/app/app.rb +48 -0
- data/lib/glark/app/help.rb +103 -0
- data/lib/glark/app/info/options.rb +84 -0
- data/lib/glark/app/options.rb +201 -0
- data/lib/glark/app/rcfile.rb +49 -0
- data/lib/glark/app/runner.rb +140 -0
- data/lib/glark/app/spec.rb +19 -0
- data/lib/glark/input/filter/criteria_opts.rb +41 -0
- data/lib/glark/input/filter/dir_criteria_opts.rb +37 -0
- data/lib/glark/input/filter/file_criteria_opts.rb +33 -0
- data/lib/glark/input/filter/filter.rb +59 -0
- data/lib/glark/input/filter/options.rb +171 -0
- data/lib/glark/input/options.rb +120 -0
- data/lib/glark/input/range.rb +104 -0
- data/lib/glark/input/spec.rb +39 -0
- data/lib/glark/io/file/archive_file.rb +64 -0
- data/lib/glark/io/file/binary_file.rb +19 -0
- data/lib/glark/io/file/file.rb +57 -0
- data/lib/glark/io/file/gz_file.rb +21 -0
- data/lib/glark/io/file/tar_file.rb +35 -0
- data/lib/glark/io/file/tar_gz_file.rb +52 -0
- data/lib/glark/io/file/zip_file.rb +39 -0
- data/lib/glark/match/and.rb +83 -0
- data/lib/glark/match/and_distance.rb +58 -0
- data/lib/glark/match/compound.rb +34 -0
- data/lib/glark/match/expression.rb +63 -0
- data/lib/glark/match/factory.rb +173 -0
- data/lib/glark/match/ior.rb +20 -0
- data/lib/glark/match/options.rb +74 -0
- data/lib/glark/match/or.rb +41 -0
- data/lib/glark/match/re.rb +81 -0
- data/lib/glark/match/re_factory.rb +44 -0
- data/lib/glark/match/spec.rb +59 -0
- data/lib/glark/match/xor.rb +20 -0
- data/lib/glark/output/binary_file_summary.rb +17 -0
- data/lib/glark/output/common.rb +43 -0
- data/lib/glark/output/context.rb +57 -0
- data/lib/glark/output/count.rb +26 -0
- data/lib/glark/output/file_header.rb +20 -0
- data/lib/glark/output/file_name_only.rb +35 -0
- data/lib/glark/output/formatted.rb +22 -0
- data/lib/glark/output/glark_count.rb +23 -0
- data/lib/glark/output/glark_format.rb +62 -0
- data/lib/glark/output/glark_lines.rb +36 -0
- data/lib/glark/output/grep_count.rb +18 -0
- data/lib/glark/output/grep_lines.rb +42 -0
- data/lib/glark/output/line_status.rb +46 -0
- data/lib/glark/output/lines.rb +100 -0
- data/lib/glark/output/match_list.rb +15 -0
- data/lib/glark/output/options.rb +103 -0
- data/lib/glark/output/results.rb +23 -0
- data/lib/glark/output/spec.rb +105 -0
- data/lib/glark/output/unfiltered_lines.rb +28 -0
- data/lib/glark/util/colors/options.rb +143 -0
- data/lib/glark/util/colors/spec.rb +21 -0
- data/lib/glark/util/highlight.rb +108 -0
- data/lib/glark/util/io/depth.rb +29 -0
- data/lib/glark/util/io/fileset.rb +162 -0
- data/lib/glark/util/io/filter/criteria.rb +49 -0
- data/lib/glark/util/io/filter/filter.rb +10 -0
- data/lib/glark/util/io/lines.rb +117 -0
- data/lib/glark/util/option.rb +34 -0
- data/lib/glark/util/options.rb +12 -0
- data/lib/glark/util/optutil.rb +69 -0
- data/lib/glark/util/timestamper.rb +18 -0
- data/man/glark.1 +1134 -0
- data/test/glark/app/and_test.rb +82 -0
- data/test/glark/app/compound_test.rb +33 -0
- data/test/glark/app/context_test.rb +43 -0
- data/test/glark/app/count_test.rb +89 -0
- data/test/glark/app/dump_test.rb +16 -0
- data/test/glark/app/expression_file_test.rb +22 -0
- data/test/glark/app/extended_regexp_test.rb +17 -0
- data/test/glark/app/extract_matches_test.rb +27 -0
- data/test/glark/app/files_with_match_test.rb +32 -0
- data/test/glark/app/files_without_match_test.rb +26 -0
- data/test/glark/app/filter_test.rb +118 -0
- data/test/glark/app/highlight_test.rb +78 -0
- data/test/glark/app/ignore_case_test.rb +22 -0
- data/test/glark/app/invert_test.rb +49 -0
- data/test/glark/app/ior_test.rb +21 -0
- data/test/glark/app/label_test.rb +28 -0
- data/test/glark/app/line_number_color_test.rb +42 -0
- data/test/glark/app/line_numbers_test.rb +42 -0
- data/test/glark/app/match_limit_test.rb +49 -0
- data/test/glark/app/options_test.rb +722 -0
- data/test/glark/app/range_test.rb +101 -0
- data/test/glark/app/rcfile_test.rb +113 -0
- data/test/glark/app/record_separator_test.rb +32 -0
- data/test/glark/app/regexp_test.rb +48 -0
- data/test/glark/app/tc.rb +92 -0
- data/test/glark/app/text_color_test.rb +31 -0
- data/test/glark/app/whole_lines_test.rb +17 -0
- data/test/glark/app/whole_words_test.rb +42 -0
- data/test/glark/app/xor_test.rb +19 -0
- data/test/glark/input/binary_file_test.rb +0 -0
- data/test/glark/input/directory_test.rb +202 -0
- data/test/glark/input/dirname_test.rb +69 -0
- data/test/glark/input/exclude_matching_test.rb +20 -0
- data/test/glark/input/ext_test.rb +65 -0
- data/test/glark/input/filter/criteria_test.rb +91 -0
- data/test/glark/input/filter/filter_spec_test.rb +27 -0
- data/test/glark/input/filter/filter_test.rb +21 -0
- data/test/glark/input/name_test.rb +75 -0
- data/test/glark/input/path_test.rb +72 -0
- data/test/glark/input/range_test.rb +82 -0
- data/test/glark/input/size_limit_test.rb +51 -0
- data/test/glark/input/split_as_path_test.rb +28 -0
- data/test/glark/match_test.rb +192 -0
- data/test/glark/resources.rb +21 -0
- data/test/glark/tc.rb +37 -0
- data/test/resources/add.rb +10 -0
- data/test/resources/echo.rb +2 -0
- data/test/resources/greet.rb +13 -0
- metadata +198 -28
- data/README +0 -0
- data/bin/jlark +0 -63
- data/lib/glark/expression.rb +0 -440
- data/lib/glark/exprfactory.rb +0 -248
- data/lib/glark/glark.rb +0 -297
- data/lib/glark/help.rb +0 -85
- data/lib/glark/input.rb +0 -183
- data/lib/glark/options.rb +0 -757
- data/lib/glark/output.rb +0 -266
- data/test/lib/glark/glark_test.rb +0 -317
- data/test/lib/glark/options_test.rb +0 -891
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class AndTestCase < AppTestCase
|
8
|
+
def test_one_line
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 6 -rw-r--r-- 1 jpace jpace [30m[43m63290[0m 2010-12-04 15:24 05-[30m[42mTheManOfLawsTale[0m.txt",
|
12
|
+
" 10 -rw-r--r-- 1 jpace jpace [30m[43m64791[0m 2010-12-04 15:24 09-[30m[42mTheClerksTale[0m.txt",
|
13
|
+
" 11 -rw-r--r-- 1 jpace jpace [30m[43m65852[0m 2010-12-04 15:24 10-[30m[42mTheMerchantsTale[0m.txt",
|
14
|
+
]
|
15
|
+
run_app_test expected, [ '--and', '\b6\d{4}\b', 'The.*Tale' ], fname
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_multi_line
|
19
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
20
|
+
expected = [
|
21
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[42mTheSquiresTale[0m.txt",
|
22
|
+
" 13 -rw-r--r-- 1 jpace jpace [30m[43m51996[0m 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
23
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
|
24
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
25
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[42mTheShipmansTale[0m.txt",
|
26
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[42mTheSecondNunsTale[0m.txt",
|
27
|
+
" 23 -rw-r--r-- 1 jpace jpace [30m[43m52953[0m 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
28
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
|
29
|
+
" 25 -rw-r--r-- 1 jpace jpace [30m[43m58300[0m 2010-12-04 15:24 24-TheParsonsTale.txt",
|
30
|
+
]
|
31
|
+
run_app_test expected, [ '--and=3', '\b5\d{4}\b', 'TheS.*Tale' ], fname
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_infinite_distance
|
35
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
36
|
+
expected = [
|
37
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-[30m[42mTheKnightsTale[0m.txt",
|
38
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
|
39
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
40
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
41
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
|
42
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
43
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
|
44
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
45
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
|
46
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
|
47
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
48
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
49
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
|
50
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
51
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
52
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
|
53
|
+
" 18 -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
54
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
55
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
|
56
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
57
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
58
|
+
" 23 -rw-r--r-- 1 jpace jpace [30m[43m52953[0m 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
59
|
+
]
|
60
|
+
run_app_test expected, [ '--and=-1', '\b529\d{2}\b', 'TheKni.*Tale' ], fname
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_multi_line_grep_one_file
|
64
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
65
|
+
expected = [
|
66
|
+
" -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
67
|
+
" -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
68
|
+
" -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
69
|
+
]
|
70
|
+
run_app_test expected, [ '-g', '--and=3', '\b5\d{4}\b', 'TheS.*Tale' ], fname
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_multi_line_grep_two_files
|
74
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
75
|
+
expected = [
|
76
|
+
"/proj/org/incava/glark/test/resources/textfile.txt: -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
77
|
+
"/proj/org/incava/glark/test/resources/filelist.txt:21-The_Second_Nuns_Tale.txt",
|
78
|
+
]
|
79
|
+
run_app_test expected, [ '-g', '--and=3', '\b21\b', 'The.*Can.*Tale' ], *fnames
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class CompoundTestCase < AppTestCase
|
8
|
+
def test_hardly_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-[33m[40mTheMillersTale[0m.txt",
|
12
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
13
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
14
|
+
" 6 -rw-r--r-- 1 jpace jpace [30m[43m63290[0m 2010-12-04 15:24 05-[33m[40mTheManOfLawsTale[0m.txt",
|
15
|
+
" 7 -rw-r--r-- 1 jpace jpace [30m[42m71054[0m 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
16
|
+
" 8 -rw-r--r-- 1 jpace jpace [30m[42m22754[0m 2010-12-04 15:24 07-[30m[45mTheFriarsTale.txt[0m",
|
17
|
+
" 9 -rw-r--r-- 1 jpace jpace [30m[42m35994[0m 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
18
|
+
" 10 -rw-r--r-- 1 jpace jpace [30m[43m64791[0m 2010-12-04 15:24 09-TheClerksTale.txt",
|
19
|
+
" 11 -rw-r--r-- 1 jpace jpace [30m[43m65852[0m 2010-12-04 15:24 10-[33m[40mTheMerchantsTale[0m.txt",
|
20
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
21
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-[30m[45mTheFranklinsTale.txt[0m",
|
22
|
+
" 18 -rw-r--r-- 1 jpace jpace [30m[42m14834[0m 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
23
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
24
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[33m[40mTheMonksTale[0m.txt",
|
25
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
26
|
+
" 22 -rw-r--r-- 1 jpace jpace [30m[42m30734[0m 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
27
|
+
" 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
28
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[33m[40mTheManciplesTale[0m.txt",
|
29
|
+
]
|
30
|
+
run_app_test expected, [ '--and=3', '--or', '\b6\d{4}\b', '\b\d{4}4\b', '--or', 'TheF.*', 'TheM.*Tale' ], fname
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class ContextTestCase < AppTestCase
|
8
|
+
def test_context
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 11 - -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
|
12
|
+
" 12 - -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
13
|
+
" 13 - -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
14
|
+
" 14 : -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoc[0mtorsTale.txt",
|
15
|
+
" 15 + -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
16
|
+
" 16 + -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
17
|
+
" 17 + -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
|
18
|
+
]
|
19
|
+
run_app_test expected, %w{ -3 TheDoc }, fname
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_after
|
23
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
24
|
+
expected = [
|
25
|
+
" 14 : -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoc[0mtorsTale.txt",
|
26
|
+
" 15 + -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
27
|
+
" 16 + -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
28
|
+
]
|
29
|
+
run_app_test expected, %w{ --after-context 2 TheDoc }, fname
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_before
|
33
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
34
|
+
expected = [
|
35
|
+
" 11 - -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
|
36
|
+
" 12 - -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
37
|
+
" 13 - -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
38
|
+
" 14 : -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-[30m[43mTheDoc[0mtorsTale.txt",
|
39
|
+
]
|
40
|
+
run_app_test expected, %w{ --before-context 3 TheDoc }, fname
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class CountTestCase < AppTestCase
|
8
|
+
def test_one_file
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/spaces.txt'
|
10
|
+
expected = [
|
11
|
+
" 13",
|
12
|
+
]
|
13
|
+
run_app_test expected, [ '--count', '\wa\w+s' ], fname
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_two_files_one_matches
|
17
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
18
|
+
expected = [
|
19
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
20
|
+
" 2",
|
21
|
+
]
|
22
|
+
run_app_test expected, [ '--count', '2 ' ], *fnames
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_two_files_both_match
|
26
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
27
|
+
expected = [
|
28
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
29
|
+
" 13",
|
30
|
+
"[1m/proj/org/incava/glark/test/resources/filelist.txt[0m",
|
31
|
+
" 2",
|
32
|
+
]
|
33
|
+
run_app_test expected, [ '--count', '6.*The' ], *fnames
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_grep_one_file
|
37
|
+
fnames = [ '/proj/org/incava/glark/test/resources/spaces.txt' ]
|
38
|
+
expected = [
|
39
|
+
"2",
|
40
|
+
]
|
41
|
+
run_app_test expected, [ '-g', '--count', '6.*The' ], *fnames
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_grep_two_files_one_matches
|
45
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
46
|
+
expected = [
|
47
|
+
"/proj/org/incava/glark/test/resources/textfile.txt:2",
|
48
|
+
]
|
49
|
+
run_app_test expected, [ '-g', '--count', '2 ' ], *fnames
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_grep_two_files_both_match
|
53
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
54
|
+
expected = [
|
55
|
+
"/proj/org/incava/glark/test/resources/textfile.txt:13",
|
56
|
+
"/proj/org/incava/glark/test/resources/filelist.txt:2"
|
57
|
+
]
|
58
|
+
run_app_test expected, [ '-g', '--count', '6.*The' ], *fnames
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_grep_one_file_invert
|
62
|
+
fnames = [ '/proj/org/incava/glark/test/resources/spaces.txt' ]
|
63
|
+
expected = [
|
64
|
+
"24",
|
65
|
+
]
|
66
|
+
run_app_test expected, [ '--invert-match', '-g', '--count', '6.*The' ], *fnames
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_grep_two_files_invert_one_matches
|
70
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
71
|
+
expected = [
|
72
|
+
"/proj/org/incava/glark/test/resources/textfile.txt:24",
|
73
|
+
"/proj/org/incava/glark/test/resources/filelist.txt:26",
|
74
|
+
]
|
75
|
+
run_app_test expected, [ '--invert-match', '-g', '--count', '2 ' ], *fnames
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_glark_two_files_invert_both_match
|
79
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
80
|
+
expected = [
|
81
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
82
|
+
" 13",
|
83
|
+
"[1m/proj/org/incava/glark/test/resources/filelist.txt[0m",
|
84
|
+
" 24",
|
85
|
+
]
|
86
|
+
run_app_test expected, [ '--invert-match', '--count', '6.*The' ], *fnames
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class ExpressionFileTestCase < AppTestCase
|
8
|
+
def test_simple
|
9
|
+
infile = '/proj/org/incava/glark/test/resources/expressions.txt'
|
10
|
+
file = '/proj/org/incava/glark/test/resources/textfile.txt'
|
11
|
+
expected = [
|
12
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-[30m[42mTheMillersTale[0m.txt",
|
13
|
+
" 6 -rw-r--r-- 1 jpace jpace [30m[43m63290[0m 2010-12-04 15:24 05-[30m[42mTheManOfLawsTale[0m.txt",
|
14
|
+
" 10 -rw-r--r-- 1 jpace jpace [30m[43m64791[0m 2010-12-04 15:24 09-TheClerksTale.txt",
|
15
|
+
" 11 -rw-r--r-- 1 jpace jpace [30m[43m65852[0m 2010-12-04 15:24 10-[30m[42mTheMerchantsTale[0m.txt",
|
16
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-[30m[42mTheMonksTale[0m.txt",
|
17
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-[30m[42mTheManciplesTale[0m.txt",
|
18
|
+
]
|
19
|
+
run_app_test expected, [ '--file', infile ], file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class ExtendedRegexpTestCase < AppTestCase
|
8
|
+
def test_simple
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-[30m[43mThePar[0mdonersTale.txt",
|
12
|
+
" 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-[30m[43mThePar[0msonsTale.txt",
|
13
|
+
]
|
14
|
+
run_app_test expected, [ '--extended', 'The P a r' ], fname
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class ExtractMatchesTestCase < AppTestCase
|
8
|
+
def test_simple
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 1 [30m[43mThePrologue[0m",
|
12
|
+
" 3 [30m[43mTheMillersTale[0m",
|
13
|
+
" 5 [30m[43mTheCooksTale[0m",
|
14
|
+
" 6 [30m[43mTheManOfLawsTale[0m",
|
15
|
+
" 10 [30m[43mTheClerksTale[0m",
|
16
|
+
" 11 [30m[43mTheMerchantsTale[0m",
|
17
|
+
" 15 [30m[43mThePardonersTale[0m",
|
18
|
+
" 17 [30m[43mThePrioresssTale[0m",
|
19
|
+
" 20 [30m[43mTheMonksTale[0m",
|
20
|
+
" 23 [30m[43mTheCanonsYeomansTale[0m",
|
21
|
+
" 24 [30m[43mTheManciplesTale[0m",
|
22
|
+
" 25 [30m[43mTheParsonsTale[0m",
|
23
|
+
]
|
24
|
+
run_app_test expected, %w{ --extract-matches The[MCP]\w+ }, fname
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class FilesWithMatchTestCase < AppTestCase
|
8
|
+
def test_one_of_one
|
9
|
+
file = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [ file ]
|
11
|
+
run_app_test expected, [ '-l', 'TheM\w+Tale' ], file
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_one_of_two
|
15
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
16
|
+
expected = [ files[0] ]
|
17
|
+
run_app_test expected, [ '-l', 'TheM\w+Tale' ], *files
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_two_of_two
|
21
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
22
|
+
expected = files
|
23
|
+
run_app_test expected, [ '-l', 'The.*M\w+Tale' ], *files
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_null_two
|
27
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
28
|
+
expected = files.collect { |x| "#{x}\000" }.join('')
|
29
|
+
run_app_test_exact_output expected, [ '-l', '-Z', 'The.*M\w+Tale' ], *files
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class FilesWithoutMatchTestCase < AppTestCase
|
8
|
+
def test_one_of_one
|
9
|
+
file = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [ file ]
|
11
|
+
run_app_test expected, [ '-L', 'TheX\w+Tale' ], file
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_one_of_two
|
15
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
16
|
+
expected = [ files[1] ]
|
17
|
+
run_app_test expected, [ '-L', 'TheM\w+Tale' ], *files
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_none_of_two
|
21
|
+
files = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/filelist.txt' ]
|
22
|
+
expected = [ ]
|
23
|
+
run_app_test expected, [ '-L', 'The.*P\w+Tale' ], *files
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'glark/app/tc'
|
5
|
+
|
6
|
+
module Glark
|
7
|
+
class FilterTestCase < AppTestCase
|
8
|
+
def test_one_file_with_matches
|
9
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
10
|
+
expected = [
|
11
|
+
" 1 -rw-r--r-- 1 jpace jpace 52183 2010-12-04 15:24 00-ThePrologue.txt",
|
12
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-TheKnightsTale.txt",
|
13
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
|
14
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
15
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
16
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
|
17
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
18
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
|
19
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-[30m[43mTheSompnoursTale[0m.txt",
|
20
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
|
21
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
|
22
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-[30m[43mTheSquiresTale[0m.txt",
|
23
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
24
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
|
25
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
26
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-[30m[43mTheShipmansTale[0m.txt",
|
27
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
|
28
|
+
" 18 -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
29
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
30
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
|
31
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
32
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-[30m[43mTheSecondNunsTale[0m.txt",
|
33
|
+
" 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
34
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
|
35
|
+
" 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-TheParsonsTale.txt",
|
36
|
+
" 26 -rw-r--r-- 1 jpace jpace 3650 2010-12-04 15:24 25-PrecesDeChauceres.txt",
|
37
|
+
]
|
38
|
+
run_app_test expected, [ '--no-filter', 'TheS\w+Tale' ], fname
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_one_file_no_matches
|
42
|
+
fname = '/proj/org/incava/glark/test/resources/textfile.txt'
|
43
|
+
expected = [
|
44
|
+
" 1 -rw-r--r-- 1 jpace jpace 52183 2010-12-04 15:24 00-ThePrologue.txt",
|
45
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-TheKnightsTale.txt",
|
46
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
|
47
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
48
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
49
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
|
50
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
51
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
|
52
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
53
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
|
54
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
|
55
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
56
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
57
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoctorsTale.txt",
|
58
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
59
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
60
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePrioresssTale.txt",
|
61
|
+
" 18 -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
62
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
63
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
|
64
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
65
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
66
|
+
" 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
67
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
|
68
|
+
" 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-TheParsonsTale.txt",
|
69
|
+
" 26 -rw-r--r-- 1 jpace jpace 3650 2010-12-04 15:24 25-PrecesDeChauceres.txt",
|
70
|
+
]
|
71
|
+
run_app_test expected, [ '--no-filter', 'TheX\w+Tale' ], fname
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_two_files
|
75
|
+
fnames = [ '/proj/org/incava/glark/test/resources/textfile.txt', '/proj/org/incava/glark/test/resources/04-TheCooksTale.txt' ]
|
76
|
+
expected = [
|
77
|
+
"[1m/proj/org/incava/glark/test/resources/textfile.txt[0m",
|
78
|
+
" 1 -rw-r--r-- 1 jpace jpace 52183 2010-12-04 15:24 00-ThePrologue.txt",
|
79
|
+
" 2 -rw-r--r-- 1 jpace jpace 126084 2010-12-04 15:24 01-TheKnightsTale.txt",
|
80
|
+
" 3 -rw-r--r-- 1 jpace jpace 45450 2010-12-04 15:24 02-TheMillersTale.txt",
|
81
|
+
" 4 -rw-r--r-- 1 jpace jpace 29296 2010-12-04 15:24 03-TheReevesTale.txt",
|
82
|
+
" 5 -rw-r--r-- 1 jpace jpace 6525 2010-12-04 15:24 04-TheCooksTale.txt",
|
83
|
+
" 6 -rw-r--r-- 1 jpace jpace 63290 2010-12-04 15:24 05-TheManOfLawsTale.txt",
|
84
|
+
" 7 -rw-r--r-- 1 jpace jpace 71054 2010-12-04 15:24 06-TheWifeOfBathsTale.txt",
|
85
|
+
" 8 -rw-r--r-- 1 jpace jpace 22754 2010-12-04 15:24 07-TheFriarsTale.txt",
|
86
|
+
" 9 -rw-r--r-- 1 jpace jpace 35994 2010-12-04 15:24 08-TheSompnoursTale.txt",
|
87
|
+
" 10 -rw-r--r-- 1 jpace jpace 64791 2010-12-04 15:24 09-TheClerksTale.txt",
|
88
|
+
" 11 -rw-r--r-- 1 jpace jpace 65852 2010-12-04 15:24 10-TheMerchantsTale.txt",
|
89
|
+
" 12 -rw-r--r-- 1 jpace jpace 42282 2010-12-04 15:24 11-TheSquiresTale.txt",
|
90
|
+
" 13 -rw-r--r-- 1 jpace jpace 51996 2010-12-04 15:24 12-TheFranklinsTale.txt",
|
91
|
+
" 14 -rw-r--r-- 1 jpace jpace 15615 2010-12-04 15:24 13-TheDoct[30m[43mor[0msTale.txt",
|
92
|
+
" 15 -rw-r--r-- 1 jpace jpace 39546 2010-12-04 15:24 14-ThePardonersTale.txt",
|
93
|
+
" 16 -rw-r--r-- 1 jpace jpace 25163 2010-12-04 15:24 15-TheShipmansTale.txt",
|
94
|
+
" 17 -rw-r--r-- 1 jpace jpace 14979 2010-12-04 15:24 16-ThePri[30m[43mor[0messsTale.txt",
|
95
|
+
" 18 -rw-r--r-- 1 jpace jpace 14834 2010-12-04 15:24 17-ChaucersTaleOfSirThopas.txt",
|
96
|
+
" 19 -rw-r--r-- 1 jpace jpace 43249 2010-12-04 15:24 18-ChaucersTaleOfMeliboeus.txt",
|
97
|
+
" 20 -rw-r--r-- 1 jpace jpace 49747 2010-12-04 15:24 19-TheMonksTale.txt",
|
98
|
+
" 21 -rw-r--r-- 1 jpace jpace 45326 2010-12-04 15:24 20-TheNunsPriestsTale.txt",
|
99
|
+
" 22 -rw-r--r-- 1 jpace jpace 30734 2010-12-04 15:24 21-TheSecondNunsTale.txt",
|
100
|
+
" 23 -rw-r--r-- 1 jpace jpace 52953 2010-12-04 15:24 22-TheCanonsYeomansTale.txt",
|
101
|
+
" 24 -rw-r--r-- 1 jpace jpace 21141 2010-12-04 15:24 23-TheManciplesTale.txt",
|
102
|
+
" 25 -rw-r--r-- 1 jpace jpace 58300 2010-12-04 15:24 24-TheParsonsTale.txt",
|
103
|
+
" 26 -rw-r--r-- 1 jpace jpace 3650 2010-12-04 15:24 25-PrecesDeChauceres.txt",
|
104
|
+
"[1m/proj/org/incava/glark/test/resources/04-TheCooksTale.txt[0m",
|
105
|
+
" 1 Of many a pilgrim hast thou Christe's curse,",
|
106
|
+
" 2 F[30m[43mor[0m of thy parsley yet fare they the w[30m[43mor[0mse.",
|
107
|
+
" 3 ",
|
108
|
+
" 4 That they have eaten in thy stubble goose:",
|
109
|
+
" 5 F[30m[43mor[0m in thy shop doth many a fly go loose.",
|
110
|
+
" 6 ",
|
111
|
+
" 7 Now tell on, gentle Roger, by thy name,",
|
112
|
+
" 8 But yet I pray thee be not wroth f[30m[43mor[0m game;",
|
113
|
+
" 9 A man may say full sooth in game and play.",
|
114
|
+
]
|
115
|
+
run_app_test expected, [ '--no-filter', 'or' ], *fnames
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|