Skip to content

Commit

Permalink
Merge pull request #44 from SublimeLinter/add-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Jul 17, 2022
2 parents 33da303 + b3b7034 commit e5f6b4c
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: TrueBrain/actions-flake8@v2

run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: SublimeText/UnitTesting/actions/setup@v1
with:
sublime-text-version: 4
extra-packages:
SublimeLinter/SublimeLinter
- uses: SublimeText/UnitTesting/actions/run-tests@v1
105 changes: 105 additions & 0 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import unittest
import importlib

import sublime
from SublimeLinter.lint.linter import get_linter_settings

from SublimeLinter.tests.parameterized import parameterized as p


LinterModule = importlib.import_module('SublimeLinter-annotations.linter')
Linter = LinterModule.Annotations


class TestRegex(unittest.TestCase):
def create_window(self):
sublime.run_command("new_window")
window = sublime.active_window()
self.addCleanup(self.close_window, window)
return window

def close_window(self, window):
window.run_command('close_window')

def create_view(self, window):
view = window.new_file()
self.addCleanup(self.close_view, view)
return view

def close_view(self, view):
view.set_scratch(True)
view.close()

def assertMatch(self, string, expected):
linter = Linter(sublime.View(0), {})
actual = list(linter.find_errors(string))[0]
# `find_errors` fills out more information we don't want to write down
# in the examples
self.assertEqual({k: actual[k] for k in expected.keys()}, expected)

def assertNoMatch(self, string):
linter = Linter(sublime.View(0), {})
actual = list(linter.find_errors(string))
self.assertFalse(actual)

@p.expand(
[
(
"# {} The {} message".format(word, error_type),
"scope:source.python",
{
"line": 0,
"col": 2,
"message": "The {} message".format(error_type),
"error_type": error_type,
},
)
for error_type, words in (
("error", ("FIXME", "ERROR")),
("warning", ("TODO", "@todo", "XXX", "WIP", "WARNING")),
("info", ("NOTE", "README", "INFO")),
)
for word in words
]
)
def test_a(self, view_content, syntax, expected):
window = self.create_window()
view = self.create_view(window)
view.assign_syntax(syntax)
view.run_command('append', {'characters': view_content})

settings = get_linter_settings(Linter, view, context=None)
linter = Linter(view, settings)
actual = list(linter.find_errors("_ignored by plugin"))[0]
self.assertEqual({k: actual[k] for k in expected.keys()}, expected)

@p.expand(
[
(
"# NOTE The note message\n" "# ERROR The error message\n",
"scope:source.python",
[
{
"line": 1,
"col": 2,
"message": "The error message",
"error_type": "error",
}
],
)
]
)
def test_set_word_group_to_null_issue_39(
self, view_content, syntax, expected
):
window = self.create_window()
view = self.create_view(window)
view.assign_syntax(syntax)
view.run_command('append', {'characters': view_content})

settings = get_linter_settings(Linter, view, context=None)
settings["infos"] = []
linter = Linter(view, settings)
actual = list(linter.find_errors("_ignored by plugin"))
for i, error in enumerate(expected):
self.assertEqual({k: actual[i][k] for k in error.keys()}, error)

0 comments on commit e5f6b4c

Please sign in to comment.