Skip to content

Commit

Permalink
Change parseTemplate to synchronous (#1266)
Browse files Browse the repository at this point in the history
* Change parseTemplate to synchronous

* Fix build

* Remove unintended file

Co-authored-by: Stephen Weatherford <[email protected]>
  • Loading branch information
StephenWeatherford and Stephen Weatherford authored Mar 24, 2021
1 parent 9a64dd9 commit 416d38b
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"DISABLE_SLOW_TESTS": "0",
"ECHO_OUTPUT_CHANNEL_TO_CONSOLE": "1",
"BREAK_ON_ASSERT": "0",
"ALWAYS_ECHO_TEST_LOG": "1" // If 1 or true, always immediately echos test log to console; otherwise test log is only echoed after a failed testcase
"ALWAYS_ECHO_TEST_LOG": "0" // If 1 or true, always immediately echos test log to console; otherwise test log is only echoed after a failed testcase
}
},
// Launch extension with webpack
Expand Down
10 changes: 5 additions & 5 deletions test/DeploymentTemplate.CodeLenses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ suite("DeploymentTemplate code lenses", () => {
suite("parameters section code lens", () => {
suite("if no parameter file then", () => {
test("expect only a single parameters section code lens", async () => {
const dt = await parseTemplate(template1);
const dt = parseTemplate(template1);
const lenses = dt.getCodeLenses(undefined);
assert.equal(lenses.length, 1, "Expecting only a code lens for the parameters section itself");
});

test("code lens should show command to select/create one", async () => {
const dt = await parseTemplate(template1);
const dt = parseTemplate(template1);
const lenses = dt.getCodeLenses(undefined);
for (const lens of lenses) {
const result = await lens.resolve();
Expand All @@ -147,7 +147,7 @@ suite("DeploymentTemplate code lenses", () => {

suite("if there is a parameter file then", () => {
test("parameter section code lens should show command to open current parameter file and one to change the selection", async () => {
const dt = await parseTemplate(template1);
const dt = parseTemplate(template1);
const { dp } = await parseParametersWithMarkers({});
const lenses = dt.getCodeLenses(new FakeParameterValuesSourceProvider(dp.documentUri, dp.parameterValuesSource));
assert.equal(lenses.length, 2 + dt.topLevelScope.parameterDefinitions.length);
Expand Down Expand Up @@ -185,7 +185,7 @@ suite("DeploymentTemplate code lenses", () => {
test(testName, async () => {
let a = testName;
a = a;
const dt = await parseTemplate(template1);
const dt = parseTemplate(template1);
const param = dt.topLevelScope.getParameterDefinition(topLevelParamName);
assert(!!param);
const { dp } = await parseParametersWithMarkers(
Expand Down Expand Up @@ -286,7 +286,7 @@ suite("DeploymentTemplate code lenses", () => {
function createCodeLensTest(testName: string, template: IPartialDeploymentTemplate, expected: (string | RegExp)[]): void {
testWithLanguageServer(testName, async () => {
testName = testName;
const dt = await parseTemplate(template);
const dt = parseTemplate(template);

await ensureLanguageServerAvailable();

Expand Down
48 changes: 24 additions & 24 deletions test/DeploymentTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ suite("DeploymentTemplate", () => {
});

test("with one user function where function name matches a built-in function name", async () => {
await parseTemplate(
parseTemplate(
// tslint:disable-next-line:no-any
<IDeploymentTemplate><any>{
"name": "[contoso.reference()]", // This is not a call to the built-in "reference" function
Expand Down Expand Up @@ -413,7 +413,7 @@ suite("DeploymentTemplate", () => {
}
};

await parseTemplate(template, []);
parseTemplate(template, []);
});

test("with reference() call inside a different expression in a variable definition", () => {
Expand Down Expand Up @@ -1118,23 +1118,23 @@ ${err}`);
test("https://github.com/Microsoft/vscode-azurearmtools/issues/193", async () => {
// Just make sure nothing throws
let modifiedTemplate = template.replace('"type": "string"', '"type": string');
let dt = await parseTemplate(modifiedTemplate);
let dt = parseTemplate(modifiedTemplate);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
});

test("Unended string", async () => {
const json = "{ \"";
let dt = await parseTemplate(json);
let dt = parseTemplate(json);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
});

test("No top-level object", async () => {
const json = "\"hello\"";
let dt = await parseTemplate(json);
let dt = parseTemplate(json);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
Expand All @@ -1151,7 +1151,7 @@ ${err}`);
"subnetRef": "[concat(variables('vne2tId'), '/subnets/', parameters('subnetName'))]"
}
}`;
let dt = await parseTemplate(json);
let dt = parseTemplate(json);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
Expand All @@ -1168,7 +1168,7 @@ ${err}`);
"subnetRef": "[concat(variables('vne2tId'), '/subnets/', parameters('subnetName'))]"
}
}`;
let dt = await parseTemplate(json);
let dt = parseTemplate(json);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
Expand All @@ -1183,7 +1183,7 @@ ${err}`);
// Just make sure nothing throws
for (let i = 0; i < template.length; ++i) {
let partialTemplate = template.slice(0, i);
let dt = await parseTemplate(partialTemplate);
let dt = parseTemplate(partialTemplate);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
Expand All @@ -1201,7 +1201,7 @@ ${err}`);
// Just make sure nothing throws
for (let i = 0; i < template.length; ++i) {
let partialTemplate = template.slice(i);
let dt = await parseTemplate(partialTemplate);
let dt = parseTemplate(partialTemplate);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
Expand All @@ -1220,7 +1220,7 @@ ${err}`);
for (let i = 0; i < template.length; ++i) {
// Remove the single character at position i
let partialTemplate = template.slice(0, i) + template.slice(i + 1);
let dt = await parseTemplate(partialTemplate);
let dt = parseTemplate(partialTemplate);
findReferences(dt, DefinitionKind.Parameter, "adminUsername", dt.topLevelScope);
findReferences(dt, DefinitionKind.Variable, "resourceGroup", dt.topLevelScope);
dt.getFunctionCounts();
Expand Down Expand Up @@ -1265,13 +1265,13 @@ ${err}`);

let dt: DeploymentTemplateDoc;
try {
dt = await parseTemplate(modifiedTemplate);
dt = parseTemplate(modifiedTemplate);
} catch (err) {
if (parseError(err).message.includes('Malformed marker')) {
// We messed up the markers in the template (testcase issue). Revert this modification and try again
// next loop
modifiedTemplate = previousTemplate;
dt = await parseTemplate(modifiedTemplate);
dt = parseTemplate(modifiedTemplate);
} else {
// Valid failure
throw err;
Expand All @@ -1289,7 +1289,7 @@ ${err}`);

suite("getMultilineStringCount", () => {
test("TLE strings", async () => {
const dt = await parseTemplate(`{
const dt = parseTemplate(`{
"abc": "[abc
def]",
"xyz": "[xyz
Expand All @@ -1299,15 +1299,15 @@ ${err}`);
});

test("JSON strings", async () => {
const dt = await parseTemplate(`{
const dt = parseTemplate(`{
"abc": "abc
def"
}`);
assert.equal(dt.getMultilineStringCount(), 1);
});

test("don't count escaped \\n, \\r", async () => {
const dt = await parseTemplate(`{
const dt = parseTemplate(`{
"abc": "abc\\r\\ndef"
}`);
assert.equal(dt.getMultilineStringCount(), 0);
Expand All @@ -1317,7 +1317,7 @@ ${err}`);

suite("getMaxLineLength", () => {
test("getMaxLineLength", async () => {
const dt = await parseTemplate(`{
const dt = parseTemplate(`{
//345678
//345678901234567890
//345
Expand All @@ -1333,7 +1333,7 @@ ${err}`);
suite("getCommentsCount()", () => {
test("no comments", async () => {
// tslint:disable-next-line:no-any
const dt = await parseTemplate(<any>{
const dt = parseTemplate(<any>{
"$schema": "foo",
"contentVersion": "1.2.3 /*not a comment*/",
"whoever": "1.2.3 //not a comment"
Expand All @@ -1344,7 +1344,7 @@ ${err}`);

test("block comments", async () => {
// tslint:disable-next-line:no-any
const dt = await parseTemplate(`{
const dt = parseTemplate(`{
"$schema": "foo",
/* This is
a comment */
Expand All @@ -1357,7 +1357,7 @@ ${err}`);

test("single-line comments", async () => {
// tslint:disable-next-line:no-any
const dt = await parseTemplate(`{
const dt = parseTemplate(`{
"$schema": "foo", // This is a comment
"contentVersion": "1.2.3", // Another comment
"whoever": "1.2.3" // This is a comment
Expand All @@ -1369,14 +1369,14 @@ ${err}`);

suite("apiProfile", () => {
test("no apiProfile", async () => {
const dt = await parseTemplate({
const dt = parseTemplate({
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
});
assert.equal(dt.apiProfile, undefined);
});

test("empty apiProfile", async () => {
const dt = await parseTemplate({
const dt = parseTemplate({
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
apiProfile: ""
});
Expand All @@ -1386,7 +1386,7 @@ ${err}`);

test("non-string apiProfile", async () => {
// tslint:disable-next-line: no-any
const dt = await parseTemplate(<IDeploymentTemplate><any>{
const dt = parseTemplate(<IDeploymentTemplate><any>{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
apiProfile: false
});
Expand All @@ -1395,7 +1395,7 @@ ${err}`);
});

test("valid apiProfile", async () => {
const dt = await parseTemplate({
const dt = parseTemplate({
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"apiProfile": "2018–03-01-hybrid"
});
Expand All @@ -1407,7 +1407,7 @@ ${err}`);
suite("getDocumentPosition", () => {
function createGetDocumentPositionTest(json: string, index: number, expectedPosition: LineColPos): void {
test(`${JSON.stringify(json)}, index=${index}`, async () => {
const dt = await parseTemplate(json);
const dt = parseTemplate(json);
const pos: LineColPos = dt.getDocumentPosition(index);
assert.deepEqual(pos, expectedPosition);
});
Expand Down
Loading

0 comments on commit 416d38b

Please sign in to comment.