1
1
require 'test/unit'
2
+ require File . expand_path ( '../../lib/assert_warning' , __FILE__ )
3
+
2
4
require 'coderay/helpers/file_type'
3
5
4
6
class FileTypeTests < Test ::Unit ::TestCase
@@ -9,31 +11,22 @@ def test_fetch
9
11
assert_raise FileType ::UnknownFileType do
10
12
FileType . fetch ''
11
13
end
12
-
14
+
13
15
assert_throws :not_found do
14
16
FileType . fetch '.' do
15
17
throw :not_found
16
18
end
17
19
end
18
-
20
+
19
21
assert_equal :default , FileType . fetch ( 'c' , :default )
20
22
end
21
23
22
24
def test_block_supersedes_default_warning
23
- stderr , fake_stderr = $stderr, Object . new
24
- begin
25
- $err = ''
26
- def fake_stderr . write x
27
- $err << x
28
- end
29
- $stderr = fake_stderr
25
+ assert_warning 'Block supersedes default value argument; use either.' do
30
26
FileType . fetch ( 'c' , :default ) { }
31
- assert_equal "Block supersedes default value argument; use either.\n " , $err
32
- ensure
33
- $stderr = stderr
34
27
end
35
28
end
36
-
29
+
37
30
def test_ruby
38
31
assert_equal :ruby , FileType [ __FILE__ ]
39
32
assert_equal :ruby , FileType [ 'test.rb' ]
@@ -48,7 +41,7 @@ def test_ruby
48
41
assert_not_equal :ruby , FileType [ 'set.rb/set' ]
49
42
assert_not_equal :ruby , FileType [ '~/projects/blabla/rb' ]
50
43
end
51
-
44
+
52
45
def test_c
53
46
assert_equal :c , FileType [ 'test.c' ]
54
47
assert_equal :c , FileType [ 'C:\\Program Files\\x\\y\\c\\test.h' ]
@@ -57,7 +50,7 @@ def test_c
57
50
assert_not_equal :c , FileType [ 'set.h/set' ]
58
51
assert_not_equal :c , FileType [ '~/projects/blabla/c' ]
59
52
end
60
-
53
+
61
54
def test_cpp
62
55
assert_equal :cpp , FileType [ 'test.c++' ]
63
56
assert_equal :cpp , FileType [ 'test.cxx' ]
@@ -68,22 +61,22 @@ def test_cpp
68
61
assert_not_equal :cpp , FileType [ 'test.c' ]
69
62
assert_not_equal :cpp , FileType [ 'test.h' ]
70
63
end
71
-
64
+
72
65
def test_html
73
66
assert_equal :page , FileType [ 'test.htm' ]
74
67
assert_equal :page , FileType [ 'test.xhtml' ]
75
68
assert_equal :page , FileType [ 'test.html.xhtml' ]
76
69
assert_equal :erb , FileType [ '_form.rhtml' ]
77
70
assert_equal :erb , FileType [ '_form.html.erb' ]
78
71
end
79
-
72
+
80
73
def test_yaml
81
74
assert_equal :yaml , FileType [ 'test.yml' ]
82
75
assert_equal :yaml , FileType [ 'test.yaml' ]
83
76
assert_equal :yaml , FileType [ 'my.html.yaml' ]
84
77
assert_not_equal :yaml , FileType [ 'YAML' ]
85
78
end
86
-
79
+
87
80
def test_pathname
88
81
require 'pathname'
89
82
pn = Pathname . new 'test.rb'
@@ -92,7 +85,7 @@ def test_pathname
92
85
assert_equal :ruby , FileType [ dir + pn ]
93
86
assert_equal :cpp , FileType [ dir + 'test.cpp' ]
94
87
end
95
-
88
+
96
89
def test_no_shebang
97
90
dir = './test'
98
91
if File . directory? dir
@@ -119,5 +112,5 @@ def test_shebang
119
112
File . open ( tmpfile , 'w' ) { |f | f . puts '#!/usr/bin/env ruby' }
120
113
assert_equal :ruby , FileType [ tmpfile , true ]
121
114
end
122
-
115
+
123
116
end
0 commit comments