Skip to content

Commit 0471388

Browse files
committed
Handle more test cases
1 parent d86fc09 commit 0471388

File tree

7 files changed

+119
-106
lines changed

7 files changed

+119
-106
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-typescript-dev",
33
"displayName": "TSC Dev",
44
"description": "An extension only for working in the TypeScript compiler codebase",
5-
"version": "0.1.1",
5+
"version": "0.1.2",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/orta/vscode-typescript-dev"

src/baselineToTest.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ describe("edge cases", () => {
4040
const tests = [
4141
[
4242
"/tests/baselines/local/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/multiple-prologues-in-all-projects.js",
43-
"/src/testRunner/unittests/tsbuild/amdModulesWithOut.ts:85",
43+
"/src/testRunner/unittests/tsbuild/amdModulesWithOut.ts:xx",
44+
],
45+
[
46+
"/tests/baselines/local/tsbuild/moduleResolution/initial-build/type-reference-resolution-uses-correct-options-for-different-resolution-options-referenced-project.js",
47+
"/src/testRunner/unittests/tsbuild/moduleResolution.ts:xx",
4448
],
4549
];
4650
for (const test of tests) {
47-
expect(baseLineToTest(root + test[0])).toEqual(root + test[1]);
51+
let res = baseLineToTest(root + test[0]);
52+
if (res && res.includes(":")) {
53+
res = res.split(":")[0] + ":xx";
54+
}
55+
expect(res).toEqual(root + test[1]);
4856
}
4957
});
5058
});

