forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme_spec.rb
52 lines (41 loc) · 1.36 KB
/
theme_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
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
describe Rouge::Theme do
def squish(str)
str.strip.gsub(/\s+/, ' ')
end
class MyTheme < Rouge::CSSTheme
style Literal::String, :fg => '#003366', :bold => true
style Literal::String::Backtick, :fg => '#555555', :italic => true
end
let(:theme) { MyTheme.new }
it 'auto-fills css classes' do
rendered = theme.render
# should also style, for example, String.Char
assert { rendered =~ /\.sc/ }
# and it should only style String.Backtick once
assert { rendered =~ /\.sb/ }
assert { $~.size == 1 }
end
it 'renders a style' do
output = Rouge::Theme::Style[:bold => true].render('.foo')
expected = <<-css
.foo {
font-weight: bold;
}
css
assert { squish(output) == squish(expected) }
end
it 'fetches a style for a token' do
style = theme.style_for(Rouge::Token['Literal.String'])
assert { style == { :fg => '#003366', :bold => true } }
end
it 'fetches a the closest style for a token' do
style = theme.style_for(Rouge::Token['Literal.String.Backtick'])
assert { style == { :fg => '#555555', :italic => true } }
end
it 'fetches style from ancestor token when no style is defined' do
style = theme.style_for(Rouge::Token['Literal.String.Char'])
assert { style == { :fg => '#003366', :bold => true } }
end
end