Commit 5ddbafd1 authored by Michal Čihař's avatar Michal Čihař

Add test for format string highlights

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent a10b1e19
...@@ -206,8 +206,12 @@ class CheckTestCase(TestCase): ...@@ -206,8 +206,12 @@ class CheckTestCase(TestCase):
def test_check_highlight(self): def test_check_highlight(self):
if self.check is None or self.test_highlight is None: if self.check is None or self.test_highlight is None:
return return
unit = MockUnit(None, self.test_highlight[0]) unit = MockUnit(
None,
self.test_highlight[0],
source=self.test_highlight[1]
)
self.assertEqual( self.assertEqual(
self.check.check_highlight(self.test_highlight[0], unit), self.check.check_highlight(self.test_highlight[1], unit),
self.test_highlight[1] self.test_highlight[2]
) )
...@@ -23,15 +23,22 @@ Tests for quality checks. ...@@ -23,15 +23,22 @@ Tests for quality checks.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from unittest import TestCase from weblate.trans.tests.test_checks import CheckTestCase
from weblate.trans.checks.format import ( from weblate.trans.checks.format import (
PythonFormatCheck, PHPFormatCheck, CFormatCheck, PythonBraceFormatCheck, PythonFormatCheck, PHPFormatCheck, CFormatCheck, PythonBraceFormatCheck,
) )
class PythonFormatCheckTest(TestCase): class PythonFormatCheckTest(CheckTestCase):
check = PythonFormatCheck()
def setUp(self): def setUp(self):
self.check = PythonFormatCheck() super(PythonFormatCheckTest, self).setUp()
self.test_highlight = (
'python-format',
'%sstring%d',
[(0, u'%s'), (8, u'%d')],
)
def test_no_format(self): def test_no_format(self):
self.assertFalse(self.check.check_format( self.assertFalse(self.check.check_format(
...@@ -118,9 +125,16 @@ class PythonFormatCheckTest(TestCase): ...@@ -118,9 +125,16 @@ class PythonFormatCheckTest(TestCase):
)) ))
class PHPFormatCheckTest(TestCase): class PHPFormatCheckTest(CheckTestCase):
check = PHPFormatCheck()
def setUp(self): def setUp(self):
self.check = PHPFormatCheck() super(PHPFormatCheckTest, self).setUp()
self.test_highlight = (
'php-format',
'%sstring%d',
[(0, u'%s'), (8, u'%d')],
)
def test_no_format(self): def test_no_format(self):
self.assertFalse(self.check.check_format( self.assertFalse(self.check.check_format(
...@@ -207,9 +221,16 @@ class PHPFormatCheckTest(TestCase): ...@@ -207,9 +221,16 @@ class PHPFormatCheckTest(TestCase):
)) ))
class CFormatCheckTest(TestCase): class CFormatCheckTest(CheckTestCase):
check = CFormatCheck()
def setUp(self): def setUp(self):
self.check = CFormatCheck() super(CFormatCheckTest, self).setUp()
self.test_highlight = (
'c-format',
'%sstring%d',
[(0, u'%s'), (8, u'%d')],
)
def test_no_format(self): def test_no_format(self):
self.assertFalse(self.check.check_format( self.assertFalse(self.check.check_format(
...@@ -282,9 +303,16 @@ class CFormatCheckTest(TestCase): ...@@ -282,9 +303,16 @@ class CFormatCheckTest(TestCase):
)) ))
class PythonBraceFormatCheckTest(TestCase): class PythonBraceFormatCheckTest(CheckTestCase):
check = PythonBraceFormatCheck()
def setUp(self): def setUp(self):
self.check = PythonBraceFormatCheck() super(PythonBraceFormatCheckTest, self).setUp()
self.test_highlight = (
'python-brace-format',
'{0}string{1}',
[(0, u'{0}'), (9, u'{1}')],
)
def test_no_format(self): def test_no_format(self):
self.assertFalse(self.check.check_format( self.assertFalse(self.check.check_format(
......
...@@ -38,6 +38,7 @@ class BBCodeCheckTest(CheckTestCase): ...@@ -38,6 +38,7 @@ class BBCodeCheckTest(CheckTestCase):
self.test_failure_1 = ('[a]string[/a]', '[b]string[/b]', '') self.test_failure_1 = ('[a]string[/a]', '[b]string[/b]', '')
self.test_failure_2 = ('[a]string[/a]', 'string', '') self.test_failure_2 = ('[a]string[/a]', 'string', '')
self.test_highlight = ( self.test_highlight = (
'',
'[a]string[/a]', '[a]string[/a]',
[(0, '[a]'), (9, '[/a]')] [(0, '[a]'), (9, '[/a]')]
) )
...@@ -53,6 +54,7 @@ class XMLTagsCheckTest(CheckTestCase): ...@@ -53,6 +54,7 @@ class XMLTagsCheckTest(CheckTestCase):
self.test_failure_2 = ('<a>string</a>', 'string', '') self.test_failure_2 = ('<a>string</a>', 'string', '')
self.test_failure_3 = ('<a>string</a>', '<b>string</a>', '') self.test_failure_3 = ('<a>string</a>', '<b>string</a>', '')
self.test_highlight = ( self.test_highlight = (
'',
'<b><a href="foo">bar</a></b>', '<b><a href="foo">bar</a></b>',
[(0, '<b>'), (3, '<a href="foo">'), (20, '</a>'), (24, '</b>')] [(0, '<b>'), (3, '<a href="foo">'), (20, '</a>'), (24, '</b>')]
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment