From f785a5176993fb39f47d060afd36128a6f7d7689 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Feb 2023 10:08:02 +0000 Subject: [PATCH] Add combined type CSS parsing tests --- tests/css/test_parse.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/css/test_parse.py b/tests/css/test_parse.py index 727d45af4..00cd8d52d 100644 --- a/tests/css/test_parse.py +++ b/tests/css/test_parse.py @@ -8,7 +8,7 @@ from textual.css.parse import substitute_references from textual.css.scalar import Scalar, Unit from textual.css.stylesheet import Stylesheet, StylesheetParseError from textual.css.tokenize import tokenize -from textual.css.tokenizer import ReferencedBy, Token +from textual.css.tokenizer import ReferencedBy, Token, TokenError from textual.css.transition import Transition from textual.geometry import Spacing from textual.layouts.vertical import VerticalLayout @@ -1189,3 +1189,40 @@ class TestParseTextAlign: stylesheet = Stylesheet() stylesheet.add_source(css) assert stylesheet.rules[0].styles.text_align == "start" + + +class TestTypeNames: + def test_type_no_number(self): + stylesheet = Stylesheet() + stylesheet.add_source("TestType {}") + assert len(stylesheet.rules) == 1 + + def test_type_with_number(self): + stylesheet = Stylesheet() + stylesheet.add_source("TestType1 {}") + assert len(stylesheet.rules) == 1 + + def test_type_starts_with_number(self): + stylesheet = Stylesheet() + stylesheet.add_source("1TestType {}") + with pytest.raises(TokenError): + stylesheet.parse() + + def test_combined_type_no_number(self): + for seperator in " >,": + stylesheet = Stylesheet() + stylesheet.add_source(f"StartType {seperator} TestType {{}}") + assert len(stylesheet.rules) == 1 + + def test_combined_type_with_number(self): + for seperator in " >,": + stylesheet = Stylesheet() + stylesheet.add_source(f"StartType {seperator} TestType1 {{}}") + assert len(stylesheet.rules) == 1 + + def test_combined_type_starts_with_number(self): + for seperator in " >,": + stylesheet = Stylesheet() + stylesheet.add_source(f"StartType {seperator} 1TestType {{}}") + with pytest.raises(TokenError): + stylesheet.parse()