aboutsummaryrefslogtreecommitdiff
path: root/tests/test_text.py
blob: 45a39fe53569954da03ca91f9bdb4a5ea0f9e4f1 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
#******************************************************************************
# Copyright (C) 2019 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the thcolor project, which is MIT-licensed.
#******************************************************************************
""" Unit tests for the thcolor color decoding and management module. """

import pytest
from thcolor import Color, Angle

def _deg(value):
	return Angle(Angle.Type.DEG, value)

@pytest.mark.parametrize('test_input,expected', (
	('blue',                      (  0,   0, 255, 1.00)),
	('#12345F',                   ( 18,  52,  95, 1.00)),
	('#123',                      ( 17,  34,  51, 1.00)),
	('123',                       (  1,   2,   3, 1.00)),
	('123.0',                     ( 18,  48,   0, 1.00)),
	('chucknorris',               (192,   0,   0, 1.00)),
	('rgb(1, 22,242)',            (  1,  22, 242, 1.00)),
	(' rgb (1,22, 242 , 50.0% )', (  1,  22, 242, 0.50)),
	(' rgb (1 22/ /242,50.0%,/)', (  1,  22, 242, 0.50)),
	('rgba(1,22,242,0.500)',      (  1,  22, 242, 0.50)),
	('rbga(5, 7)',                (  5,   0,   7, 1.00)),
	('hsl(0, 1,50.0%)',           (255,   0,   0, 1.00)),
	('hls(0 / 1 0.5   , 0.2)',    (255, 255, 255, 0.20)),
	('hwb(0 0% 0)',               (255,   0,   0, 1.00)),
	('hbw(127 .5)',               (  0, 128,  15, 1.00)),
	('gray(100)',                 (100, 100, 100, 1.00)),
	('gray(100 / 55 %)',          (100, 100, 100, 0.55)),
	('gray(red( #123456 )/0.2/)', ( 18,  18,  18, 0.20)),
	('B20 50% 32%',               (137, 128, 173, 1.00)),
	('ncol(B20 / 50% 32%)',       (137, 128, 173, 1.00)),
	('cmyk(0% 37% 0.13 .78)',     ( 56,  35,  49, 1.00)),
))
def test_rgba(test_input, expected):
	assert Color.from_text(test_input).rgba() == expected

@pytest.mark.parametrize('test_input,expected', (
	('darker(10%,  hsl(0, 1, 50.0%))',      (_deg( 0   ), 1.00, 0.40, 1.00)),
	('lighter(50%, hsl(0, 1, 60.0%))',      (_deg( 0   ), 1.00, 1.00, 1.00)),
	('saturate(10%,  hls(0, 1, 85.0%))',    (_deg( 0   ), 0.95, 1.00, 1.00)),
	('desaturate(10%, hls(0, 1, 5%, 0.2))', (_deg( 0   ), 0.00, 1.00, 0.20)),
	('rgba(255, 0, 0, 20 %)',               (_deg( 0   ), 1.00, 0.50, 0.20)),
	('Y40, 33%, 55%',                       (_deg(83.23), 0.16, 0.39, 1.00)),
))
def test_hsla(test_input, expected):
	assert Color.from_text(test_input).hsla() == expected

@pytest.mark.parametrize('test_input,expected', (
	('cmyk(0% 37% 0.13 .78)',     (0.00, 0.37, 0.13, 0.78, 1.00)),
))
def test_cmyka(test_input, expected):
	assert Color.from_text(test_input).cmyka() == expected

@pytest.mark.parametrize('test_input,expected', (
	('blue',
		('#0000FF',)),
	(' rgb (1,22, 242 , 50.0% )',
		('#0116F2', 'rgba(1, 22, 242, 50%)')),
	('darker(10%,  hsl(0, 1, 50.0%))',
		('#CC0000', 'hsl(0deg, 100%, 40%)')),
	('hls(0 / 1 0.5   , 0.2)',
		('#FFFFFF', 'rgba(255, 255, 255, 20%)', 'hsla(0deg, 50%, 100%, 20%)')),
	('hbw(127 .5)',
		('#00800F', 'hwb(127deg, 0%, 50%)')),
))
def test_css(test_input, expected):
	assert Color.from_text(test_input).css() == expected

# End of file.