forked from prawnpdf/prawn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont_metric_cache_spec.rb
52 lines (36 loc) · 1.37 KB
/
font_metric_cache_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
# encoding: utf-8
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
require 'pathname'
describe "Font metrics caching" do
let(:document) { Prawn::Document.new }
subject { Prawn::FontMetricCache.new( document ) }
it "should start with an empty cache" do
subject.instance_variable_get( :@cache ).should be_empty
end
it "should cache the width of the provided string" do
subject.width_of('M', {})
subject.instance_variable_get( :@cache ).should have(1).entry
end
it "should only cache a single copy of the same string" do
subject.width_of('M', {})
subject.width_of('M', {})
subject.instance_variable_get( :@cache ).should have(1).entry
end
it "should cache different copies for different strings" do
subject.width_of('M', {})
subject.width_of('W', {})
subject.instance_variable_get( :@cache ).should have(2).entries
end
it "should cache different copies of the same string with different font sizes" do
subject.width_of('M', {})
document.font_size 24
subject.width_of('M', {})
subject.instance_variable_get( :@cache ).should have(2).entries
end
it "should cache different copies of the same string with different fonts" do
subject.width_of('M', {})
document.font 'Courier'
subject.width_of('M', {})
subject.instance_variable_get( :@cache ).should have(2).entries
end
end