Commit bf06eafb authored by Philipp Wolfer's avatar Philipp Wolfer

AngularJS check: Removed caching

This was removed from all checks in a0009086
parent 821d3b39
...@@ -47,23 +47,20 @@ class AngularJSInterpolationCheck(TargetCheck): ...@@ -47,23 +47,20 @@ class AngularJSInterpolationCheck(TargetCheck):
default_disabled = True default_disabled = True
severity = 'danger' severity = 'danger'
def check_single(self, source, target, unit, cache_slot): def check_single(self, source, target, unit):
# Verify unit is properly flagged # Verify unit is properly flagged
if self.enable_string not in unit.all_flags: if self.enable_string not in unit.all_flags:
return False return False
# Try geting source parsing from cache src_match = ANGULARJS_INTERPOLATION_MATCH.findall(source)
src_match = self.get_cache(unit, cache_slot)
# Cache miss
if src_match is None:
src_match = ANGULARJS_INTERPOLATION_MATCH.findall(source)
self.set_cache(unit, src_match, cache_slot)
# Any interpolation strings in source? # Any interpolation strings in source?
if len(src_match) == 0: if len(src_match) == 0:
return False return False
# Parse target
tgt_match = ANGULARJS_INTERPOLATION_MATCH.findall(target) tgt_match = ANGULARJS_INTERPOLATION_MATCH.findall(target)
# Fail the check if the number of matches is different
if len(src_match) != len(tgt_match): if len(src_match) != len(tgt_match):
return True return True
......
...@@ -36,50 +36,42 @@ class AngularJSInterpolationCheckTest(TestCase): ...@@ -36,50 +36,42 @@ class AngularJSInterpolationCheckTest(TestCase):
self.assertFalse(self.check.check_single( self.assertFalse(self.check.check_single(
'strins', 'strins',
'string', 'string',
MockUnit('angularjs_no_format', flags='angularjs-format'), MockUnit('angularjs_no_format', flags='angularjs-format')
0
)) ))
def test_format(self): def test_format(self):
self.assertFalse(self.check.check_single( self.assertFalse(self.check.check_single(
u'{{name}} string {{other}}', u'{{name}} string {{other}}',
u'{{name}} {{other}} string', u'{{name}} {{other}} string',
MockUnit('angularjs_format', flags='angularjs-format'), MockUnit('angularjs_format', flags='angularjs-format')
0
)) ))
def test_format_ignore_position(self): def test_format_ignore_position(self):
self.assertFalse(self.check.check_single( self.assertFalse(self.check.check_single(
u'{{name}} string {{other}}', u'{{name}} string {{other}}',
u'{{other}} string {{name}}', u'{{other}} string {{name}}',
MockUnit( MockUnit('angularjs_format_ignore_position',
'angularjs_format_ignore_position', flags='angularjs-format')
flags='angularjs-format'),
0
)) ))
def test_different_whitespace(self): def test_different_whitespace(self):
self.assertFalse(self.check.check_single( self.assertFalse(self.check.check_single(
u'{{ name }} string', u'{{ name }} string',
u'{{name}} string', u'{{name}} string',
MockUnit( MockUnit('angularjs_different_whitespace',
'angularjs_different_whitespace', flags='angularjs-format')
flags='angularjs-format'),
0
)) ))
def test_missing_format(self): def test_missing_format(self):
self.assertTrue(self.check.check_single( self.assertTrue(self.check.check_single(
u'{{name}} string', u'{{name}} string',
u'string', u'string',
MockUnit('angularjs_missing_format', flags='angularjs-format'), MockUnit('angularjs_missing_format', flags='angularjs-format')
0
)) ))
def test_wrong_value(self): def test_wrong_value(self):
self.assertTrue(self.check.check_single( self.assertTrue(self.check.check_single(
u'{{name}} string', u'{{name}} string',
u'{{nameerror}} string', u'{{nameerror}} string',
MockUnit('angularjs_wrong_value', flags='angularjs-format'), MockUnit('angularjs_wrong_value', flags='angularjs-format')
0
)) ))
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