Skip to content

Commit dadd3e9

Browse files
committed
Produce tokens for test-file.ps1
1 parent 0ddf786 commit dadd3e9

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

tests/__init__.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,62 @@ def getTokenHeader(self):
4343
return ['scope_name', 'str', 'start', 'end']
4444

4545
def getTokens(self):
46-
selectors = ["comment", "constant", "entity", "interpolated", "keyword", "meta", "punctuation", "source", "storage", "string", "support", "variable"]
46+
selectors = [
47+
"comment.block",
48+
"comment.documentation.embedded",
49+
"comment.line.number-sign",
50+
"constant.character.escape",
51+
"constant.language",
52+
"constant.numeric.hexadecimal",
53+
"constant.numeric.scientific",
54+
"constant.string.documentation",
55+
"entity.name",
56+
"entity.name.function.invocation",
57+
"entity.other",
58+
"entity.other.attribute-name",
59+
"entity.other.attribute.parameter",
60+
"interpolated.complex.source",
61+
"interpolated.simple.source",
62+
"keyword.control",
63+
"keyword.operator.assignment",
64+
"keyword.operator.bitwise",
65+
"keyword.operator.comparison",
66+
"keyword.operator.documentation",
67+
"keyword.operator.logical",
68+
"keyword.operator.math",
69+
"keyword.operator.other",
70+
"keyword.operator.range",
71+
"keyword.operator.redirection",
72+
"keyword.operator.string-format",
73+
"keyword.operator.unary",
74+
"keyword.other",
75+
"keyword.other.statement-separator",
76+
"meta",
77+
"meta.group.array-expression",
78+
"meta.group.complex.subexpression",
79+
"meta.scriptblock",
80+
"punctuation.end.definition.comment.block",
81+
"punctuation.start.definition.comment.block",
82+
"source",
83+
"storage",
84+
"storage.modifier.scope",
85+
"string.quoted.double",
86+
"string.quoted.double.heredoc",
87+
"string.quoted.single",
88+
"string.quoted.single.heredoc",
89+
"support.constant",
90+
"support.constant.variable",
91+
"support.function",
92+
"support.variable.automatic",
93+
"support.variable.drive",
94+
"variable.language",
95+
"variable.other",
96+
"variable.other.normal",
97+
"variable.other.readwrite",
98+
]
4799
tokens = []
48100
for selector in selectors:
49101
regions = self.view.find_by_selector(selector)
50102
for region in regions:
51-
tokens += [{ 'scope_name': selector, 'str': 'foo', 'start': region.a, 'end': region.b }]
103+
tokens += [{ 'scope_name': selector, 'str': self.view.substr(region), 'start': region.a, 'end': region.b }]
52104
return tokens

tests/syntax_def/test_token_gen.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import os
22
import sublime
3-
import csv
3+
import json
44

55
from PowerShell.tests import PowerShellSyntaxTokenTest
66

77
class Test_TokenGenerator(PowerShellSyntaxTokenTest):
88
def testGetTokens(self):
99

10-
self.append("""$foo = @'
11-
hello
12-
'@
13-
""")
10+
test_path = os.path.join(sublime.packages_path(), 'PowerShell', 'tests', 'samples', 'test-file.ps1')
11+
12+
with open(test_path) as f:
13+
content = f.readlines()
14+
for line in content:
15+
self.append(line)
16+
1417
tokens = self.getTokens()
1518

1619
outputdir = os.path.join(sublime.packages_path(), 'User', 'UnitTesting', "tokens")
@@ -21,9 +24,6 @@ def testGetTokens(self):
2124
if os.path.exists(outfile):
2225
os.remove(outfile)
2326
with open(outfile, 'w') as f:
24-
header = self.getTokenHeader()
25-
writer = csv.DictWriter(f, header, delimiter=',')
26-
writer.writeheader()
27-
writer.writerows(tokens)
27+
f.write(json.dumps(tokens, indent=4, separators=(',', ': ')))
28+
f.write(test_path)
2829

29-

0 commit comments

Comments
 (0)