This repository was archived by the owner on Feb 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScopeDescriptorHelper-spec.coffee
87 lines (60 loc) · 2.48 KB
/
ScopeDescriptorHelper-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{Point} = require 'atom'
ScopeDescriptorHelper = require '../lib/ScopeDescriptorHelper'
describe "ScopeDescriptorHelper", ->
editor = null
grammar = null
helper = new ScopeDescriptorHelper()
beforeEach ->
waitsForPromise ->
atom.workspace.open().then (result) ->
editor = result
waitsForPromise ->
atom.packages.activatePackage('language-php')
runs ->
grammar = atom.grammars.selectGrammar('.text.html.php')
waitsFor ->
grammar and editor
runs ->
editor.setGrammar(grammar)
it "getStartOfClassListAtPosition returns the range of a class list", ->
source =
'''
<?php
$test = 'string';
'''
editor.setText(source)
classList = ['meta', 'string-contents', 'quoted', 'single', 'php']
line = 2
startColumn = 9
endColumn = 14
for i in [startColumn .. endColumn]
bufferPosition = new Point(2, i)
range = helper.getBufferRangeForClassListAtPosition(editor, classList, bufferPosition, 1)
expect(range).toBeTruthy()
# NOTE: The quotation marks have a different scope descriptor than the actual string contents, so they are not
# included in the range.
expect(range.start.row).toEqual(2)
expect(range.start.column).toEqual(startColumn)
expect(range.end.row).toEqual(2)
expect(range.end.column).toEqual(endColumn + 1)
it "getStartOfClassListAtPosition moves up in the scope list if requested", ->
source =
'''
<?php
$test = \\Some\\Namespace\\CONST_TEST;
'''
editor.setText(source)
classList = ['support', 'other', 'namespace', 'php']
line = 2
startColumn = 8
endColumn = 23
for i in [startColumn .. endColumn]
bufferPosition = new Point(2, i)
range = helper.getBufferRangeForClassListAtPosition(editor, classList, bufferPosition, 0)
expect(range).toBeTruthy()
# NOTE: The quotation marks have a different scope descriptor than the actual string contents, so they are not
# included in the range.
expect(range.start.row).toEqual(2)
expect(range.start.column).toEqual(startColumn)
expect(range.end.row).toEqual(2)
expect(range.end.column).toEqual(endColumn + 1)