Skip to content

Commit 8bde494

Browse files
author
Onimock
committed
Fix: ignore single-line
1 parent 94ca200 commit 8bde494

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

src/qss_parser/qss_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,8 @@ def process_line(
13181318
state.in_comment = False
13191319
return True
13201320
if line.startswith("/*"):
1321+
if "*/" in line:
1322+
return True
13211323
state.in_comment = True
13221324
return True
13231325
if line == "@variables {" and not state.in_rule:

tests/test_qss_parser.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,152 @@ def test_parsing_multiple_selectors_separate_with_comma_in_each_line_with_pseudo
17161716
self.assertEqual(self.parser.to_string().strip(), expected.strip())
17171717
self.assertEqual(self.errors, [], "Single-line rule should produce no errors")
17181718

1719+
def test_to_string_comments_in_single_line(self) -> None:
1720+
"""
1721+
Test parsing QSS with only comments in single line.
1722+
"""
1723+
qss: str = """
1724+
/* This is a comment */
1725+
/* Another comment */
1726+
#secondButton QPushButton {
1727+
color: red;
1728+
width: 15px;
1729+
height: 15px;
1730+
border-radius: 10px;
1731+
}
1732+
/* Another comment */
1733+
#customButton {
1734+
qproperty-enabled: false;
1735+
background: gray;
1736+
}
1737+
"""
1738+
expected = """#secondButton QPushButton {
1739+
color: red;
1740+
width: 15px;
1741+
height: 15px;
1742+
border-radius: 10px;
1743+
}
1744+
1745+
#customButton {
1746+
qproperty-enabled: false;
1747+
background: gray;
1748+
}
1749+
"""
1750+
self.parser.parse(qss)
1751+
print(self.parser.to_string())
1752+
self.assertEqual(
1753+
len(self.parser._state.rules),
1754+
2,
1755+
"Comments-only QSS should result in no rules",
1756+
)
1757+
self.assertEqual(
1758+
self.parser.to_string().split(),
1759+
expected.split(),
1760+
"Expected string passed",
1761+
)
1762+
self.assertEqual(self.errors, [], "Comments-only QSS should produce no errors")
1763+
1764+
def test_to_string_comments_bigger_than_a_line(self) -> None:
1765+
"""
1766+
Test parsing QSS with only comments in bigger than a line.
1767+
"""
1768+
qss: str = """
1769+
/* This is a comment
1770+
new line
1771+
more line here
1772+
*/
1773+
/* Another comment
1774+
seccond comment
1775+
*/
1776+
#secondButton QPushButton {
1777+
color: red;
1778+
width: 15px;
1779+
height: 15px;
1780+
border-radius: 10px;
1781+
}
1782+
/* Another comment
1783+
more comment*/
1784+
#customButton {
1785+
qproperty-enabled: false;
1786+
background: gray;
1787+
}
1788+
"""
1789+
expected = """#secondButton QPushButton {
1790+
color: red;
1791+
width: 15px;
1792+
height: 15px;
1793+
border-radius: 10px;
1794+
}
1795+
1796+
#customButton {
1797+
qproperty-enabled: false;
1798+
background: gray;
1799+
}
1800+
"""
1801+
self.parser.parse(qss)
1802+
print(self.parser.to_string())
1803+
self.assertEqual(
1804+
len(self.parser._state.rules),
1805+
2,
1806+
"Comments-only QSS should result in no rules",
1807+
)
1808+
self.assertEqual(
1809+
self.parser.to_string().split(),
1810+
expected.split(),
1811+
"Expected string passed",
1812+
)
1813+
self.assertEqual(self.errors, [], "Comments-only QSS should produce no errors")
1814+
1815+
def test_to_string_comments_bigger_than_a_line_and_single_line(self) -> None:
1816+
"""
1817+
Test parsing QSS with only comments in bigger than a line and in a single line.
1818+
"""
1819+
qss: str = """
1820+
/* This is a comment
1821+
new line
1822+
more line here
1823+
*/
1824+
/* Another comment */
1825+
#secondButton QPushButton {
1826+
color: red;
1827+
width: 15px;
1828+
height: 15px;
1829+
border-radius: 10px;
1830+
}
1831+
/*More single-line comment*/
1832+
/* Another comment
1833+
more comment*/
1834+
#customButton {
1835+
qproperty-enabled: false;
1836+
background: gray;
1837+
}
1838+
"""
1839+
expected = """#secondButton QPushButton {
1840+
color: red;
1841+
width: 15px;
1842+
height: 15px;
1843+
border-radius: 10px;
1844+
}
1845+
1846+
#customButton {
1847+
qproperty-enabled: false;
1848+
background: gray;
1849+
}
1850+
"""
1851+
self.parser.parse(qss)
1852+
print(self.parser.to_string())
1853+
self.assertEqual(
1854+
len(self.parser._state.rules),
1855+
2,
1856+
"Comments-only QSS should result in no rules",
1857+
)
1858+
self.assertEqual(
1859+
self.parser.to_string().split(),
1860+
expected.split(),
1861+
"Expected string passed",
1862+
)
1863+
self.assertEqual(self.errors, [], "Comments-only QSS should produce no errors")
1864+
17191865

17201866
class TestQSSParserQProperty(unittest.TestCase):
17211867
def setUp(self) -> None:

0 commit comments

Comments
 (0)