sw = None
self.assertEqual(buf.getvalue(), "")
+ def testEmptyLines(self):
+ buf = StringIO()
+ sw = utils.ShellWriter(buf)
+
+ def _AddLevel(level):
+ if level == 6:
+ return
+ sw.IncIndent()
+ try:
+ # Add empty line, it should not be indented
+ sw.Write("")
+ sw.Write(str(level))
+ _AddLevel(level + 1)
+ finally:
+ sw.DecIndent()
+
+ _AddLevel(1)
+
+ self.assertEqual(buf.getvalue(),
+ "".join("\n%s%s\n" % (i * " ", i) for i in range(1, 6)))
+
class TestNormalizeAndValidateMac(unittest.TestCase):
def testInvalid(self):
b = [sep, sep, "c", "d.moo\\"]
self.assertEqual(utils.UnescapeAndSplit("%s\\" % sep.join(a), sep=sep), b)
+ def testMultipleEscapes(self):
+ for sep in self._seps:
+ a = ["a", "b\\" + sep + "c", "d\\" + sep + "e\\" + sep + "f", "g"]
+ b = ["a", "b" + sep + "c", "d" + sep + "e" + sep + "f", "g"]
+ self.failUnlessEqual(utils.UnescapeAndSplit(sep.join(a), sep=sep), b)
+
class TestCommaJoin(unittest.TestCase):
def test(self):
self.assertEqual(utils.FormatOrdinal(value), ordinal)
+class TestTruncate(unittest.TestCase):
+ def _Test(self, text, length):
+ result = utils.Truncate(text, length)
+ self.assertTrue(len(result) <= length)
+ return result
+
+ def test(self):
+ self.assertEqual(self._Test("", 80), "")
+ self.assertEqual(self._Test("abc", 4), "abc")
+ self.assertEqual(self._Test("Hello World", 80), "Hello World")
+ self.assertEqual(self._Test("Hello World", 4), "H...")
+ self.assertEqual(self._Test("Hello World", 5), "He...")
+
+ for i in [4, 10, 100]:
+ data = i * "FooBarBaz"
+ self.assertEqual(self._Test(data, len(data)), data)
+
+ for (length, exp) in [(8, u"T\u00e4st\u2026xyz"), (7, u"T\u00e4st...")]:
+ self.assertEqual(self._Test(u"T\u00e4st\u2026xyz", length), exp)
+
+ self.assertEqual(self._Test(range(100), 20), "[0, 1, 2, 3, 4, 5...")
+
+ def testError(self):
+ for i in range(4):
+ self.assertRaises(AssertionError, utils.Truncate, "", i)
+
+
if __name__ == "__main__":
testutils.GanetiTestProgram()