2009-11-19 10:26:35 +00:00
|
|
|
require 'test_helper'
|
2008-11-29 09:08:07 +00:00
|
|
|
|
|
|
|
class SassExtensionsTest < Test::Unit::TestCase
|
|
|
|
def test_simple
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "a b", evaluate(%Q{nest("a", "b")})
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
|
|
|
def test_left_side_expansion
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "a c, b c", evaluate(%Q{nest("a, b", "c")})
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
|
|
|
def test_right_side_expansion
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "a b, a c", evaluate(%Q{nest("a", "b, c")})
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
|
|
|
def test_both_sides_expansion
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "a c, a d, b c, b d", evaluate(%Q{nest("a, b", "c, d")})
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
|
|
|
def test_three_selectors_expansion
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "a b, a c, a d", evaluate(%Q{nest("a", "b, c, d")})
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
|
|
|
def test_third_argument_expansion
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "a b e, a b f, a c e, a c f, a d e, a d f", evaluate(%Q{nest("a", "b, c, d", "e, f")})
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
2009-05-07 19:01:03 +00:00
|
|
|
|
2010-04-13 08:06:56 +00:00
|
|
|
def test_enumerate
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal ".grid-1, .grid-2, .grid-3", evaluate(%Q{enumerate(".grid", 1, 3, "-")})
|
2010-04-13 08:06:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_append_selector
|
2010-04-13 17:02:55 +00:00
|
|
|
assert_equal "div.bar", evaluate(%Q{append_selector("div", ".bar")})
|
|
|
|
assert_equal ".foo1.bar1, .foo1.bar2, .foo2.bar1, .foo2.bar2", evaluate(%Q{append_selector(".foo1, .foo2", ".bar1, .bar2")})
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_headers
|
|
|
|
assert_equal "h1, h2, h3, h4, h5, h6", evaluate("headers()")
|
|
|
|
assert_equal "h1, h2, h3, h4, h5, h6", evaluate("headers(all)")
|
|
|
|
assert_equal "h1, h2, h3, h4", evaluate("headers(4)")
|
|
|
|
assert_equal "h2, h3", evaluate("headers(2,3)")
|
|
|
|
assert_equal "h4, h5, h6", evaluate("headers(4,6)")
|
2010-04-13 08:06:56 +00:00
|
|
|
end
|
|
|
|
|
2010-11-12 04:50:17 +00:00
|
|
|
def test_scale_lightness
|
|
|
|
assert_equal "75%", evaluate("lightness(scale-lightness(hsl(50deg, 50%, 50%), 50%))")
|
|
|
|
assert_equal "25%", evaluate("lightness(scale-lightness(hsl(50deg, 50%, 50%), -50%))")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_adjust_lightness
|
|
|
|
assert_equal "75%", evaluate("lightness(adjust-lightness(hsl(50deg, 50%, 50%), 25%))")
|
|
|
|
assert_equal "25%", evaluate("lightness(adjust-lightness(hsl(50deg, 50%, 50%), -25%))")
|
|
|
|
assert_equal "100%", evaluate("lightness(adjust-lightness(hsl(50deg, 50%, 50%), 500%))")
|
|
|
|
assert_equal "0%", evaluate("lightness(adjust-lightness(hsl(50deg, 50%, 50%), -500%))")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_scale_saturation
|
|
|
|
assert_equal "75%", evaluate("saturation(scale-saturation(hsl(50deg, 50%, 50%), 50%))")
|
|
|
|
assert_equal "25%", evaluate("saturation(scale-saturation(hsl(50deg, 50%, 50%), -50%))")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_adjust_saturation
|
|
|
|
assert_equal "75%", evaluate("saturation(adjust-saturation(hsl(50deg, 50%, 50%), 25%))")
|
|
|
|
assert_equal "25%", evaluate("saturation(adjust-saturation(hsl(50deg, 50%, 50%), -25%))")
|
|
|
|
end
|
|
|
|
|
2010-11-13 08:46:41 +00:00
|
|
|
def test_if_function
|
|
|
|
assert_equal "no", evaluate("if(false, yes, no)")
|
|
|
|
assert_equal "yes", evaluate("if(true, yes, no)")
|
|
|
|
end
|
|
|
|
|
2012-03-08 09:41:52 +00:00
|
|
|
def test_math_functions
|
2011-08-02 22:49:06 +00:00
|
|
|
assert_equal "0.841", evaluate("sin(1)")
|
2010-11-12 23:14:37 +00:00
|
|
|
assert_equal "0.841px", evaluate("sin(1px)")
|
|
|
|
assert_equal "0.0", evaluate("sin(pi())")
|
|
|
|
assert_equal "1", evaluate("sin(pi() / 2)")
|
2012-03-08 22:55:49 +00:00
|
|
|
assert_equal "0.0", evaluate("sin(180deg)")
|
2010-11-12 23:14:37 +00:00
|
|
|
assert_equal "-1", evaluate("sin(3* pi() / 2)")
|
|
|
|
assert_equal "-1", evaluate("cos(pi())")
|
2012-03-08 22:55:49 +00:00
|
|
|
assert_equal "1", evaluate("cos(360deg)")
|
2011-08-02 22:49:06 +00:00
|
|
|
assert_equal "-0.176", evaluate("sin(270)")
|
2010-11-12 23:14:37 +00:00
|
|
|
assert_equal "1", evaluate("cos(2*pi())")
|
|
|
|
assert_equal "0.0", evaluate("cos(pi() / 2)")
|
|
|
|
assert_equal "0.0", evaluate("cos(3* pi() / 2)")
|
|
|
|
assert_equal "0.0", evaluate("tan(pi())")
|
|
|
|
assert_equal "0.0", evaluate("tan(360deg)")
|
2011-08-02 22:49:06 +00:00
|
|
|
assert_equal "0.959", evaluate("sin(360)")
|
2010-11-12 23:14:37 +00:00
|
|
|
assert evaluate("tan(pi()/2 - 0.0001)").to_f > 1000, evaluate("tan(pi()/2 - 0.0001)")
|
|
|
|
assert evaluate("tan(pi()/2 + 0.0001)").to_f < -1000, evaluate("tan(pi()/2 - 0.0001)")
|
2012-03-08 22:55:49 +00:00
|
|
|
assert_equal "0.693px", evaluate("log(2px)")
|
|
|
|
assert_equal "0", evaluate("log(1)")
|
|
|
|
assert_equal "1", evaluate("log(e())")
|
2012-03-08 09:41:52 +00:00
|
|
|
assert_equal "5px", evaluate("sqrt(25px)")
|
|
|
|
assert_equal "25px", evaluate("pow(5px, 2)")
|
2012-03-08 22:55:49 +00:00
|
|
|
assert_equal "79.432px", evaluate("pow(5px, e())")
|
2010-11-12 23:14:37 +00:00
|
|
|
end
|
|
|
|
|
2010-11-27 23:34:29 +00:00
|
|
|
def test_blank
|
|
|
|
assert_equal "false", evaluate("blank(true)")
|
|
|
|
assert_equal "true", evaluate("blank(false)")
|
|
|
|
assert_equal "true", evaluate("blank('')")
|
|
|
|
assert_equal "true", evaluate("blank(' ')")
|
|
|
|
assert_equal "true", evaluate("blank(-compass-space-list(' '))")
|
|
|
|
end
|
|
|
|
|
2011-03-30 17:45:27 +00:00
|
|
|
def test_css2_fallback
|
|
|
|
assert_equal "css3", evaluate("css2-fallback(css3, css2)")
|
|
|
|
assert_equal "css2", evaluate("-css2(css2-fallback(css3, css2))")
|
|
|
|
assert_equal "true", evaluate("prefixed(-css2, css2-fallback(css3, css2))")
|
|
|
|
end
|
|
|
|
|
2011-09-09 00:59:03 +00:00
|
|
|
def test_font_files
|
|
|
|
assert_equal '', evaluate('font_files()')
|
|
|
|
assert_equal "url(/font/name.woff) format('woff'), url(/fonts/name.ttf) format('truetype'), url(/fonts/name.svg#fontpath) format('svg')", evaluate("font-files('/font/name.woff', woff, '/fonts/name.ttf', truetype, '/fonts/name.svg#fontpath', svg)")
|
2011-09-09 03:12:11 +00:00
|
|
|
|
|
|
|
assert_equal "url(/font/with/right_ext.woff) format('woff')", evaluate("font_files('/font/with/right_ext.woff')")
|
|
|
|
assert_equal "url(/font/with/wrong_ext.woff) format('svg')", evaluate("font_files('/font/with/wrong_ext.woff', 'svg')")
|
|
|
|
assert_equal "url(/font/with/no_ext) format('opentype')", evaluate("font_files('/font/with/no_ext', 'otf')")
|
|
|
|
assert_equal "url(/font/with/weird.ext) format('truetype')", evaluate("font_files('/font/with/weird.ext', 'ttf')")
|
|
|
|
|
|
|
|
assert_equal "url(/font/with/right_ext.woff) format('woff'), url(/font/with/right_ext_also.otf) format('opentype')", evaluate("font_files('/font/with/right_ext.woff', '/font/with/right_ext_also.otf')")
|
|
|
|
assert_equal "url(/font/with/wrong_ext.woff) format('truetype'), url(/font/with/right_ext.otf) format('opentype')", evaluate("font_files('/font/with/wrong_ext.woff', 'ttf', '/font/with/right_ext.otf')")
|
|
|
|
|
|
|
|
assert_nothing_raised Sass::SyntaxError do
|
2011-09-09 00:59:03 +00:00
|
|
|
evaluate("font-files('/font/name.woff')")
|
|
|
|
end
|
2011-09-09 03:12:11 +00:00
|
|
|
|
|
|
|
assert_raises Sass::SyntaxError do
|
|
|
|
evaluate("font-files('/font/name.ext')")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises Sass::SyntaxError do
|
|
|
|
evaluate("font-files('/font/name.ext', 'nonsense')")
|
|
|
|
end
|
2011-09-09 00:59:03 +00:00
|
|
|
end
|
|
|
|
|
2011-08-27 07:38:38 +00:00
|
|
|
%w(stylesheet_url font_url image_url generated_image_url).each do |helper|
|
|
|
|
class_eval %Q{
|
|
|
|
def test_#{helper}_helper_defers_to_existing_helper
|
|
|
|
c = Class.new do
|
|
|
|
def #{helper}(*args)
|
|
|
|
:original
|
|
|
|
end
|
|
|
|
end
|
|
|
|
c.send(:include, Compass::SassExtensions::Functions::Urls)
|
|
|
|
assert_equal :original, c.new.#{helper}("logo.png")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2011-09-07 20:06:01 +00:00
|
|
|
def test_inline_font_files
|
|
|
|
Compass.configuration.fonts_path = File.expand_path "../fixtures/fonts", File.dirname(__FILE__)
|
|
|
|
base64_string = File.read(File.join(Compass.configuration.fonts_path, "bgrove.base64.txt")).chomp
|
|
|
|
assert_equal "url('data:font/truetype;base64,#{base64_string}') format('truetype')", evaluate("inline_font_files('bgrove.ttf', truetype)")
|
|
|
|
end
|
2011-11-17 20:07:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_image_size_should_respond_to_to_path
|
|
|
|
object = mock()
|
|
|
|
object.expects(:to_path).returns('foo.jpg')
|
|
|
|
object.expects(:respond_to?).with(:to_path).returns(true)
|
|
|
|
|
|
|
|
Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(object)
|
|
|
|
end
|
|
|
|
|
2011-12-24 00:53:48 +00:00
|
|
|
def test_reject
|
|
|
|
assert_equal "b d", evaluate("reject(a b c d, a, c)")
|
|
|
|
assert_equal "a b c d", evaluate("reject(a b c d, e)")
|
|
|
|
end
|
|
|
|
|
2009-05-07 19:01:03 +00:00
|
|
|
protected
|
2010-04-13 17:02:55 +00:00
|
|
|
def evaluate(value)
|
|
|
|
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|
2009-11-19 10:26:35 +00:00
|
|
|
end
|