1
|
|
|
import sublime |
2
|
|
|
import sys |
3
|
|
|
from unittest import TestCase |
4
|
|
|
|
5
|
|
|
version = sublime.version() |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class stderrobj: |
9
|
|
|
def __init__(self): |
10
|
|
|
self.buff='' |
11
|
|
|
self.__console__=sys.stderr |
12
|
|
|
sys.stderr = self |
13
|
|
|
|
14
|
|
|
def write(self, output_stream): |
15
|
|
|
self.buff+=output_stream |
16
|
|
|
|
17
|
|
|
def empty(self): |
18
|
|
|
return self.buff == '' |
19
|
|
|
|
20
|
|
|
def reset(self): |
21
|
|
|
if self.__console__ is not None: |
22
|
|
|
sys.stderr = self.__console__ |
23
|
|
|
self.__console__ = None |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
# for testing sublime command |
27
|
|
|
class TestQuickGotoAnything(TestCase): |
28
|
|
|
|
29
|
|
|
def setUp(self): |
30
|
|
|
self.view = sublime.active_window().new_file() |
31
|
|
|
# make sure we have a window to work with |
32
|
|
|
s = sublime.load_settings("Preferences.sublime-settings") |
33
|
|
|
s.set("close_windows_when_empty", False) |
34
|
|
|
|
35
|
|
|
self.obj = stderrobj() |
36
|
|
|
|
37
|
|
|
def tearDown(self): |
38
|
|
|
self.obj.reset() |
39
|
|
|
if self.view: |
40
|
|
|
self.view.set_scratch(True) |
41
|
|
|
self.view.window().focus_view(self.view) |
42
|
|
|
self.view.window().run_command("close_file") |
43
|
|
|
|
44
|
|
|
self.assertTrue(self.obj.empty(), self.obj.buff) |
45
|
|
|
|
46
|
|
|
# since ST3 uses python 2 and python 2 doesn't support @unittest.skip, |
47
|
|
|
# we have to do primitive skipping |
48
|
|
|
# if version >= '3000': |
49
|
|
|
# def test_hello_world_st3(self): |
50
|
|
|
# self.view.run_command("quick_goto_function") |
51
|
|
|
# first_row = self.getRow(0) |
52
|
|
|
# self.assertEqual(first_row, "hello world") |
53
|
|
|
|
54
|
|
|
def test_goto_function(self): |
55
|
|
|
self.view.run_command("quick_goto_function") |
56
|
|
|
|
57
|
|
|
def test_goto_variable(self): |
58
|
|
|
self.view.run_command("quick_goto_variable") |
59
|
|
|
|
60
|
|
|
def test_goto_file(self): |
61
|
|
|
self.view.run_command("quick_goto_file") |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
# for testing internal function |
66
|
|
|
# if version < '3000': |
67
|
|
|
# # st2 |
68
|
|
|
# QuickGotoAnything = sys.modules["QuickGotoAnything"] |
69
|
|
|
# else: |
70
|
|
|
# # st3 |
71
|
|
|
# QuickGotoAnything = sys.modules["QuickGotoAnything.QuickGotoAnything"] |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
# class TestFunctions(TestCase): |
75
|
|
|
|
76
|
|
|
# def setUp(self): |
77
|
|
|
# self.view = sublime.active_window().new_file() |
78
|
|
|
# # make sure we have a window to work with |
79
|
|
|
# s = sublime.load_settings("Preferences.sublime-settings") |
80
|
|
|
# s.set("close_windows_when_empty", False) |
81
|
|
|
|
82
|
|
|
# def tearDown(self): |
83
|
|
|
# if self.view: |
84
|
|
|
# self.view.set_scratch(True) |
85
|
|
|
# self.view.window().focus_view(self.view) |
86
|
|
|
# self.view.window().run_command("close_file") |
87
|
|
|
|
88
|
|
|
# def test_foo(self): |
89
|
|
|
# command = QuickGotoAnything.QuickGotoFunctionCommand() |
90
|
|
|
# command.run(None) |