Example #1
0
class CFormatCheckTest(CheckTestCase):
    check = CFormatCheck()
    flag = 'c-format'

    def setUp(self):
        super(CFormatCheckTest, self).setUp()
        self.test_highlight = (
            self.flag,
            '%sstring%d',
            [(0, 2, u'%s'), (8, 10, u'%d')],
        )

    def test_no_format(self):
        self.assertFalse(self.check.check_format('strins', 'string', False))

    def test_format(self):
        self.assertFalse(
            self.check.check_format('%s string', '%s string', False))

    def test_named_format(self):
        self.assertFalse(
            self.check.check_format('%10s string', '%10s string', False))

    def test_missing_format(self):
        self.assertTrue(self.check.check_format('%s string', 'string', False))

    def test_missing_named_format(self):
        self.assertTrue(self.check.check_format('%10s string', 'string',
                                                False))

    def test_missing_named_format_ignore(self):
        self.assertFalse(self.check.check_format('%10s string', 'string',
                                                 True))

    def test_wrong_format(self):
        self.assertTrue(
            self.check.check_format('%s string', '%c string', False))

    def test_wrong_named_format(self):
        self.assertTrue(
            self.check.check_format('%10s string', '%20s string', False))

    def test_reorder_format(self):
        self.assertFalse(
            self.check.check_format('%1$s %2$s string', '%2$s %1$s string',
                                    False))

    def test_locale_delimiter(self):
        self.assertFalse(
            self.check.check_format('lines: %6.3f', 'radky: %\'6.3f', False))

    def test_ld_format(self):
        self.assertFalse(
            self.check.check_format(
                '%ld bytes (free %ld bytes, used %ld bytes)',
                '%l octets (%l octets libres, %l octets utilisés)', True))

    def test_parenthesis(self):
        self.assertFalse(
            self.check.check_format('(%.0lf%%)', '(%%%.0lf)', False))
Example #2
0
class CFormatCheckTest(CheckTestCase):
    check = CFormatCheck()

    def setUp(self):
        super(CFormatCheckTest, self).setUp()
        self.test_highlight = (
            'c-format',
            '%sstring%d',
            [(0, 2, u'%s'), (8, 10, u'%d')],
        )

    def test_no_format(self):
        self.assertFalse(self.check.check_format('strins', 'string', False))

    def test_format(self):
        self.assertFalse(
            self.check.check_format('%s string', '%s string', False))

    def test_named_format(self):
        self.assertFalse(
            self.check.check_format('%10s string', '%10s string', False))

    def test_missing_format(self):
        self.assertTrue(self.check.check_format('%s string', 'string', False))

    def test_missing_named_format(self):
        self.assertTrue(self.check.check_format('%10s string', 'string',
                                                False))

    def test_missing_named_format_ignore(self):
        self.assertFalse(self.check.check_format('%10s string', 'string',
                                                 True))

    def test_wrong_format(self):
        self.assertTrue(
            self.check.check_format('%s string', '%c string', False))

    def test_wrong_named_format(self):
        self.assertTrue(
            self.check.check_format('%10s string', '%20s string', False))

    def test_reorder_format(self):
        self.assertFalse(
            self.check.check_format('%1$s %2$s string', '%2$s %1$s string',
                                    False))

    def test_locale_delimiter(self):
        self.assertFalse(
            self.check.check_format('lines: %6.3f', 'radky: %\'6.3f', False))
Example #3
0
 def setUp(self):
     self.check = CFormatCheck()