Skip to content

Commit

Permalink
Add and test new values of CSS alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Apr 5, 2024
1 parent 05f6f40 commit 5c3ea17
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 66 deletions.
271 changes: 271 additions & 0 deletions tests/css/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,274 @@ def test_grid_line_invalid(rule):
assert_invalid(f'grid-row-end: {rule}')
assert_invalid(f'grid-column-start: {rule}')
assert_invalid(f'grid-column-end: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('normal', ('normal',)),
('baseline', ('first', 'baseline')),
('first baseline', ('first', 'baseline')),
('last baseline', ('last', 'baseline')),
('baseline last', ('baseline', 'last')),
('space-between', ('space-between',)),
('space-around', ('space-around',)),
('space-evenly', ('space-evenly',)),
('stretch', ('stretch',)),
('center', ('center',)),
('start', ('start',)),
('end', ('end',)),
('flex-start', ('flex-start',)),
('flex-end', ('flex-end',)),
('safe center', ('safe', 'center')),
('unsafe start', ('unsafe', 'start')),
('safe end', ('safe', 'end')),
('safe flex-start', ('safe', 'flex-start')),
('unsafe flex-start', ('unsafe', 'flex-start')),
))
def test_align_content(rule, value):
assert get_value(f'align-content: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'auto',
'none',
'auto auto',
'first last',
'baseline baseline',
'start safe',
'start end',
'safe unsafe',
'left',
'right',
))
def test_align_content_invalid(rule):
assert_invalid(f'align-content: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('normal', ('normal',)),
('stretch', ('stretch',)),
('baseline', ('first', 'baseline')),
('first baseline', ('first', 'baseline')),
('last baseline', ('last', 'baseline')),
('baseline last', ('baseline', 'last')),
('center', ('center',)),
('self-start', ('self-start',)),
('self-end', ('self-end',)),
('start', ('start',)),
('end', ('end',)),
('flex-start', ('flex-start',)),
('flex-end', ('flex-end',)),
('safe center', ('safe', 'center')),
('unsafe start', ('unsafe', 'start')),
('safe end', ('safe', 'end')),
('unsafe self-start', ('unsafe', 'self-start')),
('safe self-end', ('safe', 'self-end')),
('safe flex-start', ('safe', 'flex-start')),
('unsafe flex-start', ('unsafe', 'flex-start')),
))
def test_align_items(rule, value):
assert get_value(f'align-items: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'auto',
'none',
'auto auto',
'first last',
'baseline baseline',
'start safe',
'start end',
'safe unsafe',
'left',
'right',
'space-between',
))
def test_align_items_invalid(rule):
assert_invalid(f'align-items: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('auto', ('auto',)),
('normal', ('normal',)),
('stretch', ('stretch',)),
('baseline', ('first', 'baseline')),
('first baseline', ('first', 'baseline')),
('last baseline', ('last', 'baseline')),
('baseline last', ('baseline', 'last')),
('center', ('center',)),
('self-start', ('self-start',)),
('self-end', ('self-end',)),
('start', ('start',)),
('end', ('end',)),
('flex-start', ('flex-start',)),
('flex-end', ('flex-end',)),
('safe center', ('safe', 'center')),
('unsafe start', ('unsafe', 'start')),
('safe end', ('safe', 'end')),
('unsafe self-start', ('unsafe', 'self-start')),
('safe self-end', ('safe', 'self-end')),
('safe flex-start', ('safe', 'flex-start')),
('unsafe flex-start', ('unsafe', 'flex-start')),
))
def test_align_self(rule, value):
assert get_value(f'align-self: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'none',
'auto auto',
'first last',
'baseline baseline',
'start safe',
'start end',
'safe unsafe',
'left',
'right',
'space-between',
))
def test_align_self_invalid(rule):
assert_invalid(f'align-self: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('normal', ('normal',)),
('space-between', ('space-between',)),
('space-around', ('space-around',)),
('space-evenly', ('space-evenly',)),
('stretch', ('stretch',)),
('center', ('center',)),
('left', ('left',)),
('right', ('right',)),
('start', ('start',)),
('end', ('end',)),
('flex-start', ('flex-start',)),
('flex-end', ('flex-end',)),
('safe center', ('safe', 'center')),
('unsafe start', ('unsafe', 'start')),
('safe end', ('safe', 'end')),
('unsafe left', ('unsafe', 'left')),
('safe right', ('safe', 'right')),
('safe flex-start', ('safe', 'flex-start')),
('unsafe flex-start', ('unsafe', 'flex-start')),
))
def test_justify_content(rule, value):
assert get_value(f'justify-content: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'auto',
'none',
'baseline',
'auto auto',
'first last',
'baseline baseline',
'start safe',
'start end',
'safe unsafe',
))
def test_justify_content_invalid(rule):
assert_invalid(f'justify-content: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('normal', ('normal',)),
('stretch', ('stretch',)),
('baseline', ('first', 'baseline')),
('first baseline', ('first', 'baseline')),
('last baseline', ('last', 'baseline')),
('baseline last', ('baseline', 'last')),
('center', ('center',)),
('self-start', ('self-start',)),
('self-end', ('self-end',)),
('start', ('start',)),
('end', ('end',)),
('left', ('left',)),
('right', ('right',)),
('flex-start', ('flex-start',)),
('flex-end', ('flex-end',)),
('safe center', ('safe', 'center')),
('unsafe start', ('unsafe', 'start')),
('safe end', ('safe', 'end')),
('unsafe self-start', ('unsafe', 'self-start')),
('safe self-end', ('safe', 'self-end')),
('safe flex-start', ('safe', 'flex-start')),
('unsafe flex-start', ('unsafe', 'flex-start')),
('legacy', ('legacy',)),
('legacy left', ('legacy', 'left')),
('left legacy', ('left', 'legacy')),
('legacy center', ('legacy', 'center')),
))
def test_justify_items(rule, value):
assert get_value(f'justify-items: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'auto',
'none',
'auto auto',
'first last',
'baseline baseline',
'start safe',
'start end',
'safe unsafe',
'space-between',
))
def test_justify_items_invalid(rule):
assert_invalid(f'justify-items: {rule}')


