def test_should_invoke_command_with_no_regions(self): region = mock_regions(['{ }'])[0] sublime = mock_sublime(region) view = mock_sublime_view([], lambda sel: sel()) edit = mock_sublime_edit() command = commands.FormatJsonCommand(view, sublime) command.run(edit) view.replace.assert_called_once_with(edit, region, '{}')
def test_should_update_syntax(self): region = mock_regions(['{ }'])[0] sublime = mock_sublime(region) view = mock_sublime_view([], lambda sel: sel()) edit = mock_sublime_edit() command = commands.FormatJsonCommand(view, sublime) command.run(edit) view.set_syntax_file.assert_called_once_with( 'Packages/JavaScript/JSON.tmLanguage')
def test_should_invoke_command_with_spaces(self): region = mock_regions(['{ hello: "world" }'])[0] sublime = mock_sublime(region) view = mock_sublime_view([], lambda sel: sel()) view.settings().set('translate_tabs_to_spaces', True) edit = mock_sublime_edit() command = commands.FormatJsonCommand(view, sublime) command.run(edit) view.replace.assert_called_once_with(edit, region, '{\n "hello": "world"\n}')
def test_should_invoke_command_with_multiple_regions(self): regions = mock_regions(['{ hello: "world" }', '[ ]']) sublime = mock_sublime() view = mock_sublime_view(regions, lambda sel: sel()) edit = mock_sublime_edit() command = commands.FormatJsonCommand(view, sublime) command.run(edit) expect(view.replace.call_count).to_equal(2) view.replace.assert_any_call(edit, regions[0], '{\n\t"hello": "world"\n}') view.replace.assert_any_call(edit, regions[1], '[]')
def __init__(self, view): sublime_plugin.TextCommand.__init__(self, view) self.command = commands.FormatJsonCommand(self.view, sublime)