-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lexers: devicetree: allow node label without root node (#1755)
* lexers: devicetree: allow node label without root node It is sometimes useful to render DeviceTree snippets such as: foo: bar@1234 { foo = "bar"; }; However the snipper shown above does not render properly unless it is enclosed on a root node, i.e. /{ foo: bar@1234 { foo = "bar"; }; }; Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no> * tests: add devicetree lexer test for fragments out of root node Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Devicetree Lexer Tests | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
|
||
import pytest | ||
|
||
from pygments.lexers.devicetree import DevicetreeLexer | ||
from pygments.token import Token | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def lexer(): | ||
yield DevicetreeLexer() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"fragment", | ||
( | ||
'nodelabel: node@0 { foo = "bar"; };', | ||
'nodelabel: node { foo = "bar"; };', | ||
'nodelabel0: nodelabel1: node@0 { foo = "bar"; };', | ||
), | ||
) | ||
def test_fragment_out_of_root_node(lexer, fragment): | ||
"""Validate that a devicetree fragment out of a root node is parsed correctly.""" | ||
|
||
tokens = list(lexer.get_tokens(fragment)) | ||
assert all(x[0] != Token.Error for x in tokens) |