src/baselineToTest.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,18 @@ export const baselineToTester = (config: { tscRoot: string }) => {
8282
const filesInDirectory = fs.readdirSync(tsBuildTests);
8383

8484
// Look through all the tsbuild test files, looking for a sub-scenario with the same name as the file
85-
const scenario = `subscenario: "${name.replace(/-/g, " ")}"`.toLowerCase();
85+
const scenarioQuote = `subscenario: "${name.replace(/-/g, " ")}"`.toLowerCase();
86+
const scenarioBack = `subscenario: \`${name.replace(/-/g, " ")}\``.toLowerCase();
8687

8788
for (const f of filesInDirectory) {
8889
const filepath = join(tsBuildTests, f);
8990
const content = fs.readFileSync(filepath, "utf8").toLowerCase();
9091

91-
if (content.includes(scenario)) {
92-
const line = getLineForResultInString(scenario, content);
92+
const gotQuote = content.includes(scenarioQuote);
93+
const gotBacktick = content.includes(scenarioBack);
94+
if (gotQuote || gotBacktick) {
95+
const found = gotQuote ? scenarioQuote : scenarioBack;
96+
const line = getLineForResultInString(found, content);
9397
const result = line !== -1 ? `${filepath}:${line}` : filepath;
9498
resultsCache.set(withoutExt, result);
9599
return result;

src/position.ts

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from "vscode";
2+
import { tryParseRangeExpression } from "./positionExpression";
23

34
const goToPositionCommandName = "io.orta.typescript-dev.go-to-position";
45
const togglePositionCommandName = "io.orta.typescript-dev.toggle-position";
@@ -58,100 +59,3 @@ function updatePosition(statusBarItem: vscode.StatusBarItem) {
5859
statusBarItem.text = "Pos " + lower + (upper === lower ? "" : `, ${upper}`);
5960
}
6061
}
61-
62-
export function tryParseRangeExpression(expr: string): readonly [number, number | undefined] | undefined {
63-
const [startExpr, endExpr] = expr.split(",");
64-
const start = tryParsePositionExpression(startExpr);
65-
if (start === undefined) return undefined;
66-
return [start, endExpr === undefined ? endExpr : tryParsePositionExpression(endExpr)];
67-
}
68-
69-
function tryParsePositionExpression(expr: string): number | undefined {
70-
const enum State {
71-
ParseOperator,
72-
ParseOperand,
73-
}
74-
75-
let state = State.ParseOperand as State;
76-
let value: number | undefined;
77-
let operator: "+" | "-" = "+";
78-
let pos = 0;
79-
80-
while (pos < expr.length) {
81-
skipSpace();
82-
const current = expr[pos];
83-
if (!current) break;
84-
85-
switch (state) {
86-
case State.ParseOperand:
87-
if (isNumeric(current)) {
88-
value = operate(consumeInt());
89-
state = State.ParseOperator;
90-
continue;
91-
} else if (current === "+") {
92-
pos++;
93-
continue;
94-
} else if (current === "-") {
95-
flipSign();
96-
pos++;
97-
continue;
98-
} else {
99-
return undefined;
100-
}
101-
case State.ParseOperator:
102-
if (current === "+") {
103-
operator = "+";
104-
pos++;
105-
state = State.ParseOperand;
106-
} else if (current === "-") {
107-
operator = "-";
108-
pos++;
109-
state = State.ParseOperand;
110-
} else {
111-
return undefined;
112-
}
113-
}
114-
}
115-
return value !== undefined && value >= 0 ? value : undefined;
116-
117-
function consumeInt(): number | undefined {
118-
let start = pos;
119-
while (pos < expr.length && isNumeric(expr[pos])) {
120-
pos++;
121-
}
122-
const int = +expr.slice(start, pos);
123-
if (Number.isSafeInteger(int)) {
124-
return int;
125-
}
126-
}
127-
128-
function skipSpace() {
129-
while (pos < expr.length && /\s/.test(expr[pos])) {
130-
pos++;
131-
}
132-
}
133-
134-
function operate(operand: number | undefined) {
135-
if (operand === undefined) return value;
136-
if (value === undefined) value = 0;
137-
switch (operator) {
138-
case "+":
139-
return value + operand;
140-
case "-":
141-
return value - operand;
142-
}
143-
}
144-
145-
function flipSign() {
146-
if (operator === "+") {
147-
operator = "-";
148-
} else {
149-
operator = "+";
150-
}
151-
}
152-
}
153-
154-
function isNumeric(char: string) {
155-
const code = char.charCodeAt(0);
156-
return 48 <= code && code <= 57;
157-
}

src/positionExpression.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
export function tryParseRangeExpression(expr: string): readonly [number, number | undefined] | undefined {
2+
const [startExpr, endExpr] = expr.split(",");
3+
const start = tryParsePositionExpression(startExpr);
4+
if (start === undefined) return undefined;
5+
return [start, endExpr === undefined ? endExpr : tryParsePositionExpression(endExpr)];
6+
}
7+
8+
function tryParsePositionExpression(expr: string): number | undefined {
9+
const enum State {
10+
ParseOperator,
11+
ParseOperand,
12+
}
13+
14+
let state = State.ParseOperand as State;
15+
let value: number | undefined;
16+
let operator: "+" | "-" = "+";
17+
let pos = 0;
18+
19+
while (pos < expr.length) {
20+
skipSpace();
21+
const current = expr[pos];
22+
if (!current) break;
23+
24+
switch (state) {
25+
case State.ParseOperand:
26+
if (isNumeric(current)) {
27+
value = operate(consumeInt());
28+
state = State.ParseOperator;
29+
continue;
30+
} else if (current === "+") {
31+
pos++;
32+
continue;
33+
} else if (current === "-") {
34+
flipSign();
35+
pos++;
36+
continue;
37+
} else {
38+
return undefined;
39+
}
40+
case State.ParseOperator:
41+
if (current === "+") {
42+
operator = "+";
43+
pos++;
44+
state = State.ParseOperand;
45+
} else if (current === "-") {
46+
operator = "-";
47+
pos++;
48+
state = State.ParseOperand;
49+
} else {
50+
return undefined;
51+
}
52+
}
53+
}
54+
return value !== undefined && value >= 0 ? value : undefined;
55+
56+
function consumeInt(): number | undefined {
57+
let start = pos;
58+
while (pos < expr.length && isNumeric(expr[pos])) {
59+
pos++;
60+
}
61+
const int = +expr.slice(start, pos);
62+
if (Number.isSafeInteger(int)) {
63+
return int;
64+
}
65+
}
66+
67+
function skipSpace() {
68+
while (pos < expr.length && /\s/.test(expr[pos])) {
69+
pos++;
70+
}
71+
}
72+
73+
function operate(operand: number | undefined) {
74+
if (operand === undefined) return value;
75+
if (value === undefined) value = 0;
76+
switch (operator) {
77+
case "+":
78+
return value + operand;
79+
case "-":
80+
return value - operand;
81+
}
82+
}
83+
84+
function flipSign() {
85+
if (operator === "+") {
86+
operator = "-";
87+
} else {
88+
operator = "+";
89+
}
90+
}
91+
}
92+
93+
function isNumeric(char: string) {
94+
const code = char.charCodeAt(0);
95+
return 48 <= code && code <= 57;
96+
}

src/test/suite/position.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from "assert";
2-
import { tryParseRangeExpression } from "../../position";
2+
import { tryParseRangeExpression } from "../../positionExpression";
33

4-
suite("Go To Position", () => {
4+
describe("Go To Position", () => {
55
test("parses simple expressions", () => {
66
assert.deepStrictEqual(tryParseRangeExpression("3"), [3, undefined]);
77
assert.deepStrictEqual(tryParseRangeExpression("422424"), [422424, undefined]);
@@ -33,4 +33,4 @@ suite("Go To Position", () => {
3333
assert.deepStrictEqual(tryParseRangeExpression("3,,,,4"), [3, undefined]);
3434
assert.deepStrictEqual(tryParseRangeExpression("3, 2"), [3, 2]);
3535
});
36-
});
36+
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"es6"
88
],
99
"sourceMap": true,
10+
"noEmit": true,
1011
"rootDir": "src",
1112
"strict": true /* enable all strict type-checking options */
1213
/* Additional Checks */

0 commit comments

Comments
 (0)