コード例 #1
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_indent_explicit_default(self):
     # Test default indenting of lines that are not whitespace only
     prefix = '  '
     expected = (
       # Basic test case
       "  Hi.\n  This is a test.\n  Testing.",
       # Include a blank line
       "  Hi.\n  This is a test.\n\n  Testing.",
       # Include leading and trailing blank lines
       "\n  Hi.\n  This is a test.\n  Testing.\n",
       # Use Windows line endings
       "  Hi.\r\n  This is a test.\r\n  Testing.\r\n",
       # Pathological case
       "\n  Hi.\r\n  This is a test.\n\r\n  Testing.\r\n\n",
     )
     for text, expect in zip(self.CASES, expected):
         self.assertEqual(indent(text, prefix, None), expect)
コード例 #2
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_indent_empty_lines(self):
     # Add 'prefix' solely to whitespace-only lines.
     prefix = '  '
     expected = (
       # Basic test case
       "Hi.\nThis is a test.\nTesting.",
       # Include a blank line
       "Hi.\nThis is a test.\n  \nTesting.",
       # Include leading and trailing blank lines
       "  \nHi.\nThis is a test.\nTesting.\n",
       # Use Windows line endings
       "Hi.\r\nThis is a test.\r\nTesting.\r\n",
       # Pathological case
       "  \nHi.\r\nThis is a test.\n  \r\nTesting.\r\n  \n",
     )
     predicate = lambda line: not line.strip()
     for text, expect in zip(self.CASES, expected):
         self.assertEqual(indent(text, prefix, predicate), expect)
コード例 #3
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_roundtrip_mixed(self):
     # A whitespace prefix should roundtrip with dedent
     for text in self.ROUNDTRIP_CASES:
         self.assertEqual(dedent(indent(text, ' \t  \t ')), text)
コード例 #4
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_indent_no_lines(self):
     # Explicitly skip indenting any lines
     predicate = lambda line: False
     for text in self.CASES:
         self.assertEqual(indent(text, '    ', predicate), text)
コード例 #5
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_indent_nomargin_all_lines(self):
     # The same as test_indent_nomargin, but using the optional
     # predicate argument
     predicate = lambda line: True
     for text in self.CASES:
         self.assertEqual(indent(text, '', predicate), text)
コード例 #6
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_indent_nomargin_explicit_default(self):
     # The same as test_indent_nomargin, but explicitly requesting
     # the default behaviour by passing None as the predicate
     for text in self.CASES:
         self.assertEqual(indent(text, '', None), text)
コード例 #7
0
ファイル: test_textwrap.py プロジェクト: edelvalle/xoutil
 def test_indent_nomargin_default(self):
     # indent should do nothing if 'prefix' is empty.
     for text in self.CASES:
         self.assertEqual(indent(text, ''), text)