def test_selection2(self, active_window): MockView.sel.return_value = [sublime.Region(5, 10)] self.assertEqual( Macro.get_selection(raw=False), "Hello" ) MockView.sel.return_value = [ sublime.Region(5, 10), sublime.Region(12, 17) ] self.assertEqual( Macro.get_selection(raw=False), "World" ) MockView.sel.return_value = [ sublime.Region(5, 10), sublime.Region(12, 17), sublime.Region(11, 17) ] self.assertEqual( Macro.get_selection(raw=False), "World" ) self.assertEqual( Macro.get_selection(raw=True), " World" )
def test_working_project_dir2(self, active_window): self.assertEqual( Macro.get_working_project_dir(), None ) self.assertEqual( Macro.get_working_project_name(), None )
def test_parent_dir2(self, active_window): self.assertEqual( Macro.get_parent_dir(), None ) self.assertEqual( Macro.get_parent_name(), None )
def test_project_dir2(self, active_window): self.assertEqual( Macro.get_project_dir(), "another/path/to/directory" ) self.assertEqual( Macro.get_project_name(), "directory" )
def test_file_path2(self, active_window): self.assertEqual( Macro.get_file_path(), None ) self.assertEqual( Macro.get_file_name(), None )
def test_parent_dir(self, active_window): self.assertEqual( Macro.get_parent_dir(), "path/to" ) self.assertEqual( Macro.get_parent_name(), "to" )
def test_file_path(self, active_window): self.assertEqual( Macro.get_file_path(), "path/to/file.ext" ) self.assertEqual( Macro.get_file_name(), "file.ext" )
def test_working_project_dir(self, active_window): self.assertEqual( Macro.get_working_project_dir(), "path/to" ) self.assertEqual( Macro.get_working_project_name(), "to" )
def test_regex_macro(self, active_window): macros = { "test": "$custom;$custom2;$custom3;$custom4", "expected": ".ext;.ext;.ext;.ext", "required": [], "macros": { "custom": [ "$file", ["\\.\\w+$"] ], "custom2": [ "$file_name", ["\\.\\w+$"] ], "custom3": [ ["$file", "\\.\\w+$"] ], "custom4": [ ["$file_name", "\\.\\w+$"] ] } } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_predefined_macro5(self, active_window): macros = { "test": "$working$$$working_project$$$project", "expected": "path/to$path/to$another/path/to/directory", "required": [], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_predefined_macro3(self, active_window): macros = { "test": "$require ; $file", "expected": " ; path/to/file.ext", "required": [], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_predefined_macro2(self, active_window): macros = { "test": "$file_name", "expected": None, "required": ["required", "file_name"], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_empty(self, active_window): macros = { "test": "", "expected": "", "required": [], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_none(self, active_window): macros = { "test": None, "expected": None, "required": None, "macros": None } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_required_macro7(self, active_window): macros = { "test": "$selection", "expected": None, "required": ["selection"], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_predefined_macro4(self, active_window): macros = { "test": "$parent$file$file_name", "expected": "path/topath/to/file.extfile.ext", "required": [], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_required_macro9(self, active_window): MockView.sel.return_value = [sublime.Region(5, 10)] macros = { "test": "$selection", "expected": "Hello", "required": ["selection"], "macros": {} } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_selection(self, active_window): self.assertEqual( Macro.get_selection(raw=False), None ) self.assertEqual( Macro.get_selection(raw=True), None ) MockView.sel.return_value = [] self.assertEqual( Macro.get_selection(raw=False), None ) self.assertEqual( Macro.get_selection(raw=True), None ) MockView.sel.return_value = [sublime.Region(11, 11)] self.assertEqual( Macro.get_selection(raw=False), None ) self.assertEqual( Macro.get_selection(raw=True), None ) MockView.sel.return_value = [sublime.Region(11, 12)] self.assertEqual( Macro.get_selection(raw=False), None ) self.assertEqual( Macro.get_selection(raw=True), " " )
def test_recursion_macro2(self, active_window): macros = { "test": "$required", "expected": "", "required": [], "macros": { "required": [ "$required2" ], "required2": [ "$required" ] } } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )
def test_required_macro5(self, active_window): macros = { "test": "$required", "expected": "", "required": [], "macros": { "required": [ 1, [1, 2], None, [None, None] ] } } self.assertEqual( Macro.parse_macro( string=macros["test"], custom_macros=macros["macros"], required=macros["required"] ), macros["expected"] )