Skip to content

Commit

Permalink
Test using Linter split match
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardroche committed Jul 13, 2022
1 parent b1b02d1 commit 15b00ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
7 changes: 2 additions & 5 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ class PHP(Linter):
def split_match(self, match):
"""Return the components of the error."""
result = super().split_match(match)
result['message'] = _filter_message(result.message)

match, line, col, error, warning, message, near = result

message = _filter_message(message)

return match, line, col, error, warning, message, near
return result

def cmd(self):
"""Read cmd from inline settings."""
Expand Down
38 changes: 24 additions & 14 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@
import re
import importlib

import sublime

# Damn you dash separated module names!!!
LinterModule = importlib.import_module('SublimeLinter-php.linter')
Linter = LinterModule.PHP
_filter_message = LinterModule._filter_message
regex = Linter.regex


class TestRegex(unittest.TestCase):

def assertMatch(self, string, expected):
def splitMatch(self, string):
linter = Linter(sublime.View(0), {})
match = re.match(regex, string)
self.assertIsNotNone(match)

# Hack to test message filtering.
actual = match.groupdict()
if 'message' in actual:
actual['message'] = _filter_message(actual['message'])
if match is None:
return None

match = linter.split_match(match)

self.assertEqual(actual, expected)
return {
'error': match['error'],
'line': match['line'],
'message': match['message'],
'near': match['near'],
}


def assertMatch(self, string, expected):
self.assertEqual(self.splitMatch(string), expected)

def assertNoMatch(self, string):
self.assertIsNone(re.match(regex, string))
self.assertIsNone(self.splitMatch(string))

def test_no_errors(self):
self.assertNoMatch('No syntax errors detected in - ')
Expand All @@ -34,17 +44,17 @@ def test_no_errors(self):

def test_errors(self):
self.assertMatch(
'Parse error: syntax error, unexpected \'$this\' (T_VARIABLE) in - on line 14', {
'Parse error: syntax error, unexpected \'$this\' (T_VARIABLE) on line 14', {
'error': 'Parse',
'line': '14',
'line': 13,
'message': 'syntax error, unexpected \'$this\' (T_VARIABLE)',
'near': '$this'
})

self.assertMatch(
'Parse error: syntax error, unexpected end of file in - on line 23', {
'error': 'Parse',
'line': '23',
'line': 22,
'message': 'syntax error, unexpected end of file',
'near': None
})
Expand All @@ -53,15 +63,15 @@ def test_issue_29(self):
self.assertMatch(
'Parse error: syntax error, unexpected \'endwhile\' (T_ENDWHILE), expecting end of file in Standard input code on line 16', {
'error': 'Parse',
'line': '16',
'line': 15,
'message': 'syntax error, unexpected \'endwhile\' (T_ENDWHILE), expecting end of file',
'near': 'endwhile'
})

self.assertMatch(
'Parse error: parse error in - on line 16', {
'error': 'Parse',
'line': '16',
'line': 15,
'message': 'parse error',
'near': None
})

0 comments on commit 15b00ec

Please sign in to comment.