]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/yapftests/line_joiner_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.line_joiner."""
19 from yapf
.yapflib
import line_joiner
20 from yapf
.yapflib
import style
22 from yapftests
import yapf_test_helper
25 class LineJoinerTest(yapf_test_helper
.YAPFTest
):
29 style
.SetGlobalStyle(style
.CreatePEP8Style())
31 def _CheckLineJoining(self
, code
, join_lines
):
32 """Check that the given LogicalLines are joined as expected.
35 code: The code to check to see if we can join it.
36 join_lines: True if we expect the lines to be joined.
38 llines
= yapf_test_helper
.ParseAndUnwrap(code
)
39 self
.assertCodeEqual(line_joiner
.CanMergeMultipleLines(llines
), join_lines
)
41 def testSimpleSingleLineStatement(self
):
42 code
= textwrap
.dedent("""\
43 if isinstance(a, int): continue
45 self
._CheckLineJoining
(code
, join_lines
=True)
47 def testSimpleMultipleLineStatement(self
):
48 code
= textwrap
.dedent("""\
49 if isinstance(b, int):
52 self
._CheckLineJoining
(code
, join_lines
=False)
54 def testSimpleMultipleLineComplexStatement(self
):
55 code
= textwrap
.dedent("""\
56 if isinstance(c, int):
60 self
._CheckLineJoining
(code
, join_lines
=False)
62 def testSimpleMultipleLineStatementWithComment(self
):
63 code
= textwrap
.dedent("""\
64 if isinstance(d, int): continue # We're pleased that d's an int.
66 self
._CheckLineJoining
(code
, join_lines
=True)
68 def testSimpleMultipleLineStatementWithLargeIndent(self
):
69 code
= textwrap
.dedent("""\
70 if isinstance(e, int): continue
72 self
._CheckLineJoining
(code
, join_lines
=True)
74 def testOverColumnLimit(self
):
75 code
= textwrap
.dedent("""\
76 if instance(bbbbbbbbbbbbbbbbbbbbbbbbb, int): cccccccccccccccccccccccccc = ddddddddddddddddddddd
78 self
._CheckLineJoining
(code
, join_lines
=False)
81 if __name__
== '__main__':