+class TestOrdinal(unittest.TestCase):
+ def test(self):
+ checks = {
+ 0: "0th", 1: "1st", 2: "2nd", 3: "3rd", 4: "4th", 5: "5th", 6: "6th",
+ 7: "7th", 8: "8th", 9: "9th", 10: "10th", 11: "11th", 12: "12th",
+ 13: "13th", 14: "14th", 15: "15th", 16: "16th", 17: "17th",
+ 18: "18th", 19: "19th", 20: "20th", 21: "21st", 25: "25th", 30: "30th",
+ 32: "32nd", 40: "40th", 50: "50th", 55: "55th", 60: "60th", 62: "62nd",
+ 70: "70th", 80: "80th", 83: "83rd", 90: "90th", 91: "91st",
+ 582: "582nd", 999: "999th",
+ }
+
+ for value, ordinal in checks.items():
+ 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)
+
+
+class TestFilterEmptyLinesAndComments(unittest.TestCase):
+ def testEmpty(self):
+ self.assertEqual(utils.FilterEmptyLinesAndComments(""), [])
+ self.assertEqual(utils.FilterEmptyLinesAndComments("\n"), [])
+ self.assertEqual(utils.FilterEmptyLinesAndComments("\n" * 100), [])
+ self.assertEqual(utils.FilterEmptyLinesAndComments("\n \n\t \n"), [])
+
+ def test(self):
+ text = """
+ This
+ is
+ # with comments
+ a
+ test
+ # in
+ #
+ saying
+ ...#...
+ # multiple places
+ Hello World!
+ """
+ self.assertEqual(utils.FilterEmptyLinesAndComments(text), [
+ "This",
+ "is",
+ "a",
+ "test",
+ "saying",
+ "...#...",
+ "Hello World!",
+ ])
+
+