Commit 5a84fce4 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'noc-fix-indent-overdedent' into 'master'

ConfDB: Allow over-dedent in indent tokenizer

See merge request !2482
parents 1d8bbed9 768d26ca
Pipeline #15288 passed with stages
in 61 minutes and 54 seconds
......@@ -52,14 +52,15 @@ class IndentTokenizer(LineTokenizer):
c_depth = len(tokens[0]) if tokens[0].startswith(" ") else 0
if c_depth:
tokens = tokens[1:]
if c_depth > depts[-1] and last:
if depts and c_depth > depts[-1] and last:
# Push context
depts += [c_depth]
contexts += [last]
elif tokens == eoc:
# Pop context
depts.pop(-1)
contexts.pop(-1)
if len(depts) > 1:
# Pop context
depts.pop(-1)
contexts.pop(-1)
continue
# Apply current context
tokens = contexts[-1] + tokens
......
......@@ -123,6 +123,29 @@ TOKENS3 = [
("ntp-service", "server", "disable"),
]
CFG4 = """! Test config
#
http server
#
interface Fa 0/1
description 1
#
interface Fa 0/2
description 2
#
#
router ospf
"""
TOKENS4 = [
("http", "server"),
("interface", "Fa", "0/1"),
("interface", "Fa", "0/1", "description", "1"),
("interface", "Fa", "0/2"),
("interface", "Fa", "0/2", "description", "2"),
("router", "ospf"),
]
@pytest.mark.parametrize(
"input,config,expected",
......@@ -130,6 +153,7 @@ TOKENS3 = [
(CFG1, {"line_comment": "#"}, TOKENS1),
(CFG2, {"line_comment": "#", "end_of_context": "end"}, TOKENS2),
(CFG3, {"line_comment": "#"}, TOKENS3),
(CFG4, {"line_comment": "!", "end_of_context": "#"}, TOKENS4),
],
)
def test_tokenizer(input, config, expected):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment