Skip to content

Commit e49891b

Browse files
committed
Fix upper logic to respect PS escape characters
1 parent 0d40691 commit e49891b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

tests/py/syntax_def/test_token_gen.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ def testGetLowerTokens(self):
2525
self.writeTokensToFile(self.getTokens(), "test-file.ps1.lower.tokens")
2626

2727
def testGetUpperTokens(self):
28+
29+
def escaped_upper(i, line):
30+
should = not (i > 0 and line[i-1] == '`')
31+
if (should):
32+
return line[i].upper()
33+
else:
34+
return line[i]
35+
2836
with open(self.test_path) as f:
2937
content = f.readlines()
3038
for line in content:
31-
self.append(line.upper())
39+
# escaped chars (like `n) are case-sensitive, don't upper them
40+
line_up = ''.join([escaped_upper(i, line) for i in range(len(line))])
41+
self.append(line_up)
3242
self.writeTokensToFile(self.getTokens(), "test-file.ps1.upper.tokens")
3343

tests/samples/test-file.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ string.'
9898
'This is a string.'
9999

100100
# Escaped characters should be highlighted
101-
"Escaped chars: `", `n, `$, `b, `""
101+
"Escaped chars: `", `n, `$, `b, `t, `""
102102

103103
# Including '' in a 'single quoted string'
104104
'But here they''re not escape chars: `", `n, `$, `b, `"'

0 commit comments

Comments
 (0)