def test_rgba(calc): # four args (css-style) assert calc('rgba(128, 192, 224, 0.5)') == ColorValue.from_rgb(128/255, 192/255, 224/255, 0.5) assert calc('rgba(20%, 40%, 60%, 0.7)') == ColorValue.from_rgb(0.2, 0.4, 0.6, 0.7) # two args (modify alpha of existing color) assert calc('rgba(red, 0.4)') == ColorValue.from_rgb(1., 0., 0., 0.4)
def test_hsl(calc): # Examples from the CSS 3 color spec, which Sass uses # (http://www.w3.org/TR/css3-color/#hsl-color) assert calc('hsl(0, 100%, 50%)') == ColorValue.from_rgb(1., 0., 0.) assert calc('hsl(120, 100%, 50%)') == ColorValue.from_rgb(0., 1., 0.) assert calc('hsl(120, 100%, 25%)') == ColorValue.from_rgb(0., 0.5, 0.) assert calc('hsl(120, 100%, 75%)') == ColorValue.from_rgb(0.5, 1., 0.5) assert calc('hsl(120, 75%, 75%)') == ColorValue.from_rgb(0.5625, 0.9375, 0.5625)
def test_hsl(calc): # Examples from the CSS 3 color spec, which Sass uses # (http://www.w3.org/TR/css3-color/#hsl-color) assert calc('hsl(0, 100%, 50%)') == ColorValue.from_rgb(1., 0., 0.) assert calc('hsl(120, 100%, 50%)') == ColorValue.from_rgb(0., 1., 0.) assert calc('hsl(120, 100%, 25%)') == ColorValue.from_rgb(0., 0.5, 0.) assert calc('hsl(120, 100%, 75%)') == ColorValue.from_rgb(0.5, 1., 0.5) assert calc('hsl(120, 75%, 75%)') == ColorValue.from_rgb( 0.5625, 0.9375, 0.5625)
def test_rgba(calc): # four args (css-style) assert calc('rgba(128, 192, 224, 0.5)') == ColorValue.from_rgb( 128 / 255, 192 / 255, 224 / 255, 0.5) assert calc('rgba(20%, 40%, 60%, 0.7)') == ColorValue.from_rgb( 0.2, 0.4, 0.6, 0.7) # two args (modify alpha of existing color) assert calc('rgba(red, 0.4)') == ColorValue.from_rgb(1., 0., 0., 0.4)
def test_hsla(calc): # Examples from the CSS 3 color spec assert calc('hsla(120, 100%, 50%, 1)') == ColorValue.from_rgb( 0., 1., 0., ) assert calc('hsla(240, 100%, 50%, 0.5)') == ColorValue.from_rgb( 0., 0., 1., 0.5) assert calc('hsla(30, 100%, 50%, 0.1)') == ColorValue.from_rgb( 1., 0.5, 0., 0.1)
def test_adjust_hue(calc): # Examples from the Ruby docs assert calc('adjust-hue(hsl(120, 30%, 90%), 60deg)') == calc( 'hsl(180, 30%, 90%)') assert calc('adjust-hue(hsl(120, 30%, 90%), -60deg)') == calc( 'hsl(60, 30%, 90%)') assert calc('adjust-hue(#811, 45deg)') == ColorValue.from_rgb( 136 / 255, 106.25 / 255, 17 / 255)
def test_hsla(calc): # Examples from the CSS 3 color spec assert calc('hsla(120, 100%, 50%, 1)') == ColorValue.from_rgb(0., 1., 0.,) assert calc('hsla(240, 100%, 50%, 0.5)') == ColorValue.from_rgb(0., 0., 1., 0.5) assert calc('hsla(30, 100%, 50%, 0.1)') == ColorValue.from_rgb(1., 0.5, 0., 0.1)
def test_grayscale(calc): assert calc('grayscale(black)') == ColorValue.from_rgb(0., 0., 0.) assert calc('grayscale(white)') == ColorValue.from_rgb(1., 1., 1.) assert calc('grayscale(yellow)') == ColorValue.from_rgb(0.5, 0.5, 0.5)
def test_desaturate(calc): # Examples from the Ruby docs assert calc('desaturate(hsl(120, 30%, 90%), 20%)') == calc( 'hsl(120, 10%, 90%)') assert calc('desaturate(#855, 20%)') == ColorValue.from_rgb( 113.9 / 255, 107.1 / 255, 107.1 / 255)
def test_invert(calc): assert calc('invert(black)') == ColorValue.from_rgb(1., 1., 1.) assert calc('invert(white)') == ColorValue.from_rgb(0., 0., 0.) assert calc('invert(yellow)') == ColorValue.from_rgb(0., 0., 1.)
def test_rgb(calc): assert calc('rgb(128, 192, 224)') == ColorValue.from_rgb(128/255, 192/255, 224/255) assert calc('rgb(20%, 40%, 60%)') == ColorValue.from_rgb(0.2, 0.4, 0.6)
def test_complement(calc): assert calc('complement(black)') == ColorValue.from_rgb(0., 0., 0.) assert calc('complement(white)') == ColorValue.from_rgb(1., 1., 1.) assert calc('complement(yellow)') == ColorValue.from_rgb(0., 0., 1.)
def test_saturate(calc): # Examples from the Ruby docs assert calc('saturate(hsl(120, 30%, 90%), 20%)') == calc( 'hsl(120, 50%, 90%)') assert calc('saturate(#855, 20%)') == ColorValue.from_rgb( 158.1 / 255, 62.9 / 255, 62.9 / 255)
def test_adjust_hue(calc): # Examples from the Ruby docs assert calc('adjust-hue(hsl(120, 30%, 90%), 60deg)') == calc('hsl(180, 30%, 90%)') assert calc('adjust-hue(hsl(120, 30%, 90%), -60deg)') == calc('hsl(60, 30%, 90%)') assert calc('adjust-hue(#811, 45deg)') == ColorValue.from_rgb(136/255, 106.25/255, 17/255)
def test_rgb(calc): assert calc('rgb(128, 192, 224)') == ColorValue.from_rgb( 128 / 255, 192 / 255, 224 / 255) assert calc('rgb(20%, 40%, 60%)') == ColorValue.from_rgb(0.2, 0.4, 0.6)
def test_saturate(calc): # Examples from the Ruby docs assert calc('saturate(hsl(120, 30%, 90%), 20%)') == calc('hsl(120, 50%, 90%)') assert calc('saturate(#855, 20%)') == ColorValue.from_rgb(158.1/255, 62.9/255, 62.9/255)
def test_desaturate(calc): # Examples from the Ruby docs assert calc('desaturate(hsl(120, 30%, 90%), 20%)') == calc('hsl(120, 10%, 90%)') assert calc('desaturate(#855, 20%)') == ColorValue.from_rgb(113.9/255, 107.1/255, 107.1/255)