Coverage for cogapp/test_whiteutils.py: 0.00%

# Coverage for cogapp/test_whiteutils.py : 0.00%

## 69 statements 0 run 69 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | """ Test the cogapp.whiteutils module. http://nedbatchelder.com/code/cog Copyright 2004-2015, Ned Batchelder. """ from __future__ import absolute_import import unittest from .whiteutils import * class WhitePrefixTests(unittest.TestCase): """ Test cases for cogapp.whiteutils. """ def testSingleLine(self): self.assertEqual(whitePrefix(['']), '') self.assertEqual(whitePrefix([' ']), '') self.assertEqual(whitePrefix(['x']), '') self.assertEqual(whitePrefix([' x']), ' ') self.assertEqual(whitePrefix(['\tx']), '\t') self.assertEqual(whitePrefix([' x']), ' ') self.assertEqual(whitePrefix([' \t \tx ']), ' \t \t') def testMultiLine(self): self.assertEqual(whitePrefix([' x',' x',' x']), ' ') self.assertEqual(whitePrefix([' y',' y',' y']), ' ') self.assertEqual(whitePrefix([' y',' y',' y']), ' ') def testBlankLinesAreIgnored(self): self.assertEqual(whitePrefix([' x',' x','',' x']), ' ') self.assertEqual(whitePrefix(['',' x',' x',' x']), ' ') self.assertEqual(whitePrefix([' x',' x',' x','']), ' ') self.assertEqual(whitePrefix([' x',' x',' ',' x']), ' ') def testTabCharacters(self): self.assertEqual(whitePrefix(['\timport sys', '', '\tprint sys.argv']), '\t') def testDecreasingLengths(self): self.assertEqual(whitePrefix([' x',' x',' x']), ' ') self.assertEqual(whitePrefix([' x',' x',' x']), ' ') class ReindentBlockTests(unittest.TestCase): """ Test cases for cogapp.reindentBlock. """ def testNonTermLine(self): self.assertEqual(reindentBlock(''), '') self.assertEqual(reindentBlock('x'), 'x') self.assertEqual(reindentBlock(' x'), 'x') self.assertEqual(reindentBlock(' x'), 'x') self.assertEqual(reindentBlock('\tx'), 'x') self.assertEqual(reindentBlock('x', ' '), ' x') self.assertEqual(reindentBlock('x', '\t'), '\tx') self.assertEqual(reindentBlock(' x', ' '), ' x') self.assertEqual(reindentBlock(' x', '\t'), '\tx') self.assertEqual(reindentBlock(' x', ' '), ' x') def testSingleLine(self): self.assertEqual(reindentBlock('\n'), '\n') self.assertEqual(reindentBlock('x\n'), 'x\n') self.assertEqual(reindentBlock(' x\n'), 'x\n') self.assertEqual(reindentBlock(' x\n'), 'x\n') self.assertEqual(reindentBlock('\tx\n'), 'x\n') self.assertEqual(reindentBlock('x\n', ' '), ' x\n') self.assertEqual(reindentBlock('x\n', '\t'), '\tx\n') self.assertEqual(reindentBlock(' x\n', ' '), ' x\n') self.assertEqual(reindentBlock(' x\n', '\t'), '\tx\n') self.assertEqual(reindentBlock(' x\n', ' '), ' x\n') def testRealBlock(self): self.assertEqual( reindentBlock('\timport sys\n\n\tprint sys.argv\n'), 'import sys\n\nprint sys.argv\n' ) class CommonPrefixTests(unittest.TestCase): """ Test cases for cogapp.commonPrefix. """ def testDegenerateCases(self): self.assertEqual(commonPrefix([]), '') self.assertEqual(commonPrefix(['']), '') self.assertEqual(commonPrefix(['','','','','']), '') self.assertEqual(commonPrefix(['cat in the hat']), 'cat in the hat') def testNoCommonPrefix(self): self.assertEqual(commonPrefix(['a','b']), '') self.assertEqual(commonPrefix(['a','b','c','d','e','f']), '') self.assertEqual(commonPrefix(['a','a','a','a','a','x']), '') def testUsualCases(self): self.assertEqual(commonPrefix(['ab', 'ac']), 'a') self.assertEqual(commonPrefix(['aab', 'aac']), 'aa') self.assertEqual(commonPrefix(['aab', 'aab', 'aab', 'aac']), 'aa') def testBlankLine(self): self.assertEqual(commonPrefix(['abc', 'abx', '', 'aby']), '') def testDecreasingLengths(self): self.assertEqual(commonPrefix(['abcd', 'abc', 'ab']), 'ab')