@assert_no_logs
@pytest.mark.parametrize('rule, value', (
('auto', ('auto',)),
('normal', ('normal',)),
('stretch', ('stretch',)),
('baseline', ('first', 'baseline')),
('first baseline', ('first', 'baseline')),
('last baseline', ('last', 'baseline')),
('baseline last', ('baseline', 'last')),
('center', ('center',)),
('self-start', ('self-start',)),
('self-end', ('self-end',)),
('start', ('start',)),
('end', ('end',)),
('left', ('left',)),
('right', ('right',)),
('flex-start', ('flex-start',)),
('flex-end', ('flex-end',)),
('safe center', ('safe', 'center')),
('unsafe start', ('unsafe', 'start')),
('safe end', ('safe', 'end')),
('unsafe left', ('unsafe', 'left')),
('safe right', ('safe', 'right')),
('unsafe self-start', ('unsafe', 'self-start')),
('safe self-end', ('safe', 'self-end')),
('safe flex-start', ('safe', 'flex-start')),
('unsafe flex-start', ('unsafe', 'flex-start')),
))
def test_justify_self(rule, value):
assert get_value(f'justify-self: {rule}') == value


@assert_no_logs
@pytest.mark.parametrize('rule', (
'none',
'auto auto',
'first last',
'baseline baseline',
'start safe',
'start end',
'safe unsafe',
'space-between',
))
def test_justify_self_invalid(rule):
assert_invalid(f'justify-self: {rule}')
10 changes: 6 additions & 4 deletions weasyprint/css/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@
'grid_column_end': 'auto',

# CSS Box Alignment Module Level 3 (WD): https://www.w3.org/TR/css-align-3/
'align_content': 'normal',
'align_items': 'normal',
'align_self': 'auto',
'justify_content': 'normal',
'align_content': ('normal',),
'align_items': ('normal',),
'align_self': ('auto',),
'justify_content': ('normal',),
'justify_items': ('normal',),
'justify_self': ('normal',),
'order': 0,
'column_gap': 'normal',
'row_gap': 'normal',
Expand Down
24 changes: 24 additions & 0 deletions weasyprint/css/validation/expanders.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,30 @@ def expand_gap(tokens, name):
yield 'row-gap', tokens[1:2]


@expander('place-content')
@generic_expander('align-content', 'justify-content')
def expand_place_content(tokens, name):
"""Expand the ``place-content`` property."""
# TODO
raise InvalidValues


@expander('place-items')
@generic_expander('align-items', 'justify-items')
def expand_place_items(tokens, name):
"""Expand the ``place-items`` property."""
# TODO
raise InvalidValues


@expander('place-self')
@generic_expander('align-self', 'justify-self')
def expand_place_self(tokens, name):
"""Expand the ``place-self`` property."""
# TODO
raise InvalidValues


@expander('line-clamp')
@generic_expander('max-lines', 'continue', 'block-ellipsis')
def expand_line_clamp(tokens, name):
Expand Down
Loading

0 comments on commit 5c3ea17

Please sign in to comment.