Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
noc
noc
Commits
ee64ec47
Verified
Commit
ee64ec47
authored
Aug 16, 2019
by
Dmitry Volodin
Browse files
ConfDB: Allow over-dedent in indent tokenizer
parent
5fb7bd3b
Pipeline
#15269
failed with stages
in 47 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
core/confdb/tokenizer/indent.py
View file @
ee64ec47
...
...
@@ -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
...
...
tests/confdb/tokenizer/test_indent.py
View file @
ee64ec47
...
...
@@ -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
):
...
...
Andrey Vertiprahov
@aversant
mentioned in commit
029cf812
·
Aug 16, 2019
mentioned in commit
029cf812
mentioned in commit 029cf812da7a41f9c44fee59558d1c8b8d25dab3
Toggle commit list
Andrey Vertiprahov
@aversant
mentioned in merge request
!2487 (merged)
·
Aug 16, 2019
mentioned in merge request
!2487 (merged)
mentioned in merge request !2487
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment