codestock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.document +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +18 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +63 -0
  7. data/VERSION +1 -0
  8. data/bin/cdstk +12 -0
  9. data/bin/cdv +11 -0
  10. data/bin/cdview +11 -0
  11. data/bin/cdweb +11 -0
  12. data/codestock.gemspec +131 -0
  13. data/lib/codestock.rb +0 -0
  14. data/lib/common/dbdir.rb +37 -0
  15. data/lib/common/display_util.rb +62 -0
  16. data/lib/common/grenfiletest.rb +19 -0
  17. data/lib/common/grensnip.rb +37 -0
  18. data/lib/common/platform.rb +17 -0
  19. data/lib/common/string_snip.rb +61 -0
  20. data/lib/common/util.rb +98 -0
  21. data/lib/findgrep/findgrep.rb +408 -0
  22. data/lib/findgrep/result.rb +43 -0
  23. data/lib/gren/cli.rb +65 -0
  24. data/lib/gren.rb +6 -0
  25. data/lib/grendb/cli.rb +43 -0
  26. data/lib/grenweb/cli.rb +54 -0
  27. data/lib/grenweb/database.rb +182 -0
  28. data/lib/grenweb/grenweb.ru +35 -0
  29. data/lib/grenweb/grep.rb +52 -0
  30. data/lib/grenweb/help.rb +40 -0
  31. data/lib/grenweb/home.rb +40 -0
  32. data/lib/grenweb/html_renderer.rb +244 -0
  33. data/lib/grenweb/public/css/gren.css +63 -0
  34. data/lib/grenweb/public/images/gren-icon-mini.png +0 -0
  35. data/lib/grenweb/public/images/gren-icon.png +0 -0
  36. data/lib/grenweb/query.rb +82 -0
  37. data/lib/grenweb/searcher.rb +130 -0
  38. data/lib/grenweb/viewer.rb +52 -0
  39. data/lib/mkgrendb/cli.rb +89 -0
  40. data/lib/mkgrendb/cli_old.rb +49 -0
  41. data/lib/mkgrendb/grendbyaml.rb +76 -0
  42. data/lib/mkgrendb/mkgrendb.rb +296 -0
  43. data/test/file_test_utils.rb +59 -0
  44. data/test/runner.rb +11 -0
  45. data/test/test_dbdir.rb +59 -0
  46. data/test/test_gren.rb +10 -0
  47. data/test/test_gren_util.rb +34 -0
  48. data/test/test_grendbyaml.rb +109 -0
  49. data/test/test_grenweb_cli.rb +10 -0
  50. data/test/test_grenweb_database.rb +37 -0
  51. data/test/test_grenweb_html_renderer.rb +41 -0
  52. data/test/test_grenweb_query.rb +54 -0
  53. data/test/test_grenweb_searcher.rb +35 -0
  54. data/test/test_helper.rb +2 -0
  55. data/test/test_mkgrendb.rb +163 -0
  56. data/test/test_string_snip.rb +31 -0
  57. metadata +229 -0
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2010/10/21
7
+
8
+ require File.join(File.dirname(__FILE__), 'test_helper')
9
+ require File.join(File.dirname(__FILE__), '../lib/grenweb/query')
10
+
11
+ class TestGrenWebQuery < Test::Unit::TestCase
12
+ include Grenweb
13
+ include Rack::Utils
14
+
15
+ def test_query
16
+ q = create_query("test fire beam")
17
+ assert_equal q.keywords, ['test', 'fire', 'beam']
18
+ assert_equal q.packages, []
19
+ assert_equal q.fpaths, []
20
+ assert_equal q.suffixs, []
21
+ assert_equal q.escape_html, 'test fire beam'
22
+
23
+ q = create_query("test fire beam f:testfile1")
24
+ assert_equal q.keywords, ['test', 'fire', 'beam']
25
+ assert_equal q.packages, []
26
+ assert_equal q.fpaths, ['testfile1']
27
+ assert_equal q.suffixs, []
28
+
29
+ q = create_query("test fire beam f:testfile1 filepath:dir32")
30
+ assert_equal q.keywords, ['test', 'fire', 'beam']
31
+ assert_equal q.packages, []
32
+ assert_equal q.fpaths, ['dir32', 'testfile1']
33
+ assert_equal q.suffixs, []
34
+
35
+ q = create_query("package:gren test fire beam f:testfile1 filepath:dir32 s:rb p:test suffix:pl")
36
+ assert_equal q.keywords, ['test', 'fire', 'beam']
37
+ assert_equal q.packages, ['gren', 'test']
38
+ assert_equal q.fpaths, ['dir32', 'testfile1']
39
+ assert_equal q.suffixs, ['pl', 'rb']
40
+
41
+ q = create_query("&p")
42
+ assert_equal q.escape_html, '&amp;p'
43
+
44
+ q = create_query("int &p")
45
+ assert_equal q.escape_html, 'int &amp;p'
46
+
47
+ q = create_query('"def update"')
48
+ assert_equal q.keywords, ['def update']
49
+ end
50
+
51
+ def create_query(query)
52
+ Query.new(Rack::Request.new({"PATH_INFO"=>"/#{escape(query)}/"}))
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2010/10/21
7
+
8
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
9
+ require File.join(File.dirname(__FILE__), "../lib/grenweb/searcher.rb")
10
+ require 'rack/mock'
11
+
12
+ class TestGrenwebSearcher < Test::Unit::TestCase
13
+ def setup
14
+ @app = Grenweb::Searcher.new
15
+ @mr = Rack::MockRequest.new(@app)
16
+ end
17
+
18
+ def test_get
19
+ res = nil
20
+ assert_nothing_raised('なんか失敗した') { res = @mr.get('/', :lint => true) }
21
+ assert_not_nil res, 'レスポンス来てない'
22
+ assert_equal 200, res.status, 'ステータスコードが変'
23
+ assert_equal 'text/html; charset=UTF-8', res['Content-Type'], 'Content-Typeが変'
24
+ #puts res.body
25
+ end
26
+
27
+ def test_post
28
+ res = nil
29
+ assert_nothing_raised('なんか失敗した') { res = @mr.post('/', :lint => true) }
30
+ assert_not_nil res, 'レスポンス来てない'
31
+ assert_equal 302, res.status, 'ステータスコードが変'
32
+ assert_equal 'text/html; charset=UTF-8', res['Content-Type'], 'Content-Typeが変'
33
+ #puts res.body
34
+ end
35
+ end
@@ -0,0 +1,2 @@
1
+ require 'stringio'
2
+ require 'test/unit'
@@ -0,0 +1,163 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2011/02/20
7
+
8
+ require 'rubygems'
9
+ require 'groonga'
10
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
11
+ require File.join(File.dirname(__FILE__), "file_test_utils")
12
+ require File.join(File.dirname(__FILE__), "../lib/mkgrendb/cli.rb")
13
+ require File.join(File.dirname(__FILE__), "../lib/mkgrendb/mkgrendb")
14
+ require 'stringio'
15
+
16
+ class TestMkgrendb < Test::Unit::TestCase
17
+ include Mkgrendb
18
+ include FileTestUtils
19
+
20
+ def test_create
21
+ db_path = Pathname.new('.') + 'db'
22
+ database = Groonga::Database.create(:path => db_path.to_s)
23
+ assert_equal database, Groonga::Context.default.database
24
+ end
25
+
26
+ def test_mkgrendb
27
+ io = StringIO.new
28
+ obj = Mkgrendb.new(io)
29
+
30
+ # Mkgrendb#init
31
+ obj.init
32
+ assert_equal <<EOF, io.string
33
+ create : grendb.yaml
34
+ create : db/grendb.db created.
35
+ EOF
36
+
37
+ io.string = ""
38
+ obj.init
39
+ assert_match "Can't create Grendb Database (Not empty)", io.string
40
+
41
+ # Mkgrendb#add, remove
42
+ obj.add('test1.html', 'test2.html')
43
+
44
+ f1 = File.expand_path 'test1.html'
45
+ f2 = File.expand_path 'test2.html'
46
+
47
+ assert_equal [f1, f2], GrendbYAML.load.directorys
48
+ assert_match /WARNING.*test1.html/, io.string
49
+ assert_match /WARNING.*test2.html/, io.string
50
+
51
+ obj.remove(f1, f2)
52
+ assert_equal [], GrendbYAML.load.directorys
53
+
54
+ # Mkgrendb#add
55
+ io.string = ""
56
+ obj.add('../../lib/findgrep', '../../lib/common')
57
+ assert_match /add_file\s+:\s+.*findgrep.rb/, io.string
58
+ assert_match /add_file\s+:\s+.*grenfiletest.rb/, io.string
59
+
60
+ # Mkgrendb#update
61
+ io.string = ""
62
+ obj.update
63
+ end
64
+
65
+ def test_mkgrendb_other_path
66
+ io = StringIO.new
67
+ FileUtils.mkdir 'other_path'
68
+ obj = Mkgrendb.new(io, 'other_path')
69
+
70
+ # Mkgrendb#init
71
+ obj.init
72
+ assert_equal <<EOF, io.string
73
+ create : other_path/grendb.yaml
74
+ create : other_path/db/grendb.db created.
75
+ EOF
76
+
77
+ io.string = ""
78
+ obj.init
79
+ assert_match "Can't create Grendb Database (Not empty)", io.string
80
+
81
+ # Mkgrendb#add, remove
82
+ obj.add('test1.html', 'test2.html')
83
+
84
+ f1 = File.expand_path 'test1.html'
85
+ f2 = File.expand_path 'test2.html'
86
+ assert_equal [f1, f2], GrendbYAML.load('other_path').directorys
87
+ assert_match /WARNING.*test1.html/, io.string
88
+ assert_match /WARNING.*test2.html/, io.string
89
+
90
+ obj.remove(f1, f2)
91
+ assert_equal [], GrendbYAML.load('other_path').directorys
92
+
93
+ # Mkgrendb#add
94
+ io.string = ""
95
+ obj.add('../../lib/findgrep', '../../lib/common')
96
+ assert_match /add_file\s+:\s+.*findgrep.rb/, io.string
97
+ assert_match /add_file\s+:\s+.*grenfiletest.rb/, io.string
98
+
99
+ # Mkgrendb#update
100
+ io.string = ""
101
+ obj.update
102
+ end
103
+
104
+ def test_cli
105
+ io = StringIO.new
106
+ CLI.execute(io, ["init"])
107
+
108
+ io.string = ""
109
+ CLI.execute(io, ["add", "dummy/bar", "foo"])
110
+ assert_match /dummy\/bar/, io.string
111
+ assert_match /foo/, io.string
112
+
113
+ io.string = ""
114
+ CLI.execute(io, ["list"])
115
+ assert_match /dummy\/bar/, io.string
116
+ assert_match /foo/, io.string
117
+
118
+ CLI.execute(io, ["remove", "foo"])
119
+ io.string = ""
120
+ CLI.execute(io, ["list"])
121
+ assert_match /dummy\/bar/, io.string
122
+ assert_no_match /foo/, io.string
123
+
124
+ CLI.execute(io, ["update"])
125
+ CLI.execute(io, ["rebuild"])
126
+ end
127
+
128
+ def test_dump
129
+ io = StringIO.new
130
+ CLI.execute(io, ["init"])
131
+ CLI.execute(io, ["add", "../runner.rb"])
132
+ io.string = ""
133
+ CLI.execute(io, ["dump"])
134
+ lines = io.string.split("\n")
135
+ assert_match /path : .*test\/runner.rb/, lines[2]
136
+ assert_match /shortpath : runner.rb/, lines[3]
137
+ assert_match /suffix : \.rb/, lines[4]
138
+ end
139
+
140
+ def test_add_remove_compact
141
+ io = StringIO.new
142
+
143
+ CLI.execute(io, ["init"])
144
+ CLI.execute(io, ["add", "dummy/bar"])
145
+ CLI.execute(io, ["add", "dummy/bar"])
146
+
147
+ assert_equal 1, GrendbYAML.load.directorys.select{|i|i == File.expand_path("dummy/bar")}.count
148
+
149
+ CLI.execute(io, ["add", "dummy/da"])
150
+ CLI.execute(io, ["add", "dummy/ad"])
151
+ CLI.execute(io, ["add", "dummy/foo"])
152
+ CLI.execute(io, ["add", "dummy/bar"])
153
+
154
+ assert_equal 1, GrendbYAML.load.directorys.select{|i|i == File.expand_path("dummy/bar")}.count
155
+ end
156
+
157
+ def teardown
158
+ teardown_custom(true)
159
+ # teardown_custom(false)
160
+ end
161
+ end
162
+
163
+
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+ require File.join(File.dirname(__FILE__), "../lib/common/util.rb")
3
+ require File.join(File.dirname(__FILE__), "../lib/common/grensnip.rb")
4
+
5
+ class TestStringSnip < Test::Unit::TestCase
6
+ def setup
7
+ end
8
+
9
+ def test_ranges_compound
10
+ ranges = [0..7, 8..232, 121..150, 248..255]
11
+ assert_equal(StringSnip.ranges_compound(ranges), [0..232, 248..255])
12
+
13
+ ranges = [10..20, 22..30, 33..40]
14
+ assert_equal(StringSnip.ranges_compound(ranges), [10..20, 22..30, 33..40])
15
+
16
+ ranges = [10..30, 20..30, 30..40]
17
+ assert_equal(StringSnip.ranges_compound(ranges), [10..40])
18
+ end
19
+
20
+ def test_string_snip
21
+ str = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|12345678901234567890123456789012345678901234567890123456"
22
+
23
+ snipper = StringSnip.new
24
+ snip_str = snipper.snip(str, [0..7, -8..-1])
25
+ assert_equal(snip_str, str)
26
+
27
+ snipper = StringSnip.new(64)
28
+ snip_str = snipper.snip(str, [-8..-1, 10..20, 0..7])
29
+ assert_equal(snip_str, "12345678<<snip>>12345678901<<snip>>90123456")
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codestock
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - ongaeshi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-11 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ segments:
26
+ - 1
27
+ - 0
28
+ - 0
29
+ version: 1.0.0
30
+ name: bundler
31
+ requirement: *id001
32
+ prerelease: false
33
+ type: :development
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 5
42
+ - 2
43
+ version: 1.5.2
44
+ name: jeweler
45
+ requirement: *id002
46
+ prerelease: false
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ name: rcov
57
+ requirement: *id003
58
+ prerelease: false
59
+ type: :development
60
+ - !ruby/object:Gem::Dependency
61
+ version_requirements: &id004 !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 1
67
+ - 2
68
+ - 0
69
+ version: 1.2.0
70
+ name: termcolor
71
+ requirement: *id004
72
+ prerelease: false
73
+ type: :runtime
74
+ - !ruby/object:Gem::Dependency
75
+ version_requirements: &id005 !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 1
81
+ - 0
82
+ - 0
83
+ version: 1.0.0
84
+ name: rroonga
85
+ requirement: *id005
86
+ prerelease: false
87
+ type: :runtime
88
+ - !ruby/object:Gem::Dependency
89
+ version_requirements: &id006 !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 1
95
+ - 2
96
+ - 1
97
+ version: 1.2.1
98
+ name: rack
99
+ requirement: *id006
100
+ prerelease: false
101
+ type: :runtime
102
+ - !ruby/object:Gem::Dependency
103
+ version_requirements: &id007 !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ - 3
110
+ - 7
111
+ version: 0.3.7
112
+ name: launchy
113
+ requirement: *id007
114
+ prerelease: false
115
+ type: :runtime
116
+ description: longer description of your gem
117
+ email: ongaeshi0621@gmail.com
118
+ executables:
119
+ - cdweb
120
+ - cdv
121
+ - cdstk
122
+ - cdview
123
+ extensions: []
124
+
125
+ extra_rdoc_files:
126
+ - LICENSE.txt
127
+ - README.rdoc
128
+ files:
129
+ - .document
130
+ - Gemfile
131
+ - Gemfile.lock
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ - Rakefile
135
+ - VERSION
136
+ - bin/cdstk
137
+ - bin/cdv
138
+ - bin/cdview
139
+ - bin/cdweb
140
+ - codestock.gemspec
141
+ - lib/codestock.rb
142
+ - lib/common/dbdir.rb
143
+ - lib/common/display_util.rb
144
+ - lib/common/grenfiletest.rb
145
+ - lib/common/grensnip.rb
146
+ - lib/common/platform.rb
147
+ - lib/common/string_snip.rb
148
+ - lib/common/util.rb
149
+ - lib/findgrep/findgrep.rb
150
+ - lib/findgrep/result.rb
151
+ - lib/gren.rb
152
+ - lib/gren/cli.rb
153
+ - lib/grendb/cli.rb
154
+ - lib/grenweb/cli.rb
155
+ - lib/grenweb/database.rb
156
+ - lib/grenweb/grenweb.ru
157
+ - lib/grenweb/grep.rb
158
+ - lib/grenweb/help.rb
159
+ - lib/grenweb/home.rb
160
+ - lib/grenweb/html_renderer.rb
161
+ - lib/grenweb/public/css/gren.css
162
+ - lib/grenweb/public/images/gren-icon-mini.png
163
+ - lib/grenweb/public/images/gren-icon.png
164
+ - lib/grenweb/query.rb
165
+ - lib/grenweb/searcher.rb
166
+ - lib/grenweb/viewer.rb
167
+ - lib/mkgrendb/cli.rb
168
+ - lib/mkgrendb/cli_old.rb
169
+ - lib/mkgrendb/grendbyaml.rb
170
+ - lib/mkgrendb/mkgrendb.rb
171
+ - test/file_test_utils.rb
172
+ - test/runner.rb
173
+ - test/test_dbdir.rb
174
+ - test/test_gren.rb
175
+ - test/test_gren_util.rb
176
+ - test/test_grendbyaml.rb
177
+ - test/test_grenweb_cli.rb
178
+ - test/test_grenweb_database.rb
179
+ - test/test_grenweb_html_renderer.rb
180
+ - test/test_grenweb_query.rb
181
+ - test/test_grenweb_searcher.rb
182
+ - test/test_helper.rb
183
+ - test/test_mkgrendb.rb
184
+ - test/test_string_snip.rb
185
+ has_rdoc: true
186
+ homepage: http://github.com/ongaeshi/codestock
187
+ licenses:
188
+ - MIT
189
+ post_install_message:
190
+ rdoc_options: []
191
+
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ segments:
199
+ - 0
200
+ version: "0"
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ segments:
206
+ - 0
207
+ version: "0"
208
+ requirements: []
209
+
210
+ rubyforge_project:
211
+ rubygems_version: 1.3.6
212
+ signing_key:
213
+ specification_version: 3
214
+ summary: one-line summary of your gem
215
+ test_files:
216
+ - test/file_test_utils.rb
217
+ - test/runner.rb
218
+ - test/test_dbdir.rb
219
+ - test/test_gren.rb
220
+ - test/test_gren_util.rb
221
+ - test/test_grendbyaml.rb
222
+ - test/test_grenweb_cli.rb
223
+ - test/test_grenweb_database.rb
224
+ - test/test_grenweb_html_renderer.rb
225
+ - test/test_grenweb_query.rb
226
+ - test/test_grenweb_searcher.rb
227
+ - test/test_helper.rb
228
+ - test/test_mkgrendb.rb
229
+ - test/test_string_snip.rb