Skip to content

Instantly share code, notes, and snippets.

@sadovnychyi
Last active January 15, 2018 08:20
Show Gist options
  • Save sadovnychyi/147b0ec14c8507e4d66d5317b4a482ba to your computer and use it in GitHub Desktop.
Save sadovnychyi/147b0ec14c8507e4d66d5317b4a482ba to your computer and use it in GitHub Desktop.
packagesToTest =
Python:
name: 'language-python'
file: 'test.py'
describe 'Jedi autocompletions', ->
[editor, provider] = []
getCompletions = ->
cursor = editor.getLastCursor()
start = cursor.getBeginningOfCurrentWordBufferPosition()
end = cursor.getBufferPosition()
prefix = editor.getTextInRange([start, end])
request =
editor: editor
bufferPosition: end
scopeDescriptor: cursor.getScopeDescriptor()
prefix: prefix
return Promise.resolve(provider.getSuggestions(request))
beforeEach ->
atom.config.set('autocomplete-python.useKite', false)
waitsForPromise -> atom.packages.activatePackage('language-python')
waitsForPromise -> atom.workspace.open('test.py')
runs ->
editor = atom.workspace.getActiveTextEditor()
editor.setGrammar(atom.grammars.grammarForScopeName['source.python'])
atom.packages.loadPackage('autocomplete-python').activationHooks = []
waitsForPromise -> atom.packages.activatePackage('autocomplete-python')
runs ->
atom.packages.getActivePackage('autocomplete-python').mainModule.load()
runs -> provider = atom.packages.getActivePackage(
'autocomplete-python').mainModule.getProvider()
it 'autocompletes builtins', ->
editor.setText 'isinstanc'
editor.setCursorBufferPosition([1, 0])
waitsForPromise ->
getCompletions().then (completions) ->
for completion in completions
expect(completion.text.length).toBeGreaterThan 0
expect(completion.text).toBe 'isinstance'
expect(completions.length).toBe 1
it 'autocompletes python keywords', ->
editor.setText 'impo'
editor.setCursorBufferPosition([1, 0])
waitsForPromise ->
getCompletions().then (completions) ->
for completion in completions
if completion.type == 'keyword'
expect(completion.text).toBe 'import'
expect(completion.text.length).toBeGreaterThan 0
expect(completions.length).toBe 3
it 'autocompletes defined functions', ->
editor.setText """
def hello_world():
return True
hell
"""
editor.setCursorBufferPosition([3, 0])
waitsForPromise ->
getCompletions().then (completions) ->
expect(completions[0].text).toBe 'hello_world'
expect(completions.length).toBe 1
it 'autocompletes stuff', ->
editor.setText """
def hello_world2():
return True
hell
"""
editor.setCursorBufferPosition([3, 0])
waitsForPromise ->
getCompletions().then (completions) ->
expect(completions[0].text).toBe 'hello_world2'
expect(completions.length).toBe 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment