예제 #1
0
class PHPFormatCheckTest(CheckTestCase):
    check = PHPFormatCheck()

    def setUp(self):
        super(PHPFormatCheckTest, self).setUp()
        self.test_highlight = (
            'php-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('%1$s string', '%1$s 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('%1$s string', 'string',
                                                False))

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

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

    def test_double_format(self):
        self.assertTrue(
            self.check.check_format('%s string', '%s%s 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_wrong_named_format(self):
        self.assertTrue(
            self.check.check_format('%1$s string', '%s string', False))

    def test_wrong_percent_format(self):
        self.assertTrue(
            self.check.check_format('%s%% (0.1%%)', '%s%% (0.1%x)', False))

    def test_missing_percent_format(self):
        self.assertFalse(
            self.check.check_format('%s%% %%', '%s%% percent', False))
예제 #2
0
class PHPFormatCheckTest(CheckTestCase):
    check = PHPFormatCheck()

    def setUp(self):
        super().setUp()
        self.test_highlight = (
            "php-format",
            "%sstring%d",
            [(0, 2, "%s"), (8, 10, "%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("%1$s string", "%1$s 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("%1$s string", "string", False))

    def test_missing_named_format_ignore(self):
        self.assertFalse(self.check.check_format("%1$s string", "string", True))

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

    def test_double_format(self):
        self.assertTrue(self.check.check_format("%s string", "%s%s 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_wrong_named_format(self):
        self.assertTrue(self.check.check_format("%1$s string", "%s string", False))

    def test_wrong_percent_format(self):
        self.assertTrue(self.check.check_format("%s%% (0.1%%)", "%s%% (0.1%x)", False))

    def test_missing_percent_format(self):
        self.assertFalse(self.check.check_format("%s%% %%", "%s%% percent", False))

    def test_space_format(self):
        self.assertTrue(self.check.check_format("%d % string", "%d % other", False))