Browse Source

👮 space inside parens

dev
Andy Meneely 10 years ago
parent
commit
0f5b7d0f8e
  1. 4
      lib/squib/graphics/shapes.rb
  2. 2
      lib/squib/graphics/text.rb
  3. 2
      lib/squib/layout_parser.rb
  4. 10
      spec/args/draw_spec.rb
  5. 54
      spec/args/paragraph_spec.rb
  6. 8
      spec/args/sheet_spec.rb
  7. 12
      spec/graphics/cairo_context_wrapper_spec.rb

4
lib/squib/graphics/shapes.rb

@ -52,8 +52,8 @@ module Squib
def grid(box, draw) def grid(box, draw)
x, y, w, h = box.x, box.y, box.width, box.height x, y, w, h = box.x, box.y, box.width, box.height
use_cairo do |cc| use_cairo do |cc|
(x..@width + w).step(w) { |ix| line_xy( ix, y - @height, ix, @height + y, draw) } (x..@width + w).step(w) { |ix| line_xy(ix, y - @height, ix, @height + y, draw) }
(y..@height + h).step(h) { |iy| line_xy( x - @width, iy, @width + x, iy, draw) } (y..@height + h).step(h) { |iy| line_xy(x - @width, iy, @width + x, iy, draw) }
end end
end end

2
lib/squib/graphics/text.rb

@ -28,7 +28,7 @@ module Squib
ink_extents.height = embed_h * Pango::SCALE if ink_extents.height == 0 #JUST embed, bug #134 ink_extents.height = embed_h * Pango::SCALE if ink_extents.height == 0 #JUST embed, bug #134
case valign.to_s.downcase case valign.to_s.downcase
when 'middle' when 'middle'
Pango.pixels( (layout.height - ink_extents.height) / 2) Pango.pixels((layout.height - ink_extents.height) / 2)
when 'bottom' when 'bottom'
Pango.pixels(layout.height - ink_extents.height) Pango.pixels(layout.height - ink_extents.height)
else else

2
lib/squib/layout_parser.rb

@ -33,7 +33,7 @@ module Squib
# Process the extends recursively # Process the extends recursively
# :nodoc: # :nodoc:
# @api private # @api private
def self.recurse_extends(yml, key, visited ) def self.recurse_extends(yml, key, visited)
assert_not_visited(key, visited) assert_not_visited(key, visited)
return yml[key] unless has_extends?(yml, key) return yml[key] unless has_extends?(yml, key)
return yml[key] unless parents_exist?(yml, key) return yml[key] unless parents_exist?(yml, key)

10
spec/args/draw_spec.rb

@ -20,7 +20,7 @@ describe Squib::Args::Draw do
it 'works when specified' do it 'works when specified' do
draw.load!({}) # go right to defaults draw.load!({}) # go right to defaults
expect(draw.stroke_width).to eq( [0.0] ) #ordinarily a non-zero according expect(draw.stroke_width).to eq([0.0]) #ordinarily a non-zero according
end end
end end
@ -57,25 +57,25 @@ describe Squib::Args::Draw do
it 'converts line caps to Cairo constants' do it 'converts line caps to Cairo constants' do
args = { cap: :SQUARE } args = { cap: :SQUARE }
draw.load! args draw.load! args
expect(draw).to have_attributes( cap: [Cairo::LINE_CAP_SQUARE] ) expect(draw).to have_attributes(cap: [Cairo::LINE_CAP_SQUARE])
end end
it 'converts line join' do it 'converts line join' do
args = { join: 'round' } args = { join: 'round' }
draw.load! args draw.load! args
expect(draw).to have_attributes( join: [Cairo::LINE_JOIN_ROUND] ) expect(draw).to have_attributes(join: [Cairo::LINE_JOIN_ROUND])
end end
it 'allows fill_first stroke_strategy' do it 'allows fill_first stroke_strategy' do
args = { stroke_strategy: :FILL_first } args = { stroke_strategy: :FILL_first }
draw.load! args draw.load! args
expect(draw).to have_attributes( stroke_strategy: [:fill_first] ) expect(draw).to have_attributes(stroke_strategy: [:fill_first])
end end
it 'allows stroke_first stroke_strategy' do it 'allows stroke_first stroke_strategy' do
args = { stroke_strategy: ' stroke_FIRST ' } args = { stroke_strategy: ' stroke_FIRST ' }
draw.load! args draw.load! args
expect(draw).to have_attributes( stroke_strategy: [:stroke_first] ) expect(draw).to have_attributes(stroke_strategy: [:stroke_first])
end end
it 'disallows anything not stroke_first and fill_first' do it 'disallows anything not stroke_first and fill_first' do

