"""
    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


def test_variable_regression_1():
    # Test regression: https://github.com/Kozea/WeasyPrint/issues/974
    page, = parse('''
      <style>
        div {
          --value: invalidValue;
          border-spacing: var(--value);
        }
      </style>
      <div>crash</div>
    ''')

@@ -264,16 +264,62 @@
 .%0A%0A%22%22%22%0A%0A
+from ..css.properties import KNOWN_PROPERTIES%0A
 from .te
@@ -2155,105 +2155,23 @@
 ble_
-regression_1():%0A    # Test regression: https://github.com/Kozea/WeasyPrint/issues/974%0A    page, =
+fallback():%0A   
  par
@@ -2223,20 +2223,19 @@
 --va
-lue: invalid
+r: improper
 Valu
@@ -2251,37 +2251,10 @@
     
-border-spacing: var(--value);
+%25s
 %0A   
@@ -2290,13 +2290,8 @@
 div%3E
-crash
 %3C/di
@@ -2292,18 +2292,83 @@
 v%3E%3C/div%3E%0A    '''
+ %25 ''.join(name + ': var(--var);%5Cn' for name in KNOWN_PROPERTIES)
 )%0A

Add test