forked from github-linguist/linguist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_blob.rb
340 lines (285 loc) · 12.7 KB
/
test_blob.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
require 'linguist/file_blob'
require 'test/unit'
require 'mime/types'
class TestBlob < Test::Unit::TestCase
include Linguist
def fixtures_path
File.expand_path("../fixtures", __FILE__)
end
def blob(name)
FileBlob.new(File.join(fixtures_path, name), fixtures_path)
end
def test_name
assert_equal "foo.rb", blob("foo.rb").name
end
def test_pathname
assert_equal Pathname.new("foo.rb"), blob("foo.rb").pathname
end
def test_mime_type
assert_equal "application/octet-stream", blob("dog.o").mime_type
assert_equal "application/postscript", blob("octocat.ai").mime_type
assert_equal "application/ruby", blob("grit.rb").mime_type
assert_equal "application/sh", blob("script.sh").mime_type
assert_equal "application/xml", blob("bar.xml").mime_type
assert_equal "text/plain", blob("README").mime_type
end
def test_content_type
assert_equal "application/octet-stream", blob("dog.o").content_type
assert_equal "application/pdf", blob("foo.pdf").content_type
assert_equal "image/png", blob("foo.png").content_type
assert_equal "text/plain; charset=utf8", blob("README").content_type
assert_equal "text/plain; charset=utf8", blob("foo.html").content_type
assert_equal "text/plain; charset=utf8", blob("foo.pl").content_type
assert_equal "text/plain; charset=utf8", blob("foo.py").content_type
assert_equal "text/plain; charset=utf8", blob("foo.rb").content_type
assert_equal "text/plain; charset=utf8", blob("foo.sh").content_type
assert_equal "text/plain; charset=utf8", blob("foo.xhtml").content_type
assert_equal "text/plain; charset=utf8", blob("foo.xml").content_type
end
def test_disposition
assert_equal "attachment; filename=foo+bar.jar", blob("foo bar.jar").disposition
assert_equal "attachment; filename=foo.bin", blob("foo.bin").disposition
assert_equal "attachment; filename=linguist.gem", blob("pkg/linguist.gem").disposition
assert_equal "attachment; filename=octocat.ai", blob("octocat.ai").disposition
assert_equal "inline", blob("README").disposition
assert_equal "inline", blob("foo.txt").disposition
assert_equal "inline", blob("grit.rb").disposition
assert_equal "inline", blob("octocat.png").disposition
end
def test_data
assert_equal "module Foo\nend\n", blob("foo.rb").data
end
def test_lines
assert_equal ["module Foo", "end", ""], blob("foo.rb").lines
end
def test_size
assert_equal 15, blob("foo.rb").size
end
def test_loc
assert_equal 3, blob("foo.rb").loc
end
def test_sloc
assert_equal 2, blob("foo.rb").sloc
end
def test_binary
assert blob("git.deb").binary?
assert blob("git.exe").binary?
assert blob("linguist.gem").binary?
assert blob("octocat.ai").binary?
assert blob("octocat.png").binary?
assert !blob("README").binary?
assert !blob("file.txt").binary?
assert !blob("foo.rb").binary?
assert !blob("script.pl").binary?
end
def test_text
assert blob("README").text?
assert blob("file.json").text?
assert blob("file.txt").text?
assert blob("md").text?
assert blob("script.sh").text?
assert blob("tender.md").text?
assert blob("txt").text?
assert blob("zip").text?
end
def test_image
assert blob("octocat.gif").image?
assert blob("octocat.jpeg").image?
assert blob("octocat.jpg").image?
assert blob("octocat.png").image?
assert !blob("octocat.ai").image?
assert !blob("octocat.psd").image?
end
def test_viewable
assert blob("README").viewable?
assert blob("foo.rb").viewable?
assert blob("script.pl").viewable?
assert !blob("linguist.gem").viewable?
assert !blob("octocat.ai").viewable?
assert !blob("octocat.png").viewable?
end
def test_generated
assert !blob("README").generated?
assert blob("MainMenu.xib").generated?
assert blob("MainMenu.nib").generated?
assert blob("project.pbxproj").generated?
# Long line
assert !blob("uglify.js").generated?
# Inlined JS, but mostly code
assert !blob("json2_backbone.js").generated?
# Minified JS
assert !blob("jquery-1.6.1.js").generated?
assert blob("jquery-1.6.1.min.js").generated?
assert blob("jquery-1.4.2.min.js").generated?
# CoffeScript JS
# These examples are to basic to tell
assert !blob("coffee/empty.js").generated?
assert !blob("coffee/hello.js").generated?
assert blob("coffee/intro.js").generated?
assert blob("coffee/classes.js").generated?
end
def test_vendored
assert !blob("README").vendored?
# Node depedencies
assert blob("node_modules/coffee-script/lib/coffee-script.js").vendored?
# Rails vendor/
assert blob("vendor/plugins/will_paginate/lib/will_paginate.rb").vendored?
# C deps
assert blob("deps/http_parser/http_parser.c").vendored?
assert blob("deps/v8/src/v8.h").vendored?
# Prototype
assert !blob("public/javascripts/application.js").vendored?
assert blob("public/javascripts/prototype.js").vendored?
assert blob("public/javascripts/effects.js").vendored?
assert blob("public/javascripts/controls.js").vendored?
assert blob("public/javascripts/dragdrop.js").vendored?
# jQuery
assert blob("jquery.js").vendored?
assert blob("public/javascripts/jquery.js").vendored?
assert blob("public/javascripts/jquery.min.js").vendored?
assert blob("public/javascripts/jquery-1.5.2.js").vendored?
assert blob("public/javascripts/jquery-1.6.1.js").vendored?
assert blob("public/javascripts/jquery-1.6.1.min.js").vendored?
assert !blob("public/javascripts/jquery.github.menu.js").vendored?
# MooTools
assert blob("public/javascripts/mootools-core-1.3.2-full-compat.js").vendored?
assert blob("public/javascripts/mootools-core-1.3.2-full-compat-yc.js").vendored?
# Dojo
assert blob("public/javascripts/dojo.js").vendored?
# MochiKit
assert blob("public/javascripts/MochiKit.js").vendored?
# YUI
assert blob("public/javascripts/yahoo-dom-event.js").vendored?
assert blob("public/javascripts/yahoo-min.js").vendored?
assert blob("public/javascripts/yuiloader-dom-event.js").vendored?
# LESS
assert blob("public/javascripts/less-1.1.0.js").vendored?
assert blob("public/javascripts/less-1.1.0.min.js").vendored?
# WYS editors
assert blob("public/javascripts/ckeditor.js").vendored?
assert blob("public/javascripts/tiny_mce.js").vendored?
assert blob("public/javascripts/tiny_mce_popup.js").vendored?
assert blob("public/javascripts/tiny_mce_src.js").vendored?
# Fabric
assert blob("fabfile.py").vendored?
end
def test_indexable
assert blob("file.txt").indexable?
assert blob("foo.rb").indexable?
assert !blob("defun.kt").indexable?
assert !blob("dump.sql").indexable?
assert !blob("github.po").indexable?
assert !blob("linguist.gem").indexable?
end
def test_language
assert_equal Language['C'], blob("hello.c").language
assert_equal Language['C'], blob("hello.h").language
assert_equal Language['C++'], blob("bar.h").language
assert_equal Language['C++'], blob("bar.hpp").language
assert_equal Language['C++'], blob("hello.cpp").language
assert_equal Language['C++'], blob("cuda.cu").language
assert_equal Language['GAS'], blob("hello.s").language
assert_equal Language['Objective-C'], blob("Foo.h").language
assert_equal Language['Objective-C'], blob("Foo.m").language
assert_equal Language['Objective-C'], blob("FooAppDelegate.h").language
assert_equal Language['Objective-C'], blob("FooAppDelegate.m").language
assert_equal Language['Objective-C'], blob("hello.m").language
assert_equal Language['OpenCL'], blob("fft.cl").language
assert_equal Language['Ruby'], blob("foo.rb").language
assert_equal Language['Ruby'], blob("script.rb").language
assert_equal Language['Ruby'], blob("wrong_shebang.rb").language
assert_nil blob("octocat.png").language
# .r disambiguation
assert_equal Language['R'], blob("hello-r.R").language
assert_equal Language['Rebol'], blob("hello-rebol.r").language
# ML
assert_equal Language['OCaml'], blob("Foo.ml").language
assert_equal Language['Standard ML'], blob("Foo.sig").language
assert_equal Language['Standard ML'], blob("Foo.sml").language
# Config files
assert_equal Language['INI'], blob(".gitconfig").language
assert_equal Language['Shell'], blob(".bash_profile").language
assert_equal Language['Shell'], blob(".bashrc").language
assert_equal Language['Shell'], blob(".profile").language
assert_equal Language['Shell'], blob(".zlogin").language
assert_equal Language['Shell'], blob(".zshrc").language
assert_equal Language['VimL'], blob(".gvimrc").language
assert_equal Language['VimL'], blob(".vimrc").language
assert_equal Language['YAML'], blob(".gemrc").language
assert_nil blob("blank").language
assert_nil blob("README").language
# https://github.com/xquery/xprocxq/blob/master/src/xquery/xproc.xqm
assert_equal Language['XQuery'], blob("xproc.xqm").language
# https://github.com/wycats/osx-window-sizing/blob/master/center.applescript
assert_equal Language['AppleScript'], blob("center.scpt").language
assert_equal Language['AppleScript'], blob("center.applescript").language
# https://github.com/Araq/Nimrod/tree/master/examples
assert_equal Language['Nimrod'], blob("foo.nim").language
# http://supercollider.sourceforge.net/
# https://github.com/drichert/BCR2000.sc/blob/master/BCR2000.sc
assert_equal Language['SuperCollider'], blob("BCR2000.sc").language
# https://github.com/gradleware/oreilly-gradle-book-examples/blob/master/ant-antbuilder/build.gradle
assert_equal Language['Groovy'], blob("build.gradle").language
# http://docs.racket-lang.org/scribble/
assert_equal Language['Racket'], blob("scribble.scrbl").language
end
def test_lexer
assert_equal Lexer['Diff'], blob("dude-thing-okay--001.patch").lexer
assert_equal Lexer['JavaScript'], blob("dude.js").lexer
assert_equal Lexer['Ruby'], blob("Capfile").lexer
assert_equal Lexer['Ruby'], blob("grit.rb").lexer
assert_equal Lexer['Scheme'], blob("dude.el").lexer
assert_equal Lexer['Text only'], blob("README").lexer
end
def test_shebang_script
assert_equal 'sh', blob("script.sh").shebang_script
assert_equal 'bash', blob("script.bash").shebang_script
assert_equal 'zsh', blob("script.zsh").shebang_script
assert_equal 'perl', blob("script.pl").shebang_script
assert_equal 'ruby', blob("script.rb").shebang_script
assert_equal 'ruby', blob("script2.rb").shebang_script
assert_equal 'python', blob("script.py").shebang_script
assert_equal 'node', blob("script.js").shebang_script
assert_equal 'groovy', blob("script.groovy").shebang_script
assert_equal 'macruby', blob("script.mrb").shebang_script
assert_equal 'rake', blob("script.rake").shebang_script
assert_equal 'foo', blob("script.foo").shebang_script
assert_equal 'nush', blob("script.nu").shebang_script
assert_equal 'scala', blob("script.scala").shebang_script
assert_equal 'racket', blob("script.rkt").shebang_script
assert_equal nil, blob("foo.rb").shebang_script
end
def test_shebang_language
assert_equal Language['Shell'], blob("script.sh").shebang_language
assert_equal Language['Shell'], blob("script.bash").shebang_language
assert_equal Language['Shell'], blob("script.zsh").shebang_language
assert_equal Language['Perl'], blob("script.pl").shebang_language
assert_equal Language['Ruby'], blob("script.rb").shebang_language
assert_equal Language['Python'], blob("script.py").shebang_language
assert_equal Language['JavaScript'], blob("script.js").shebang_language
assert_equal Language['Groovy'], blob("script.groovy").shebang_language
assert_equal Language['Ruby'], blob("script.mrb").shebang_language
assert_equal Language['Ruby'], blob("script.rake").shebang_language
assert_equal Language['Nu'], blob("script.nu").shebang_language
assert_equal Language['Scala'], blob("script.scala").shebang_language
assert_equal Language['Racket'], blob("script.rkt").shebang_language
assert_equal nil, blob("script.foo").shebang_language
assert_equal nil, blob("foo.rb").shebang_language
end
if Lexer.has_pygments?
def test_colorize
assert_equal <<-HTML, blob("foo.rb").colorize
<div class="highlight"><pre><span class="k">module</span> <span class="nn">Foo</span>
<span class="k">end</span>
</pre>
</div>
HTML
end
def test_colorize_without_wrapper
assert_equal <<-HTML, blob("foo.rb").colorize_without_wrapper
<span class="k">module</span> <span class="nn">Foo</span>
<span class="k">end</span>
HTML
end
end
end