2014-03-28 20:28:06 +04:00
|
|
|
describe "TokenizedLine", ->
|
|
|
|
editor = null
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-03-28 20:51:30 +04:00
|
|
|
waitsForPromise -> atom.packages.activatePackage('language-coffee-script')
|
2014-03-28 20:28:06 +04:00
|
|
|
|
2014-06-25 01:44:45 +04:00
|
|
|
describe "::isOnlyWhitespace()", ->
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('coffee.coffee').then (o) -> editor = o
|
|
|
|
|
|
|
|
it "returns true when the line is only whitespace", ->
|
2014-09-04 00:49:52 +04:00
|
|
|
expect(editor.tokenizedLineForScreenRow(3).isOnlyWhitespace()).toBe true
|
|
|
|
expect(editor.tokenizedLineForScreenRow(7).isOnlyWhitespace()).toBe true
|
|
|
|
expect(editor.tokenizedLineForScreenRow(23).isOnlyWhitespace()).toBe true
|
2014-06-25 01:44:45 +04:00
|
|
|
|
2014-06-25 02:13:01 +04:00
|
|
|
it "returns false when the line is not only whitespace", ->
|
2014-09-04 00:49:52 +04:00
|
|
|
expect(editor.tokenizedLineForScreenRow(0).isOnlyWhitespace()).toBe false
|
|
|
|
expect(editor.tokenizedLineForScreenRow(2).isOnlyWhitespace()).toBe false
|
2014-06-25 01:44:45 +04:00
|
|
|
|
2014-03-28 20:28:06 +04:00
|
|
|
describe "::getScopeTree()", ->
|
2014-10-14 03:30:41 +04:00
|
|
|
it "returns a tree whose inner nodes are scopeDescriptor and whose leaf nodes are tokens in those scopeDescriptor", ->
|
2014-04-30 03:24:16 +04:00
|
|
|
[tokens, tokenIndex] = []
|
2014-03-28 20:51:30 +04:00
|
|
|
|
2014-10-14 03:30:41 +04:00
|
|
|
ensureValidScopeTree = (scopeTree, scopeDescriptor=[]) ->
|
2014-03-28 20:51:30 +04:00
|
|
|
if scopeTree.children?
|
|
|
|
for child in scopeTree.children
|
2014-10-14 03:30:41 +04:00
|
|
|
ensureValidScopeTree(child, scopeDescriptor.concat([scopeTree.scope]))
|
2014-03-28 20:51:30 +04:00
|
|
|
else
|
|
|
|
expect(scopeTree).toBe tokens[tokenIndex++]
|
2014-10-21 22:38:43 +04:00
|
|
|
expect(scopeDescriptor).toEqual scopeTree.scopes
|
2014-03-28 20:51:30 +04:00
|
|
|
|
2014-04-25 01:14:10 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('coffee.coffee').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
tokenIndex = 0
|
2014-09-04 00:49:52 +04:00
|
|
|
tokens = editor.tokenizedLineForScreenRow(1).tokens
|
|
|
|
scopeTree = editor.tokenizedLineForScreenRow(1).getScopeTree()
|
2014-04-25 01:14:10 +04:00
|
|
|
ensureValidScopeTree(scopeTree)
|