54
spec/args/paragraph_spec.rb

@ -7,146 +7,146 @@ describe Squib::Args::Paragraph do
context 'str validator' do context 'str validator' do
it 'converts everything to string' do it 'converts everything to string' do
para.load!( { str: 5 } ) para.load!({ str: 5 })
expect(para.str).to eq ['5'] expect(para.str).to eq ['5']
end end
end end
context 'font validator' do context 'font validator' do
it 'uses deck font by default' do it 'uses deck font by default' do
para.load!( {} ) para.load!({})
expect(para.font).to eq ['FooFont 32'] expect(para.font).to eq ['FooFont 32']
end end
it 'uses system default font when deck font is :default' do it 'uses system default font when deck font is :default' do
para = Squib::Args::Paragraph.new(:default) para = Squib::Args::Paragraph.new(:default)
para.load!( {} ) para.load!({})
expect(para.font).to eq [Squib::DEFAULT_FONT] expect(para.font).to eq [Squib::DEFAULT_FONT]
end end
it 'uses specified font when given' do it 'uses specified font when given' do
para.load!( { font: 'MyFont 8' }) para.load!({ font: 'MyFont 8' })
expect(para.font).to eq ['MyFont 8'] expect(para.font).to eq ['MyFont 8']
end end
end end
context 'align validator' do context 'align validator' do
it 'converts to pango left' do it 'converts to pango left' do
para.load!( { align: :left } ) para.load!({ align: :left })
expect(para.align).to eq [Pango::ALIGN_LEFT] expect(para.align).to eq [Pango::ALIGN_LEFT]
end end
it 'converts to pango right' do it 'converts to pango right' do
para.load!( { align: :RIGHT } ) para.load!({ align: :RIGHT })
expect(para.align).to eq [Pango::ALIGN_RIGHT] expect(para.align).to eq [Pango::ALIGN_RIGHT]
end end
it 'converts to pango center' do it 'converts to pango center' do
para.load!( { align: 'center' } ) para.load!({ align: 'center' })
expect(para.align).to eq [Pango::ALIGN_CENTER] expect(para.align).to eq [Pango::ALIGN_CENTER]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( { align: 'foo' } ) }.to raise_error(ArgumentError, 'align must be one of: center, left, right') expect { para.load!({ align: 'foo' }) }.to raise_error(ArgumentError, 'align must be one of: center, left, right')
end end
end end
context 'wrap validator' do context 'wrap validator' do
it 'converts to pango wrap word' do it 'converts to pango wrap word' do
para.load!( { wrap: 'word' } ) para.load!({ wrap: 'word' })
expect(para.wrap).to eq [Pango::WRAP_WORD] expect(para.wrap).to eq [Pango::WRAP_WORD]
end end
it 'converts to pango wrap char' do it 'converts to pango wrap char' do
para.load!( { wrap: 'WORD_ChAr' } ) para.load!({ wrap: 'WORD_ChAr' })
expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR] expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR]
end end
it 'converts to pango wrap char on true' do it 'converts to pango wrap char on true' do
para.load!( { wrap: true } ) para.load!({ wrap: true })
expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR] expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR]
end end
it 'converts to pango wrap char with false' do it 'converts to pango wrap char with false' do
para.load!( { wrap: false } ) para.load!({ wrap: false })
expect(para.wrap).to eq [Pango::WRAP_CHAR] expect(para.wrap).to eq [Pango::WRAP_CHAR]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( { wrap: 'foo' }) }.to raise_error(ArgumentError, 'wrap must be one of: word, char, word_char, true, or false') expect { para.load!({ wrap: 'foo' }) }.to raise_error(ArgumentError, 'wrap must be one of: word, char, word_char, true, or false')
end end
end end
context 'ellipsize validator' do context 'ellipsize validator' do
it 'converts to pango on none and false' do it 'converts to pango on none and false' do
para.load!( { ellipsize: 'none' } ) para.load!({ ellipsize: 'none' })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_NONE] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_NONE]
end end
it 'converts to pango with start' do it 'converts to pango with start' do
para.load!( { ellipsize: :StArt } ) para.load!({ ellipsize: :StArt })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_START] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_START]
end end
it 'converts to pango middle' do it 'converts to pango middle' do
para.load!( { ellipsize: 'middle' } ) para.load!({ ellipsize: 'middle' })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_MIDDLE] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_MIDDLE]
end end
it 'converts to pango end' do it 'converts to pango end' do
para.load!( { ellipsize: 'END' } ) para.load!({ ellipsize: 'END' })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_END] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_END]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( { ellipsize: 'foo' }) }.to raise_error(ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, or false') expect { para.load!({ ellipsize: 'foo' }) }.to raise_error(ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, or false')
end end
end end
context 'justify validator' do context 'justify validator' do
it 'allows nil' do it 'allows nil' do
para.load!( { justify: nil } ) para.load!({ justify: nil })
expect(para.justify).to eq [nil] expect(para.justify).to eq [nil]
end end
it 'can be true' do it 'can be true' do
para.load!( { justify: true } ) para.load!({ justify: true })
expect(para.justify).to eq [true] expect(para.justify).to eq [true]
end end
it 'can be false' do it 'can be false' do
para.load!( { justify: false } ) para.load!({ justify: false })
expect(para.justify).to eq [false] expect(para.justify).to eq [false]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( { justify: 'false' }) }.to raise_error(ArgumentError, 'justify must be one of: nil, true, or false') expect { para.load!({ justify: 'false' }) }.to raise_error(ArgumentError, 'justify must be one of: nil, true, or false')
end end
end end
context 'spacing validator' do context 'spacing validator' do
it 'allows nil' do it 'allows nil' do
para.load!( { spacing: nil } ) para.load!({ spacing: nil })
expect(para.spacing).to eq [nil] expect(para.spacing).to eq [nil]
end end
it 'is converted to Pango space' do it 'is converted to Pango space' do
para.load!( { spacing: 519 } ) para.load!({ spacing: 519 })
expect(para.spacing).to eq [Pango::SCALE * 519.0] expect(para.spacing).to eq [Pango::SCALE * 519.0]
end end
it 'raises an exception if not a float' do it 'raises an exception if not a float' do
expect { para.load!( { spacing: /foo/ }) }.to raise_error(ArgumentError, 'spacing must be a number or nil') expect { para.load!({ spacing: /foo/ }) }.to raise_error(ArgumentError, 'spacing must be a number or nil')
end end
end end
context 'valign validator' do context 'valign validator' do
it 'converts top' do it 'converts top' do
para.load!( { valign: :top } ) para.load!({ valign: :top })
expect(para.valign).to eq ['top'] expect(para.valign).to eq ['top']
end end
it 'raises an exception if not one of the three' do it 'raises an exception if not one of the three' do
expect { para.load!( { valign: 'foo' }) }.to raise_error(ArgumentError, 'valign must be one of: top, middle, bottom') expect { para.load!({ valign: 'foo' }) }.to raise_error(ArgumentError, 'valign must be one of: top, middle, bottom')
end end
end end

