codestock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +18 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/bin/cdstk +12 -0
- data/bin/cdv +11 -0
- data/bin/cdview +11 -0
- data/bin/cdweb +11 -0
- data/codestock.gemspec +131 -0
- data/lib/codestock.rb +0 -0
- data/lib/common/dbdir.rb +37 -0
- data/lib/common/display_util.rb +62 -0
- data/lib/common/grenfiletest.rb +19 -0
- data/lib/common/grensnip.rb +37 -0
- data/lib/common/platform.rb +17 -0
- data/lib/common/string_snip.rb +61 -0
- data/lib/common/util.rb +98 -0
- data/lib/findgrep/findgrep.rb +408 -0
- data/lib/findgrep/result.rb +43 -0
- data/lib/gren/cli.rb +65 -0
- data/lib/gren.rb +6 -0
- data/lib/grendb/cli.rb +43 -0
- data/lib/grenweb/cli.rb +54 -0
- data/lib/grenweb/database.rb +182 -0
- data/lib/grenweb/grenweb.ru +35 -0
- data/lib/grenweb/grep.rb +52 -0
- data/lib/grenweb/help.rb +40 -0
- data/lib/grenweb/home.rb +40 -0
- data/lib/grenweb/html_renderer.rb +244 -0
- data/lib/grenweb/public/css/gren.css +63 -0
- data/lib/grenweb/public/images/gren-icon-mini.png +0 -0
- data/lib/grenweb/public/images/gren-icon.png +0 -0
- data/lib/grenweb/query.rb +82 -0
- data/lib/grenweb/searcher.rb +130 -0
- data/lib/grenweb/viewer.rb +52 -0
- data/lib/mkgrendb/cli.rb +89 -0
- data/lib/mkgrendb/cli_old.rb +49 -0
- data/lib/mkgrendb/grendbyaml.rb +76 -0
- data/lib/mkgrendb/mkgrendb.rb +296 -0
- data/test/file_test_utils.rb +59 -0
- data/test/runner.rb +11 -0
- data/test/test_dbdir.rb +59 -0
- data/test/test_gren.rb +10 -0
- data/test/test_gren_util.rb +34 -0
- data/test/test_grendbyaml.rb +109 -0
- data/test/test_grenweb_cli.rb +10 -0
- data/test/test_grenweb_database.rb +37 -0
- data/test/test_grenweb_html_renderer.rb +41 -0
- data/test/test_grenweb_query.rb +54 -0
- data/test/test_grenweb_searcher.rb +35 -0
- data/test/test_helper.rb +2 -0
- data/test/test_mkgrendb.rb +163 -0
- data/test/test_string_snip.rb +31 -0
- metadata +229 -0
@@ -0,0 +1,296 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'pathname'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'groonga'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'pathname'
|
9
|
+
require File.join(File.dirname(__FILE__), 'grendbyaml')
|
10
|
+
require File.join(File.dirname(__FILE__), '../common/grenfiletest')
|
11
|
+
require File.join(File.dirname(__FILE__), '../common/util')
|
12
|
+
include Gren
|
13
|
+
|
14
|
+
module Mkgrendb
|
15
|
+
class Mkgrendb
|
16
|
+
DB_FILE_PATH = 'db/grendb.db'
|
17
|
+
|
18
|
+
def initialize(io = $stdout, db_dir = ".")
|
19
|
+
@db_dir = db_dir
|
20
|
+
@out = io
|
21
|
+
@file_count = 0
|
22
|
+
@add_count = 0
|
23
|
+
@update_count = 0
|
24
|
+
@start_time = Time.now
|
25
|
+
end
|
26
|
+
|
27
|
+
def init
|
28
|
+
if Dir.entries(@db_dir) == [".", ".."]
|
29
|
+
GrendbYAML.create(@db_dir)
|
30
|
+
@out.puts "create : #{yaml_file}"
|
31
|
+
db_create(db_file)
|
32
|
+
else
|
33
|
+
@out.puts "Can't create Grendb Database (Not empty) in #{@db_dir}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update
|
38
|
+
print_result do
|
39
|
+
yaml = yaml_load
|
40
|
+
db_open(db_file)
|
41
|
+
|
42
|
+
yaml.contents.each do |content|
|
43
|
+
update_dir_in(content["directory"])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_dir(dir)
|
49
|
+
print_result do
|
50
|
+
update_dir_in(dir)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def add(*content)
|
55
|
+
# 絶対パスに変換
|
56
|
+
content.map!{|v|File.expand_path(v)}
|
57
|
+
|
58
|
+
# YAML更新
|
59
|
+
yaml = yaml_load
|
60
|
+
yaml.add(*content)
|
61
|
+
yaml.save
|
62
|
+
|
63
|
+
# 部分アップデート
|
64
|
+
db_open(db_file)
|
65
|
+
content.each do |dir|
|
66
|
+
update_dir(dir)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def remove(*content)
|
71
|
+
# 絶対パスに変換
|
72
|
+
content.map!{|v|File.expand_path(v)}
|
73
|
+
|
74
|
+
# YAML更新
|
75
|
+
yaml = yaml_load
|
76
|
+
yaml.remove(*content)
|
77
|
+
yaml.save
|
78
|
+
|
79
|
+
# @todo 削除したコンテンツをインデックスから削除
|
80
|
+
end
|
81
|
+
|
82
|
+
def list
|
83
|
+
@out.puts yaml_load.list
|
84
|
+
end
|
85
|
+
|
86
|
+
def rebuild
|
87
|
+
db_delete(db_file)
|
88
|
+
db_create(db_file)
|
89
|
+
update
|
90
|
+
end
|
91
|
+
|
92
|
+
def dump
|
93
|
+
db_open(db_file)
|
94
|
+
|
95
|
+
documents = Groonga::Context.default["documents"]
|
96
|
+
records = documents.select
|
97
|
+
records.each do |record|
|
98
|
+
@out.puts record.inspect
|
99
|
+
@out.puts "path : #{record.path}"
|
100
|
+
@out.puts "shortpath : #{record.shortpath}"
|
101
|
+
@out.puts "suffix : #{record.suffix}"
|
102
|
+
@out.puts "timestamp : #{record.timestamp.strftime('%Y/%m/%d %H:%M:%S')}"
|
103
|
+
@out.puts "content :", record.content ? record.content[0..64] : nil
|
104
|
+
@out.puts
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def db_file
|
111
|
+
(Pathname.new(@db_dir) + DB_FILE_PATH).to_s
|
112
|
+
end
|
113
|
+
|
114
|
+
def yaml_file
|
115
|
+
GrendbYAML.yaml_file @db_dir
|
116
|
+
end
|
117
|
+
|
118
|
+
def yaml_load
|
119
|
+
GrendbYAML.load(@db_dir)
|
120
|
+
end
|
121
|
+
|
122
|
+
def update_dir_in(dir)
|
123
|
+
dir = File.expand_path(dir)
|
124
|
+
|
125
|
+
if (!FileTest.exist?(dir))
|
126
|
+
@out.puts "[WARNING] : #{dir} (Not found, skip)"
|
127
|
+
elsif (FileTest.directory? dir)
|
128
|
+
db_add_dir(dir)
|
129
|
+
else
|
130
|
+
db_add_file(STDOUT, dir, File.basename(dir))
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def time
|
135
|
+
@end_time - @start_time
|
136
|
+
end
|
137
|
+
|
138
|
+
def print_result
|
139
|
+
yield
|
140
|
+
|
141
|
+
@end_time = Time.now
|
142
|
+
|
143
|
+
@out.puts
|
144
|
+
@out.puts "time : #{Util::time_s(time)}"
|
145
|
+
@out.puts "files : #{@file_count}"
|
146
|
+
@out.puts "add : #{@add_count}"
|
147
|
+
@out.puts "update : #{@update_count}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def db_create(filename)
|
151
|
+
dbfile = Pathname(File.expand_path(filename))
|
152
|
+
dbdir = dbfile.dirname
|
153
|
+
dbdir.mkpath unless dbdir.exist?
|
154
|
+
|
155
|
+
unless dbfile.exist?
|
156
|
+
Groonga::Database.create(:path => dbfile.to_s)
|
157
|
+
Groonga::Schema.define do |schema|
|
158
|
+
schema.create_table("documents") do |table|
|
159
|
+
table.string("path")
|
160
|
+
table.string("shortpath")
|
161
|
+
table.text("content")
|
162
|
+
table.time("timestamp")
|
163
|
+
table.text("suffix")
|
164
|
+
end
|
165
|
+
|
166
|
+
schema.create_table("terms",
|
167
|
+
:type => :patricia_trie,
|
168
|
+
:key_normalize => true,
|
169
|
+
:default_tokenizer => "TokenBigram") do |table|
|
170
|
+
table.index("documents.path", :with_position => true)
|
171
|
+
table.index("documents.shortpath", :with_position => true)
|
172
|
+
table.index("documents.content", :with_position => true)
|
173
|
+
table.index("documents.suffix", :with_position => true)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
@out.puts "create : #{filename} created."
|
177
|
+
else
|
178
|
+
@out.puts "message : #{filename} already exist."
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def db_open(filename)
|
183
|
+
dbfile = Pathname(File.expand_path(filename))
|
184
|
+
|
185
|
+
if dbfile.exist?
|
186
|
+
Groonga::Database.open(dbfile.to_s)
|
187
|
+
@out.puts "open : #{dbfile} open."
|
188
|
+
else
|
189
|
+
raise "error : #{dbfile.to_s} not found!!"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def db_delete(filename)
|
194
|
+
raise "Illegal file name : #{filename}." unless filename =~ /\.db$/
|
195
|
+
Dir.glob("#{filename}*").each do |f|
|
196
|
+
@out.puts "delete : #{f}"
|
197
|
+
FileUtils.rm_r(f)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
private :db_delete
|
201
|
+
|
202
|
+
def db_add_dir(dirname)
|
203
|
+
searchDirectory(STDOUT, dirname, File.basename(dirname), 0)
|
204
|
+
end
|
205
|
+
private :db_add_dir
|
206
|
+
|
207
|
+
def db_add_file(stdout, filename, shortpath)
|
208
|
+
# 格納するデータ
|
209
|
+
values = {
|
210
|
+
:path => filename,
|
211
|
+
:shortpath => shortpath,
|
212
|
+
:content => nil,
|
213
|
+
:timestamp => File.mtime(filename),
|
214
|
+
:suffix => File::extname(filename),
|
215
|
+
}
|
216
|
+
|
217
|
+
# 検索するデータベース
|
218
|
+
documents = Groonga::Context.default["documents"]
|
219
|
+
|
220
|
+
# 既に登録されているファイルならばそれを上書き、そうでなければ新規レコードを作成
|
221
|
+
_documents = documents.select do |record|
|
222
|
+
record["path"] == values[:path]
|
223
|
+
end
|
224
|
+
|
225
|
+
isNewFile = false
|
226
|
+
|
227
|
+
if _documents.size.zero?
|
228
|
+
document = documents.add
|
229
|
+
isNewFile = true
|
230
|
+
else
|
231
|
+
document = _documents.to_a[0].key
|
232
|
+
end
|
233
|
+
|
234
|
+
# タイムスタンプが新しければデータベースに格納
|
235
|
+
if (document[:timestamp] < values[:timestamp])
|
236
|
+
# 実際に使うタイミングでファイルの内容を読み込み
|
237
|
+
values[:content] = open(filename).read
|
238
|
+
|
239
|
+
# データベースに格納
|
240
|
+
values.each do |key, value|
|
241
|
+
if (key == :path)
|
242
|
+
if (isNewFile)
|
243
|
+
@add_count += 1
|
244
|
+
@out.puts "add_file : #{value}"
|
245
|
+
else
|
246
|
+
@update_count += 1
|
247
|
+
@out.puts "update : #{value}"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
document[key] = value
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
def searchDirectory(stdout, dir, shortdir, depth)
|
257
|
+
Dir.foreach(dir) do |name|
|
258
|
+
next if (name == '.' || name == '..')
|
259
|
+
|
260
|
+
fpath = File.join(dir,name)
|
261
|
+
shortpath = File.join(shortdir,name)
|
262
|
+
|
263
|
+
# 除外ディレクトリならばパス
|
264
|
+
next if ignoreDir?(fpath)
|
265
|
+
|
266
|
+
# 読み込み不可ならばパス
|
267
|
+
next unless FileTest.readable?(fpath)
|
268
|
+
|
269
|
+
# ファイルならば中身を探索、ディレクトリならば再帰
|
270
|
+
case File.ftype(fpath)
|
271
|
+
when "directory"
|
272
|
+
searchDirectory(stdout, fpath, shortpath, depth + 1)
|
273
|
+
when "file"
|
274
|
+
unless ignoreFile?(fpath)
|
275
|
+
db_add_file(stdout, fpath, shortpath)
|
276
|
+
@file_count += 1
|
277
|
+
@out.puts "file_count : #{@file_count}" if (@file_count % 100 == 0)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def ignoreDir?(fpath)
|
284
|
+
FileTest.directory?(fpath) &&
|
285
|
+
GrenFileTest::ignoreDir?(fpath)
|
286
|
+
end
|
287
|
+
private :ignoreDir?
|
288
|
+
|
289
|
+
def ignoreFile?(fpath)
|
290
|
+
GrenFileTest::ignoreFile?(fpath) ||
|
291
|
+
GrenFileTest::binary?(fpath)
|
292
|
+
end
|
293
|
+
private :ignoreFile?
|
294
|
+
|
295
|
+
end
|
296
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief ファイルテスト用ユーティリティ
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2011/02/21
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# 以下のことを自動でやってくれます
|
10
|
+
#
|
11
|
+
# 1. tmpディレクトリの作成
|
12
|
+
# 2. tmpディレクトリに移動
|
13
|
+
# 3. テスト実行
|
14
|
+
# 4. 元のディレクトリに戻る
|
15
|
+
# 5. tmpディレクトリの削除
|
16
|
+
#
|
17
|
+
# また、以下の関数が使えます
|
18
|
+
#
|
19
|
+
# assert_diff_files(file1, file2)
|
20
|
+
#
|
21
|
+
# 二つのファイルが等しい場合はテスト成功
|
22
|
+
# 失敗した場合は二つのファイルのdiffを表示します
|
23
|
+
|
24
|
+
require 'pathname'
|
25
|
+
require 'fileutils'
|
26
|
+
|
27
|
+
module FileTestUtils
|
28
|
+
def setup
|
29
|
+
create_tmp_dir
|
30
|
+
FileUtils.cd(@tmp_dir.to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_diff_files(file1, file2)
|
34
|
+
unless (IO.read(file1) == IO.read(file2))
|
35
|
+
puts `diff -c #{file1} #{file2}`
|
36
|
+
assert_equal true, false
|
37
|
+
else
|
38
|
+
assert_equal true, true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
teardown_custom(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown_custom(is_remove_dir)
|
47
|
+
FileUtils.cd(@prev_dir)
|
48
|
+
FileUtils.rm_rf(@tmp_dir.to_s) if (is_remove_dir)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def create_tmp_dir
|
54
|
+
@prev_dir = Dir.pwd
|
55
|
+
@tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
|
56
|
+
FileUtils.rm_rf(@tmp_dir.to_s)
|
57
|
+
FileUtils.mkdir_p(@tmp_dir.to_s)
|
58
|
+
end
|
59
|
+
end
|
data/test/runner.rb
ADDED
data/test/test_dbdir.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2011/03/08
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
10
|
+
require File.join(File.dirname(__FILE__), "../lib/common/dbdir")
|
11
|
+
require File.join(File.dirname(__FILE__), "file_test_utils")
|
12
|
+
|
13
|
+
class TestDbDir< Test::Unit::TestCase
|
14
|
+
include CodeStock
|
15
|
+
include FileTestUtils
|
16
|
+
|
17
|
+
def test_db_default_dir
|
18
|
+
assert_equal File.expand_path('~/.codestock'), db_default_dir
|
19
|
+
|
20
|
+
ENV['CODESTOCK_DEFAULT_DIR'] = "~/DummyDir"
|
21
|
+
assert_equal File.expand_path("~/DummyDir"), db_default_dir
|
22
|
+
|
23
|
+
ENV['CODESTOCK_DEFAULT_DIR'] = nil
|
24
|
+
ENV['CODESTOCK_DEFAULT_DIRR'] = "~/DummyDir"
|
25
|
+
assert_equal File.expand_path('~/.codestock'), db_default_dir
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_is_dbdir
|
29
|
+
assert_equal false, dbdir?
|
30
|
+
|
31
|
+
FileUtils.touch "grendb.yaml"
|
32
|
+
assert_equal true, dbdir?
|
33
|
+
|
34
|
+
FileUtils.mkdir_p 'damadame'
|
35
|
+
FileUtils.touch "damadame/grendb.yaml"
|
36
|
+
assert_equal true, dbdir?('damadame')
|
37
|
+
assert_equal false, dbdir?('damadameyo')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_db_groonga_path
|
41
|
+
assert_equal 'db/grendb.db', db_groonga_path
|
42
|
+
assert_equal '../db/grendb.db', db_groonga_path('..')
|
43
|
+
assert_equal '/Users/MrRuby/db/grendb.db', db_groonga_path('/Users/MrRuby')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_db_expand_groonga_path
|
47
|
+
assert_equal File.expand_path('./db/grendb.db'), db_expand_groonga_path
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_db_yaml_path
|
51
|
+
assert_equal 'grendb.yaml', db_yaml_path
|
52
|
+
assert_equal '../grendb.yaml', db_yaml_path('..')
|
53
|
+
assert_equal '/Users/MrRuby/grendb.yaml', db_yaml_path('/Users/MrRuby')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
data/test/test_gren.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/common/util')
|
3
|
+
require File.join(File.dirname(__FILE__), '../lib/common/grensnip')
|
4
|
+
|
5
|
+
class TestGrenSnip < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_snip
|
10
|
+
str = "abcdefghijkmlnopqrstuvwxyz"
|
11
|
+
assert_equal(str, GrenSnip::snip(str, nil))
|
12
|
+
|
13
|
+
str = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|12345678901234567890123456789012345678901234567890123456"
|
14
|
+
assert_equal(str, GrenSnip::snip(str, nil))
|
15
|
+
|
16
|
+
str = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234561"
|
17
|
+
match_datas = []
|
18
|
+
match_datas << str.match(/123456789\|/)
|
19
|
+
assert_equal("12345678901234567890123456789012<<snip>>90123456789012345678901234567890123456789|123456789012345678901234567890123<<snip>>67890123456789012345678901234561", GrenSnip::snip(str, match_datas))
|
20
|
+
|
21
|
+
str = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234561"
|
22
|
+
match_datas = []
|
23
|
+
match_datas << str.match(/123456789\|/)
|
24
|
+
match_datas << str.match(/34567/)
|
25
|
+
assert_equal("12345678901234567890123456789012<<snip>>90123456789012345678901234567890123456789|123456789012345678901234567890123<<snip>>67890123456789012345678901234561", GrenSnip::snip(str, match_datas))
|
26
|
+
|
27
|
+
str = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|123456789012345678901234567890123456789012345678901234561"
|
28
|
+
match_datas = []
|
29
|
+
match_datas << str.match(/123456789\|/)
|
30
|
+
match_datas << str.match(/01234561/)
|
31
|
+
assert_equal("12345678901234567890123456789012<<snip>>90123456789012345678901234567890123456789|123456789012345678901234567890123<<snip>>8901234567890123456789012345678901234561", GrenSnip::snip(str, match_datas))
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2011/02/20
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
9
|
+
require File.join(File.dirname(__FILE__), "../lib/mkgrendb/grendbyaml.rb")
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
class TestGrendbYAML < Test::Unit::TestCase
|
13
|
+
include Mkgrendb
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@prev_dir = Dir.pwd
|
17
|
+
@tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
|
18
|
+
FileUtils.rm_rf(@tmp_dir.to_s)
|
19
|
+
FileUtils.mkdir_p(@tmp_dir.to_s)
|
20
|
+
FileUtils.cd(@tmp_dir.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_000
|
24
|
+
# create
|
25
|
+
yaml = GrendbYAML.create
|
26
|
+
assert_equal yaml.contents, []
|
27
|
+
assert_equal yaml.version, 0.1
|
28
|
+
assert_raise(GrendbYAML::YAMLAlreadyExist) { GrendbYAML.create }
|
29
|
+
|
30
|
+
# load
|
31
|
+
yaml = GrendbYAML.load
|
32
|
+
assert_equal yaml.contents, []
|
33
|
+
assert_equal yaml.version, 0.1
|
34
|
+
|
35
|
+
# load fail
|
36
|
+
FileUtils.mkdir 'loadtest'
|
37
|
+
FileUtils.cd 'loadtest' do
|
38
|
+
assert_raise(GrendbYAML::YAMLNotExist) { GrendbYAML.load }
|
39
|
+
end
|
40
|
+
|
41
|
+
# add
|
42
|
+
yaml.add('dir1')
|
43
|
+
yaml.add('dir2', 'dir3')
|
44
|
+
assert_equal ['dir1', 'dir2', 'dir3'], yaml.directorys
|
45
|
+
|
46
|
+
# remove
|
47
|
+
yaml.add('dir2', 'dir4', 'dir5')
|
48
|
+
yaml.remove('dir5')
|
49
|
+
yaml.remove('dir2', 'dir3')
|
50
|
+
assert_equal ['dir1', 'dir4'], yaml.directorys
|
51
|
+
|
52
|
+
# save
|
53
|
+
yaml.save
|
54
|
+
assert_equal <<EOF, open('grendb.yaml').read
|
55
|
+
---
|
56
|
+
version: 0.1
|
57
|
+
contents:
|
58
|
+
- directory: dir1
|
59
|
+
- directory: dir4
|
60
|
+
EOF
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_001
|
64
|
+
FileUtils.mkdir 'otherpath'
|
65
|
+
|
66
|
+
# create
|
67
|
+
yaml = GrendbYAML.create('otherpath')
|
68
|
+
assert_equal yaml.contents, []
|
69
|
+
assert_equal yaml.version, 0.1
|
70
|
+
assert_raise(GrendbYAML::YAMLAlreadyExist) { GrendbYAML.create('otherpath') }
|
71
|
+
|
72
|
+
# load
|
73
|
+
yaml = GrendbYAML.load 'otherpath'
|
74
|
+
assert_equal yaml.contents, []
|
75
|
+
assert_equal yaml.version, 0.1
|
76
|
+
|
77
|
+
# load fail
|
78
|
+
FileUtils.mkdir 'loadtest'
|
79
|
+
FileUtils.cd 'loadtest' do
|
80
|
+
assert_raise(GrendbYAML::YAMLNotExist) { GrendbYAML.load }
|
81
|
+
end
|
82
|
+
|
83
|
+
# add
|
84
|
+
yaml.add('dir1')
|
85
|
+
yaml.add('dir2', 'dir3')
|
86
|
+
assert_equal ['dir1', 'dir2', 'dir3'], yaml.directorys
|
87
|
+
|
88
|
+
# remove
|
89
|
+
yaml.add('dir2', 'dir4', 'dir5')
|
90
|
+
yaml.remove('dir5')
|
91
|
+
yaml.remove('dir2', 'dir3')
|
92
|
+
assert_equal ['dir1', 'dir4'], yaml.directorys
|
93
|
+
|
94
|
+
# save
|
95
|
+
yaml.save
|
96
|
+
assert_equal <<EOF, open('otherpath/grendb.yaml').read
|
97
|
+
---
|
98
|
+
version: 0.1
|
99
|
+
contents:
|
100
|
+
- directory: dir1
|
101
|
+
- directory: dir4
|
102
|
+
EOF
|
103
|
+
end
|
104
|
+
|
105
|
+
def teardown
|
106
|
+
FileUtils.cd(@prev_dir)
|
107
|
+
FileUtils.rm_rf(@tmp_dir.to_s)
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/cli.rb')
|
3
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/searcher.rb')
|
4
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/viewer.rb')
|
5
|
+
|
6
|
+
class TestGrenwebCli < Test::Unit::TestCase
|
7
|
+
def test_print_default_output
|
8
|
+
# assert_match(/To update this executable/, @stdout)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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")
|
11
|
+
require File.join(File.dirname(__FILE__), "file_test_utils")
|
12
|
+
require File.join(File.dirname(__FILE__), "../lib/grenweb/database")
|
13
|
+
require File.join(File.dirname(__FILE__), "../lib/common/dbdir")
|
14
|
+
require File.join(File.dirname(__FILE__), "../lib/mkgrendb/mkgrendb")
|
15
|
+
require 'stringio'
|
16
|
+
|
17
|
+
class TestMkgrendb < Test::Unit::TestCase
|
18
|
+
include Grenweb
|
19
|
+
include FileTestUtils
|
20
|
+
include CodeStock
|
21
|
+
|
22
|
+
def test_setup_and_open
|
23
|
+
io = StringIO.new
|
24
|
+
obj = ::Mkgrendb::Mkgrendb.new(io)
|
25
|
+
obj.init
|
26
|
+
|
27
|
+
Database.setup('.')
|
28
|
+
Database.instance
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
teardown_custom(true)
|
33
|
+
# teardown_custom(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
3
|
+
require File.join(File.dirname(__FILE__), "../lib/grenweb/html_renderer.rb")
|
4
|
+
|
5
|
+
class TestGrenwebHTMLRendeler < Test::Unit::TestCase
|
6
|
+
include Grenweb
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@rendeler = HTMLRendeler.new('/')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_pagination_line
|
13
|
+
assert_equal("<span class='pagination-link'><a href='?page=1'>test</a></span>\n", @rendeler.pagination_link(1, "test"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_search_summary
|
17
|
+
assert_equal(@rendeler.search_summary(10, 500, 10..20, 0.00893),
|
18
|
+
<<-EOS)
|
19
|
+
<div class='search-summary'>
|
20
|
+
<span class="keyword">10</span>の検索結果:
|
21
|
+
<span class="total-entries">500</span>件中
|
22
|
+
<span class="display-range">10 - 20</span>件(0.00893秒)
|
23
|
+
</div>
|
24
|
+
EOS
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_match_strong
|
28
|
+
assert_equal(@rendeler.match_strong("This is line.", [nil, nil]), "This is line.")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_search_box
|
32
|
+
assert_equal(@rendeler.search_box('test must'), <<-EOF)
|
33
|
+
<form method="post" action="/::search">
|
34
|
+
<p>
|
35
|
+
<input name="query" type="text" size="60" value="test must" />
|
36
|
+
<input type="submit" value="検索" />
|
37
|
+
</p>
|
38
|
+
</form>
|
39
|
+
EOF
|
40
|
+
end
|
41
|
+
end
|