Esempio n. 1
0
    def test_should_be_enabled_when_language_yaml(self):
        sublime = mock_sublime()
        view = mock_sublime_view()
        view.settings().set('syntax', 'Packages/YAML/YAML.tmLanguage')

        command = commands.FormatYamlCommand(view, sublime)
        expect(command.is_enabled()).to_equal(False)
Esempio n. 2
0
    def test_should_be_enabled_when_language_plain_text(self):
        sublime = mock_sublime()
        view = mock_sublime_view()
        view.settings().set('syntax', 'Packages/Text/Plain text.tmLanguage')

        command = commands.FormatYamlCommand(view, sublime)
        expect(command.is_enabled()).to_equal(True)
Esempio n. 3
0
    def test_should_be_enabled_when_language_json(self):
        sublime = mock_sublime()
        view = mock_sublime_view()
        view.settings().set('syntax', 'Packages/JavaScript/JSON.tmLanguage')

        command = commands.FormatYamlCommand(view, sublime)
        expect(command.is_enabled()).to_equal(True)
Esempio n. 4
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.FormatYamlCommand(view, sublime)
        command.run(edit)

        view.replace.assert_called_once_with(edit, region, '')
Esempio n. 5
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.FormatYamlCommand(view, sublime)
        command.run(edit)

        view.set_syntax_file.assert_called_once_with(
            'Packages/YAML/YAML.tmLanguage')
Esempio n. 6
0
    def test_should_invoke_command_with_multiple_regions(self):
        regions = mock_regions(['{ }', '[ ]', '[1,2]'])
        sublime = mock_sublime()
        view = mock_sublime_view(regions, lambda sel: sel())
        edit = mock_sublime_edit()

        command = commands.FormatYamlCommand(view, sublime)
        command.run(edit)

        expect(view.replace.call_count).to_equal(3)
        view.replace.assert_any_call(edit, regions[0], '')
        view.replace.assert_any_call(edit, regions[1], '')
        view.replace.assert_any_call(edit, regions[2], '- 1\n- 2')
Esempio n. 7
0
 def __init__(self, view):
     sublime_plugin.TextCommand.__init__(self, view)
     self.command = commands.FormatYamlCommand(self.view, sublime)