8
spec/args/sheet_spec.rb

@ -8,7 +8,7 @@ describe Squib::Args::Sheet do
it 'works when specified' do it 'works when specified' do
sheet.load!({}) # go right to defaults sheet.load!({}) # go right to defaults
expect(sheet.file).to eq( 'foo' ) # dsl method default override expect(sheet.file).to eq('foo') # dsl method default override
end end
end end
@ -31,19 +31,19 @@ describe Squib::Args::Sheet do
it 'computes properly on non-integer' do it 'computes properly on non-integer' do
opts = { columns: 1, rows: :infinite } opts = { columns: 1, rows: :infinite }
sheet.load! opts sheet.load! opts
expect(sheet).to have_attributes( columns: 1, rows: 4 ) expect(sheet).to have_attributes(columns: 1, rows: 4)
end end
it 'computes properly on unspecified rows' do it 'computes properly on unspecified rows' do
opts = { columns: 1 } opts = { columns: 1 }
sheet.load! opts sheet.load! opts
expect(sheet).to have_attributes( columns: 1, rows: 4 ) expect(sheet).to have_attributes(columns: 1, rows: 4)
end end
it 'computes properly on unspecified, too-big column' do it 'computes properly on unspecified, too-big column' do
opts = {} opts = {}
sheet.load! opts sheet.load! opts
expect(sheet).to have_attributes( columns: 5, rows: 1 ) expect(sheet).to have_attributes(columns: 5, rows: 1)
end end
it 'fails on a non-integer column' do it 'fails on a non-integer column' do

