forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguesser_spec.rb
77 lines (65 loc) · 1.9 KB
/
guesser_spec.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
describe Rouge::Guesser do
include Support::Guessing
describe 'guessing with custom globs' do
it 'guesses correctly' do
assert_guess(Rouge::Lexers::Javascript,
:custom_globs => [['*.pl', 'javascript']],
:filename => 'oddly-named.pl'
)
end
end
describe 'guessing with custom guessing strategies' do
it 'guesses in order' do
assert_guess(Rouge::Lexers::Ruby,
:guessers => [
Rouge::Guessers::Source.new('#!/usr/bin/env ruby'),
Rouge::Guessers::Filename.new('foo.md'),
]
)
assert_guess(Rouge::Lexers::Markdown,
:guessers => [
Rouge::Guessers::Filename.new('foo.md'),
Rouge::Guessers::Source.new('#!/usr/bin/env ruby'),
]
)
end
it 'uses custom guessers' do
passed_lexers = nil
custom = Class.new(Rouge::Guesser) {
define_method(:filter) { |lexers|
passed_lexers = lexers
[Rouge::Lexers::Javascript]
}
}.new
assert_guess(Rouge::Lexers::Javascript, :guessers => [custom])
assert { passed_lexers.size == Rouge::Lexer.all.size }
end
it 'sequentially filters' do
custom = Class.new(Rouge::Guesser) {
define_method(:filter) { |lexers|
passed_lexers = lexers
[Rouge::Lexers::Javascript, Rouge::Lexers::Prolog]
}
}.new
assert_guess(Rouge::Lexers::Prolog,
:guessers => [
custom,
Rouge::Guessers::Filename.new('foo.pl'),
]
)
end
it 'filters with a lambda' do
assert_guess(Rouge::Lexers::C,
:guessers => [
->(lexers) { [ Rouge::Lexers::C ] }
]
)
end
end
describe 'modeline guessing' do
it 'guesses by modeline' do
# don't confuse actual editors when opening this file lol
assert_guess(Rouge::Lexers::Ruby, :source => '# v' + 'im: syntax=ruby')
end
end
end