Exemple #1
0
    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, '{}')
Exemple #2
0
    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')
Exemple #3
0
    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}')
Exemple #4
0
    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], '[]')
Exemple #5
0
 def __init__(self, view):
     sublime_plugin.TextCommand.__init__(self, view)
     self.command = commands.FormatJsonCommand(self.view, sublime)