12
spec/graphics/cairo_context_wrapper_spec.rb

@ -40,10 +40,10 @@ describe Squib::Graphics::CairoContextWrapper do
expect(cairo).to receive(:set_source).with(dbl) expect(cairo).to receive(:set_source).with(dbl)
end end
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2) (3,4) blue@0 red@1') } it('handles no decimals') { subject.set_source_squibcolor('(1,2) (3,4) blue@0 red@1') }
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0) (3.0,4.0) blue@0 red@1') } it('handles decimals') { subject.set_source_squibcolor('(1.0,2.0) (3.0,4.0) blue@0 red@1') }
it('handles no whitespace') { subject.set_source_squibcolor('(1,2)(3,4)blue@0red@1') } it('handles no whitespace') { subject.set_source_squibcolor('(1,2)(3,4)blue@0red@1') }
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 ) ( 3 , 4 ) blue@0 red@1 ') } it('handles whitespace') { subject.set_source_squibcolor(' ( 1 , 2 ) ( 3 , 4 ) blue@0 red@1 ') }
end end
context 'regex variations for radial gradients' do context 'regex variations for radial gradients' do
@ -58,10 +58,10 @@ describe Squib::Graphics::CairoContextWrapper do
expect(cairo).to receive(:set_source).with(dbl) expect(cairo).to receive(:set_source).with(dbl)
end end
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2,5) (3,4,6) blue@0 red@1') } it('handles no decimals') { subject.set_source_squibcolor('(1,2,5) (3,4,6) blue@0 red@1') }
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0,5.0) (3.0,4.0,6.0) blue@0 red@1') } it('handles decimals') { subject.set_source_squibcolor('(1.0,2.0,5.0) (3.0,4.0,6.0) blue@0 red@1') }
it('handles no whitespace') { subject.set_source_squibcolor('(1,2,5)(3,4,6)blue@0red@1') } it('handles no whitespace') { subject.set_source_squibcolor('(1,2,5)(3,4,6)blue@0red@1') }
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 , 5 ) ( 3 , 4 , 6 ) blue@0 red@1 ') } it('handles whitespace') { subject.set_source_squibcolor(' ( 1 , 2 , 5 ) ( 3 , 4 , 6 ) blue@0 red@1 ') }
end end
context 'regex handles hash notation' do context 'regex handles hash notation' do

Loading…
Cancel
Save