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)
x, y, w, h = box.x, box.y, box.width, box.height
use_cairo do |cc|
(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) }
(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) }
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
case valign.to_s.downcase
when 'middle'
Pango.pixels( (layout.height - ink_extents.height) / 2)
Pango.pixels((layout.height - ink_extents.height) / 2)
when 'bottom'
Pango.pixels(layout.height - ink_extents.height)
else

2
lib/squib/layout_parser.rb

@ -33,7 +33,7 @@ module Squib
# Process the extends recursively
# :nodoc:
# @api private
def self.recurse_extends(yml, key, visited )
def self.recurse_extends(yml, key, visited)
assert_not_visited(key, visited)
return yml[key] unless has_extends?(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
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
@ -57,25 +57,25 @@ describe Squib::Args::Draw do
it 'converts line caps to Cairo constants' do
args = { cap: :SQUARE }
draw.load! args
expect(draw).to have_attributes( cap: [Cairo::LINE_CAP_SQUARE] )
expect(draw).to have_attributes(cap: [Cairo::LINE_CAP_SQUARE])
end
it 'converts line join' do
args = { join: 'round' }
draw.load! args
expect(draw).to have_attributes( join: [Cairo::LINE_JOIN_ROUND] )
expect(draw).to have_attributes(join: [Cairo::LINE_JOIN_ROUND])
end
it 'allows fill_first stroke_strategy' do
args = { stroke_strategy: :FILL_first }
draw.load! args
expect(draw).to have_attributes( stroke_strategy: [:fill_first] )
expect(draw).to have_attributes(stroke_strategy: [:fill_first])
end
it 'allows stroke_first stroke_strategy' do
args = { stroke_strategy: ' stroke_FIRST ' }
draw.load! args
expect(draw).to have_attributes( stroke_strategy: [:stroke_first] )
expect(draw).to have_attributes(stroke_strategy: [:stroke_first])
end
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
it 'converts everything to string' do
para.load!( { str: 5 } )
para.load!({ str: 5 })
expect(para.str).to eq ['5']
end
end
context 'font validator' do
it 'uses deck font by default' do
para.load!( {} )
para.load!({})
expect(para.font).to eq ['FooFont 32']
end
it 'uses system default font when deck font is :default' do
para = Squib::Args::Paragraph.new(:default)
para.load!( {} )
para.load!({})
expect(para.font).to eq [Squib::DEFAULT_FONT]
end
it 'uses specified font when given' do
para.load!( { font: 'MyFont 8' })
para.load!({ font: 'MyFont 8' })
expect(para.font).to eq ['MyFont 8']
end
end
context 'align validator' do
it 'converts to pango left' do
para.load!( { align: :left } )
para.load!({ align: :left })
expect(para.align).to eq [Pango::ALIGN_LEFT]
end
it 'converts to pango right' do
para.load!( { align: :RIGHT } )
para.load!({ align: :RIGHT })
expect(para.align).to eq [Pango::ALIGN_RIGHT]
end
it 'converts to pango center' do
para.load!( { align: 'center' } )
para.load!({ align: 'center' })
expect(para.align).to eq [Pango::ALIGN_CENTER]
end
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
context 'wrap validator' do
it 'converts to pango wrap word' do
para.load!( { wrap: 'word' } )
para.load!({ wrap: 'word' })
expect(para.wrap).to eq [Pango::WRAP_WORD]
end
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]
end
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]
end
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]
end
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
context 'ellipsize validator' 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]
end
it 'converts to pango with start' do
para.load!( { ellipsize: :StArt } )
para.load!({ ellipsize: :StArt })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_START]
end
it 'converts to pango middle' do
para.load!( { ellipsize: 'middle' } )
para.load!({ ellipsize: 'middle' })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_MIDDLE]
end
it 'converts to pango end' do
para.load!( { ellipsize: 'END' } )
para.load!({ ellipsize: 'END' })
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_END]
end
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
context 'justify validator' do
it 'allows nil' do
para.load!( { justify: nil } )
para.load!({ justify: nil })
expect(para.justify).to eq [nil]
end
it 'can be true' do
para.load!( { justify: true } )
para.load!({ justify: true })
expect(para.justify).to eq [true]
end
it 'can be false' do
para.load!( { justify: false } )
para.load!({ justify: false })
expect(para.justify).to eq [false]
end
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
context 'spacing validator' do
it 'allows nil' do
para.load!( { spacing: nil } )
para.load!({ spacing: nil })
expect(para.spacing).to eq [nil]
end
it 'is converted to Pango space' do
para.load!( { spacing: 519 } )
para.load!({ spacing: 519 })
expect(para.spacing).to eq [Pango::SCALE * 519.0]
end
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
context 'valign validator' do
it 'converts top' do
para.load!( { valign: :top } )
para.load!({ valign: :top })
expect(para.valign).to eq ['top']
end
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

8
spec/args/sheet_spec.rb

@ -8,7 +8,7 @@ describe Squib::Args::Sheet do
it 'works when specified' do
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
@ -31,19 +31,19 @@ describe Squib::Args::Sheet do
it 'computes properly on non-integer' do
opts = { columns: 1, rows: :infinite }
sheet.load! opts
expect(sheet).to have_attributes( columns: 1, rows: 4 )
expect(sheet).to have_attributes(columns: 1, rows: 4)
end
it 'computes properly on unspecified rows' do
opts = { columns: 1 }
sheet.load! opts
expect(sheet).to have_attributes( columns: 1, rows: 4 )
expect(sheet).to have_attributes(columns: 1, rows: 4)
end
it 'computes properly on unspecified, too-big column' do
opts = {}
sheet.load! opts
expect(sheet).to have_attributes( columns: 5, rows: 1 )
expect(sheet).to have_attributes(columns: 5, rows: 1)
end
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)
end
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 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 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
context 'regex variations for radial gradients' do
@ -58,10 +58,10 @@ describe Squib::Graphics::CairoContextWrapper do
expect(cairo).to receive(:set_source).with(dbl)
end
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 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 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
context 'regex handles hash notation' do

Loading…
Cancel
Save