]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/yapftests/logical_line_test.py
1 # Copyright 2015 Google Inc. All Rights Reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Tests for yapf.logical_line."""
19 from yapf_third_party
._ylib
2to
3 import pytree
20 from yapf_third_party
._ylib
2to
3.pgen2
import token
22 from yapf
.pytree
import split_penalty
23 from yapf
.yapflib
import format_token
24 from yapf
.yapflib
import logical_line
26 from yapftests
import yapf_test_helper
29 class LogicalLineBasicTest(yapf_test_helper
.YAPFTest
):
31 def testConstruction(self
):
32 toks
= _MakeFormatTokenList([(token
.DOT
, '.', 'DOT'),
33 (token
.VBAR
, '|', 'VBAR')])
34 lline
= logical_line
.LogicalLine(20, toks
)
35 self
.assertEqual(20, lline
.depth
)
36 self
.assertEqual(['DOT', 'VBAR'], [tok
.name
for tok
in lline
.tokens
])
38 def testFirstLast(self
):
39 toks
= _MakeFormatTokenList([(token
.DOT
, '.', 'DOT'),
40 (token
.LPAR
, '(', 'LPAR'),
41 (token
.VBAR
, '|', 'VBAR')])
42 lline
= logical_line
.LogicalLine(20, toks
)
43 self
.assertEqual(20, lline
.depth
)
44 self
.assertEqual('DOT', lline
.first
.name
)
45 self
.assertEqual('VBAR', lline
.last
.name
)
48 toks
= _MakeFormatTokenList([(token
.DOT
, '.', 'DOT'),
49 (token
.LPAR
, '(', 'LPAR'),
50 (token
.VBAR
, '|', 'VBAR')])
51 lline
= logical_line
.LogicalLine(2, toks
)
52 self
.assertEqual(' . ( |', lline
.AsCode())
54 def testAppendToken(self
):
55 lline
= logical_line
.LogicalLine(0)
56 lline
.AppendToken(_MakeFormatTokenLeaf(token
.LPAR
, '(', 'LPAR'))
57 lline
.AppendToken(_MakeFormatTokenLeaf(token
.RPAR
, ')', 'RPAR'))
58 self
.assertEqual(['LPAR', 'RPAR'], [tok
.name
for tok
in lline
.tokens
])
61 class LogicalLineFormattingInformationTest(yapf_test_helper
.YAPFTest
):
63 def testFuncDef(self
):
64 code
= textwrap
.dedent("""\
68 llines
= yapf_test_helper
.ParseAndUnwrap(code
)
70 f
= llines
[0].tokens
[1]
71 self
.assertFalse(f
.can_break_before
)
72 self
.assertFalse(f
.must_break_before
)
73 self
.assertEqual(f
.split_penalty
, split_penalty
.UNBREAKABLE
)
75 lparen
= llines
[0].tokens
[2]
76 self
.assertFalse(lparen
.can_break_before
)
77 self
.assertFalse(lparen
.must_break_before
)
78 self
.assertEqual(lparen
.split_penalty
, split_penalty
.UNBREAKABLE
)
81 def _MakeFormatTokenLeaf(token_type
, token_value
, name
):
82 return format_token
.FormatToken(pytree
.Leaf(token_type
, token_value
), name
)
85 def _MakeFormatTokenList(token_type_values
):
87 _MakeFormatTokenLeaf(token_type
, token_value
, token_name
)
88 for token_type
, token_value
, token_name
in token_type_values
92 if __name__
== '__main__':