-
-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #843 from Kozea/variables
Add CSS variables
- Loading branch information
Showing
8 changed files
with
209 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
weasyprint.tests.test_variables | ||
------------------------------- | ||
Test CSS custom proproperties, also known as CSS variables. | ||
:copyright: Copyright 2011-2019 Simon Sapin and contributors, see AUTHORS. | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
|
||
from .test_boxes import render_pages as parse | ||
|
||
|
||
def test_variable_simple(): | ||
page, = parse(''' | ||
<style> | ||
p { --var: 10px; width: var(--var) } | ||
</style> | ||
<p></p> | ||
''') | ||
html, = page.children | ||
body, = html.children | ||
paragraph, = body.children | ||
assert paragraph.width == 10 | ||
|
||
|
||
def test_variable_inherit(): | ||
page, = parse(''' | ||
<style> | ||
html { --var: 10px } | ||
p { width: var(--var) } | ||
</style> | ||
<p></p> | ||
''') | ||
html, = page.children | ||
body, = html.children | ||
paragraph, = body.children | ||
assert paragraph.width == 10 | ||
|
||
|
||
def test_variable_inherit_override(): | ||
page, = parse(''' | ||
<style> | ||
html { --var: 20px } | ||
p { width: var(--var); --var: 10px } | ||
</style> | ||
<p></p> | ||
''') | ||
html, = page.children | ||
body, = html.children | ||
paragraph, = body.children | ||
assert paragraph.width == 10 | ||
|
||
|
||
def test_variable_case_sensitive(): | ||
page, = parse(''' | ||
<style> | ||
html { --var: 20px } | ||
body { --VAR: 10px } | ||
p { width: var(--VAR) } | ||
</style> | ||
<p></p> | ||
''') | ||
html, = page.children | ||
body, = html.children | ||
paragraph, = body.children | ||
assert paragraph.width == 10 | ||
|
||
|
||
def test_variable_chain(): | ||
page, = parse(''' | ||
<style> | ||
html { --foo: 10px } | ||
body { --var: var(--foo) } | ||
p { width: var(--var) } | ||
</style> | ||
<p></p> | ||
''') | ||
html, = page.children | ||
body, = html.children | ||
paragraph, = body.children | ||
assert paragraph.width == 10 | ||
|
||
|
||
def test_variable_initial(): | ||
page, = parse(''' | ||
<style> | ||
html { --var: initial } | ||
p { width: var(--var, 10px) } | ||
</style> | ||
<p></p> | ||
''') | ||
html, = page.children | ||
body, = html.children | ||
paragraph, = body.children | ||
assert paragraph.width == 10 |