From 9df9eec99cb72b6060954d4fece6d6522d188f23 Mon Sep 17 00:00:00 2001 From: Nigma Liu Date: Thu, 6 May 2021 09:16:10 +0800 Subject: [PATCH 1/5] Test the configuration update --- extension/src/test/suite/ConfigTest.test.ts | 337 ++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 extension/src/test/suite/ConfigTest.test.ts diff --git a/extension/src/test/suite/ConfigTest.test.ts b/extension/src/test/suite/ConfigTest.test.ts new file mode 100644 index 00000000..ba7b0203 --- /dev/null +++ b/extension/src/test/suite/ConfigTest.test.ts @@ -0,0 +1,337 @@ + +import * as chai from 'chai'; +import * as fs from 'fs' +import * as path from 'path'; +import * as vscode from 'vscode'; +import { before, beforeEach, after } from 'mocha'; +import { LispFormatter } from '../../format/formatter'; +import { ReadonlyDocument } from '../../project/readOnlyDocument'; +import { readFile2TextDocument } from '../suite/helper'; +let assert = chai.assert; +let testDir = path.join(__dirname + "/../../../extension/src/test"); +const outputDir = path.join(testDir + "/OutputFile"); +let config = vscode.workspace.getConfiguration("autolispext"); + +async function restoreConfig() { + try { + await config.update('format.CloseParenthesisStyle','New line with outer identation',true); + await config.update('format.MaxLineChars',85,true); + await config.update('format.LongListFormatStyle','Fill to Margin',true); + await config.update('format.NarrowStyleIndent',2,true); + } catch (error) { + console.log(error); + } + +} + +async function setClosedParenInSameLine(sameline : string){ + await config.update('format.CloseParenthesisStyle',sameline,true); +} +async function setMaxLineChars(maxchar : number){ + await config.update('format.MaxLineChars',maxchar,true); +} +async function setLongListFormat(singleCol : string){ + await config.update('format.LongListFormatStyle',singleCol,true); +} +async function setIndentSpaces(indent : number){ + await config.update('format.NarrowStyleIndent',indent,true); +} + +fs.mkdir(outputDir, { recursive: true }, (err) => { + if (err) { + return console.error(err); + } +}); + +function getFileName(i: number) { + const source = path.join(testDir + "/SourceFile/unFormatted" + i + ".lsp"); + const output = path.join(testDir + "/OutputFile/formatedOutputFile" + i + ".lsp"); + const baseline = path.join(testDir + "/Baseline/formatedBasefile" + i + ".lsp"); + return [source, output,baseline]; +} +function comparefileSync(i : number, output : string,fmt : string, baseline : string) { + try { + fs.writeFileSync(output,fmt); + let baseString = fs.readFileSync(baseline, { encoding: 'utf8', flag: 'r' }); + //Trick to pass the test is to ignore the \r + fmt = fmt.replace(/(\r)/gm, ""); + baseString = baseString.replace(/(\r)/gm, ""); + assert.isTrue(fmt === baseString); + } catch (err) { + assert.fail(`Format Test Case ${i} failed!`); + } +} + +suite.only("Lisp Formatter Tests", function () { + // Notes: + // Format test is a setting sensitive which depends on the format settings defined + // in the fmtconfig.ts + // The baseline is generated by the above default value: + // MaxLineChars: 85 + // NarrowStyleIndent: 2 + // CloseParenthesisStyle: 'New line with outer indentation' + // LongListFormatStyle: 'Fill to margin' + // Need to remove the \r to do the format output compare + after( async ()=>{ + await restoreConfig(); + }) + beforeEach(async () => { + await restoreConfig(); + }); + + test("Lisp Formatter Test case 1", async function () { + //Basic test case + let i = 1; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 2", async function () { + // Test setq in new lines + let i = 2; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 3", async function () { + // Test multiple functions format + let i = 3; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 4", async function () { + // The empty line should not be removed after format + let i = 4; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 5", async function () { + // Test the Max line chars setting + // Test the bug that it will be a space between the last two brackets ) ) + // MaxLineChars: 65 + let i = 5; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + await setMaxLineChars(65); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 6", async function () { + // Test the indent, the default indent should be 2 + let i = 6; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 7", async function () { + // Test the single column setting + let i = 7; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + // set as wide single column format + await setLongListFormat('Single Column'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 8",async function () { + // Test another single column setting + let i = 8; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + // set as wide single column format + await setLongListFormat('Single Column'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 9", async function () { + // Test list format which comes from an old bug + // This is a bug needs to be fixed in lisp extension + let i = 9; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 10", async function () { + // Test long list and big file - chinaMap.lsp + // This test will take long time + let i = 10; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 11",async function () { + // Test indent space setting + let i = 11; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(4); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 12",async function () { + // Test Closed Parenthesis In Same Line setting + let i = 12; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setClosedParenInSameLine('same line'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 13",async function () { + // Test Mixed settings + // MaxLineChars: 65 + // NarrowStyleIndent: 4 + // CloseParenthesisStyle: 'Same line' + // LongListFormatStyle: 'Single line' + let i = 13; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setClosedParenInSameLine('same line'); + await setIndentSpaces(4); + await setMaxLineChars(65); + await setLongListFormat('single column'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 14",async function () { + // Test the comments after the brackets ") ;progn" + // MaxLineChars: 80 + // NarrowStyleIndent: 4 + let i = 14; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(4); + await setMaxLineChars(80); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 15",async function () { + // Test unicode + // MaxLineChars: 60 + // NarrowStyleIndent: 2 + let i = 15; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(2); + await setMaxLineChars(60); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 16",async function () { + // Test invalid setting + // MaxLineChars: 30 + // NarrowStyleIndent: 8 + let i = 16; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(8); + await setMaxLineChars(30); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i,output,fmt,baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + +}); From 6df209410729e7232436c4b4657cacbdde20e627 Mon Sep 17 00:00:00 2001 From: Nigma Liu Date: Thu, 6 May 2021 09:24:51 +0800 Subject: [PATCH 2/5] using autolispext.format instead of format --- extension/src/test/suite/ConfigTest.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extension/src/test/suite/ConfigTest.test.ts b/extension/src/test/suite/ConfigTest.test.ts index ba7b0203..48b4c264 100644 --- a/extension/src/test/suite/ConfigTest.test.ts +++ b/extension/src/test/suite/ConfigTest.test.ts @@ -10,14 +10,14 @@ import { readFile2TextDocument } from '../suite/helper'; let assert = chai.assert; let testDir = path.join(__dirname + "/../../../extension/src/test"); const outputDir = path.join(testDir + "/OutputFile"); -let config = vscode.workspace.getConfiguration("autolispext"); +let config = vscode.workspace.getConfiguration(); async function restoreConfig() { try { - await config.update('format.CloseParenthesisStyle','New line with outer identation',true); - await config.update('format.MaxLineChars',85,true); - await config.update('format.LongListFormatStyle','Fill to Margin',true); - await config.update('format.NarrowStyleIndent',2,true); + await config.update('autolispext.format.CloseParenthesisStyle','New line with outer identation',true); + await config.update('autolispext.format.MaxLineChars',85,true); + await config.update('autolispext.format.LongListFormatStyle','Fill to Margin',true); + await config.update('autolispext.format.NarrowStyleIndent',2,true); } catch (error) { console.log(error); } @@ -25,16 +25,16 @@ async function restoreConfig() { } async function setClosedParenInSameLine(sameline : string){ - await config.update('format.CloseParenthesisStyle',sameline,true); + await config.update('autolispext.format.CloseParenthesisStyle',sameline,true); } async function setMaxLineChars(maxchar : number){ - await config.update('format.MaxLineChars',maxchar,true); + await config.update('autolispext.format.MaxLineChars',maxchar,true); } async function setLongListFormat(singleCol : string){ - await config.update('format.LongListFormatStyle',singleCol,true); + await config.update('autolispext.format.LongListFormatStyle',singleCol,true); } async function setIndentSpaces(indent : number){ - await config.update('format.NarrowStyleIndent',indent,true); + await config.update('autolispext.format.NarrowStyleIndent',indent,true); } fs.mkdir(outputDir, { recursive: true }, (err) => { From 40fe01813d295f73f9ee5eb4d8110371cfc49215 Mon Sep 17 00:00:00 2001 From: Nigma Liu Date: Fri, 7 May 2021 09:06:17 +0800 Subject: [PATCH 3/5] Correct the extensionDevelopmentPath --- .vscode/launch.json | 1 + extension/src/test/runTest.ts | 3 ++- extension/src/test/suite/ConfigTest.test.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 954f6c47..339705ed 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,6 +22,7 @@ "preLaunchTask": "buildproject", "runtimeExecutable": "${execPath}", "args": [ + "--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" ], diff --git a/extension/src/test/runTest.ts b/extension/src/test/runTest.ts index f0eacd55..995ce7ac 100644 --- a/extension/src/test/runTest.ts +++ b/extension/src/test/runTest.ts @@ -6,7 +6,8 @@ async function main() { try { // The folder containing the Extension Manifest package.json // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve(__dirname, '../../../../'); + // The __dirname is \AutoLispExt\out\test + const extensionDevelopmentPath = path.resolve(__dirname, '../../'); let extensionTestsPath =''; // The path to the extension test or code coverage script // Passed to --extensionTestsPath diff --git a/extension/src/test/suite/ConfigTest.test.ts b/extension/src/test/suite/ConfigTest.test.ts index 48b4c264..b177e2d4 100644 --- a/extension/src/test/suite/ConfigTest.test.ts +++ b/extension/src/test/suite/ConfigTest.test.ts @@ -62,7 +62,7 @@ function comparefileSync(i : number, output : string,fmt : string, baseline : st } } -suite.only("Lisp Formatter Tests", function () { +suite("Lisp Formatter Tests", function () { // Notes: // Format test is a setting sensitive which depends on the format settings defined // in the fmtconfig.ts From 7800513f31bef33f36c91b4ceb90647518885c6d Mon Sep 17 00:00:00 2001 From: Nigma Liu Date: Fri, 7 May 2021 09:28:31 +0800 Subject: [PATCH 4/5] Remove the mock method for formatter test --- extension/src/test/suite/ConfigTest.test.ts | 337 --------- extension/src/test/suite/Formatter.test.ts | 764 +++++++++----------- 2 files changed, 360 insertions(+), 741 deletions(-) delete mode 100644 extension/src/test/suite/ConfigTest.test.ts diff --git a/extension/src/test/suite/ConfigTest.test.ts b/extension/src/test/suite/ConfigTest.test.ts deleted file mode 100644 index b177e2d4..00000000 --- a/extension/src/test/suite/ConfigTest.test.ts +++ /dev/null @@ -1,337 +0,0 @@ - -import * as chai from 'chai'; -import * as fs from 'fs' -import * as path from 'path'; -import * as vscode from 'vscode'; -import { before, beforeEach, after } from 'mocha'; -import { LispFormatter } from '../../format/formatter'; -import { ReadonlyDocument } from '../../project/readOnlyDocument'; -import { readFile2TextDocument } from '../suite/helper'; -let assert = chai.assert; -let testDir = path.join(__dirname + "/../../../extension/src/test"); -const outputDir = path.join(testDir + "/OutputFile"); -let config = vscode.workspace.getConfiguration(); - -async function restoreConfig() { - try { - await config.update('autolispext.format.CloseParenthesisStyle','New line with outer identation',true); - await config.update('autolispext.format.MaxLineChars',85,true); - await config.update('autolispext.format.LongListFormatStyle','Fill to Margin',true); - await config.update('autolispext.format.NarrowStyleIndent',2,true); - } catch (error) { - console.log(error); - } - -} - -async function setClosedParenInSameLine(sameline : string){ - await config.update('autolispext.format.CloseParenthesisStyle',sameline,true); -} -async function setMaxLineChars(maxchar : number){ - await config.update('autolispext.format.MaxLineChars',maxchar,true); -} -async function setLongListFormat(singleCol : string){ - await config.update('autolispext.format.LongListFormatStyle',singleCol,true); -} -async function setIndentSpaces(indent : number){ - await config.update('autolispext.format.NarrowStyleIndent',indent,true); -} - -fs.mkdir(outputDir, { recursive: true }, (err) => { - if (err) { - return console.error(err); - } -}); - -function getFileName(i: number) { - const source = path.join(testDir + "/SourceFile/unFormatted" + i + ".lsp"); - const output = path.join(testDir + "/OutputFile/formatedOutputFile" + i + ".lsp"); - const baseline = path.join(testDir + "/Baseline/formatedBasefile" + i + ".lsp"); - return [source, output,baseline]; -} -function comparefileSync(i : number, output : string,fmt : string, baseline : string) { - try { - fs.writeFileSync(output,fmt); - let baseString = fs.readFileSync(baseline, { encoding: 'utf8', flag: 'r' }); - //Trick to pass the test is to ignore the \r - fmt = fmt.replace(/(\r)/gm, ""); - baseString = baseString.replace(/(\r)/gm, ""); - assert.isTrue(fmt === baseString); - } catch (err) { - assert.fail(`Format Test Case ${i} failed!`); - } -} - -suite("Lisp Formatter Tests", function () { - // Notes: - // Format test is a setting sensitive which depends on the format settings defined - // in the fmtconfig.ts - // The baseline is generated by the above default value: - // MaxLineChars: 85 - // NarrowStyleIndent: 2 - // CloseParenthesisStyle: 'New line with outer indentation' - // LongListFormatStyle: 'Fill to margin' - // Need to remove the \r to do the format output compare - after( async ()=>{ - await restoreConfig(); - }) - beforeEach(async () => { - await restoreConfig(); - }); - - test("Lisp Formatter Test case 1", async function () { - //Basic test case - let i = 1; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 2", async function () { - // Test setq in new lines - let i = 2; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 3", async function () { - // Test multiple functions format - let i = 3; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 4", async function () { - // The empty line should not be removed after format - let i = 4; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 5", async function () { - // Test the Max line chars setting - // Test the bug that it will be a space between the last two brackets ) ) - // MaxLineChars: 65 - let i = 5; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - await setMaxLineChars(65); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 6", async function () { - // Test the indent, the default indent should be 2 - let i = 6; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 7", async function () { - // Test the single column setting - let i = 7; - try { - const [source, output, baseline] = getFileName(i); - const doc = await readFile2TextDocument(source); - // set as wide single column format - await setLongListFormat('Single Column'); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 8",async function () { - // Test another single column setting - let i = 8; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - // set as wide single column format - await setLongListFormat('Single Column'); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 9", async function () { - // Test list format which comes from an old bug - // This is a bug needs to be fixed in lisp extension - let i = 9; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 10", async function () { - // Test long list and big file - chinaMap.lsp - // This test will take long time - let i = 10; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 11",async function () { - // Test indent space setting - let i = 11; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - await setIndentSpaces(4); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 12",async function () { - // Test Closed Parenthesis In Same Line setting - let i = 12; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - await setClosedParenInSameLine('same line'); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 13",async function () { - // Test Mixed settings - // MaxLineChars: 65 - // NarrowStyleIndent: 4 - // CloseParenthesisStyle: 'Same line' - // LongListFormatStyle: 'Single line' - let i = 13; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - await setClosedParenInSameLine('same line'); - await setIndentSpaces(4); - await setMaxLineChars(65); - await setLongListFormat('single column'); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 14",async function () { - // Test the comments after the brackets ") ;progn" - // MaxLineChars: 80 - // NarrowStyleIndent: 4 - let i = 14; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - await setIndentSpaces(4); - await setMaxLineChars(80); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 15",async function () { - // Test unicode - // MaxLineChars: 60 - // NarrowStyleIndent: 2 - let i = 15; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - await setIndentSpaces(2); - await setMaxLineChars(60); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 16",async function () { - // Test invalid setting - // MaxLineChars: 30 - // NarrowStyleIndent: 8 - let i = 16; - try { - const [source, output, baseline] = getFileName(i); - let doc = await readFile2TextDocument(source); - await setIndentSpaces(8); - await setMaxLineChars(30); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i,output,fmt,baseline); - } - catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - -}); diff --git a/extension/src/test/suite/Formatter.test.ts b/extension/src/test/suite/Formatter.test.ts index 6537ecd5..30daed19 100644 --- a/extension/src/test/suite/Formatter.test.ts +++ b/extension/src/test/suite/Formatter.test.ts @@ -1,430 +1,386 @@ -import * as chai from "chai"; -import * as fs from "fs"; -import * as path from "path"; -import { LispFormatter } from "../../format/formatter"; -import { ReadonlyDocument } from "../../project/readOnlyDocument"; -import * as fmtConfig from "../../format/fmtconfig"; -import { ImportMock } from "ts-mock-imports"; -import * as resources from "../../resources"; -import * as vscode from 'vscode'; +import * as chai from 'chai'; +import * as fs from 'fs' +import * as path from 'path'; +import * as vscode from 'vscode'; +import { beforeEach, after } from 'mocha'; +import { LispFormatter } from '../../format/formatter'; +import { readFile2TextDocument } from '../suite/helper'; let assert = chai.assert; let testDir = path.join(__dirname + "/../../../extension/src/test"); const outputDir = path.join(testDir + "/OutputFile"); +let config = vscode.workspace.getConfiguration('autolispext'); fs.mkdir(outputDir, { recursive: true }, (err) => { - if (err) { - return console.error(err); - } + if (err) { + return console.error(err); + } }); -function getFileName(i: number) { - const source = path.join(testDir + "/SourceFile/unFormatted" + i + ".lsp"); - const output = path.join( - testDir + "/OutputFile/formatedOutputFile" + i + ".lsp" - ); - const baseline = path.join( - testDir + "/Baseline/formatedBasefile" + i + ".lsp" - ); - return [source, output, baseline]; -} -function comparefileSync( - i: number, - output: string, - fmt: string, - baseline: string -) { - try { - fs.writeFileSync(output, fmt); - let baseString = fs.readFileSync(baseline, { encoding: "utf8", flag: "r" }); - //Trick to pass the test is to ignore the \r - fmt = fmt.replace(/(\r)/gm, ""); - baseString = baseString.replace(/(\r)/gm, ""); - assert.isTrue(fmt === baseString); - } catch (err) { - assert.fail(`Format Test Case ${i} failed!`); - } -} -// Notes: -// Format test is a setting sensitive which depends on the format settings defined -// in the fmtconfig.ts -// The baseline is generated by the above default value: -// MaxLineChars: 85 -// NarrowStyleIndent: 2 -// CloseParenthesisStyle: 'New line with outer indentation' -// LongListFormatStyle: 'Fill to margin' -// Need to remove the \r to do the format output compare -suite("Lisp Formatter mock Tests", function () { - let closeParenStyleStub; - let maximumLineCharsStub; - let longListFormatStyleStub; - let indentSpacesStub; - let internalLispFuncsStub; - let internalOperators; - - suiteSetup(() => { - let keyFile = path.join( - __dirname + "/../../../extension/data/alllispkeys.txt" - ); - internalOperators = fs.readFileSync(keyFile).toString().split("\r\n"); - internalLispFuncsStub = ImportMock.mockOther( - resources, - "internalLispFuncs", - internalOperators - ); - }); - - setup(()=>{ - resetDefault(); - }); - - suiteTeardown(() => { - internalLispFuncsStub.restore(); - closeParenStyleStub.restore(); - maximumLineCharsStub.restore(); - longListFormatStyleStub.restore(); - indentSpacesStub.restore(); - }); - - test("Lisp Formatter Test case 1", function () { - //Basic test case - let i = 1; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 2", function () { - // Test setq in new lines - let i = 2; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); - - test("Lisp Formatter Test case 3", function () { - // Test multiple functions format - let i = 3; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); +suite("Lisp Formatter Tests", function () { + // Notes: + // Format test is a setting sensitive which depends on the format settings defined + // in the fmtconfig.ts + // The baseline is generated by the above default value: + // MaxLineChars: 85 + // NarrowStyleIndent: 2 + // CloseParenthesisStyle: 'New line with outer indentation' + // LongListFormatStyle: 'Fill to margin' + // Need to remove the \r to do the format output compare + after(async () => { + await restoreConfig(); + }) + beforeEach(async () => { + await restoreConfig(); + }); - test("Lisp Formatter Test case 4", function () { - // The empty line should not be removed after format - let i = 4; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 1", async function () { + //Basic test case + let i = 1; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 5", async function () { - // Test the Max line chars setting - // Test the bug that it will be a space between the last two brackets ) ) - // MaxLineChars: 65 - let i = 5; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - setMaxLineChars(65); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 2", async function () { + // Test setq in new lines + let i = 2; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 6", function () { - // Test the indent, the default indent should be 2 - let i = 6; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 3", async function () { + // Test multiple functions format + let i = 3; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 7", async function () { - // Test the single column setting - let i = 7; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - // set as wide single column format - setLongListFormat("Single Column"); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 4", async function () { + // The empty line should not be removed after format + let i = 4; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 8", async function () { - // Test another single column setting - let i = 8; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - // set as wide single column format - setLongListFormat("Single Column"); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 5", async function () { + // Test the Max line chars setting + // Test the bug that it will be a space between the last two brackets ) ) + // MaxLineChars: 65 + let i = 5; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + await setMaxLineChars(65); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 9", function () { - // Test list format which comes from an old bug - // This is a bug needs to be fixed in lisp extension - let i = 9; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 6", async function () { + // Test the indent, the default indent should be 2 + let i = 6; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 10", function () { - // Test long list and big file - chinaMap.lsp - // This test will take long time - let i = 10; - this.timeout(20000); - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 7", async function () { + // Test the single column setting + let i = 7; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + // set as wide single column format + await setLongListFormat('Single Column'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 11", async function () { - // Test indent space setting - let i = 11; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - setIndentSpaces(4); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 8", async function () { + // Test another single column setting + let i = 8; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + // set as wide single column format + await setLongListFormat('Single Column'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 12", async function () { - // Test Closed Parenthesis In Same Line setting - let i = 12; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - setClosedParenInSameLine("same line"); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 9", async function () { + // Test list format which comes from an old bug + // This is a bug needs to be fixed in lisp extension + let i = 9; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 13", async function () { - // Test Mixed settings - // MaxLineChars: 65 - // NarrowStyleIndent: 4 - // CloseParenthesisStyle: 'Same line' - // LongListFormatStyle: 'Single line' - let i = 13; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - setClosedParenInSameLine("same line"); - setIndentSpaces(4); - setMaxLineChars(65); - setLongListFormat("single column"); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 10", async function () { + // Test long list and big file - chinaMap.lsp + // This test will take long time + let i = 10; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 14", async function () { - // Test the comments after the brackets ") ;progn" - // MaxLineChars: 80 - // NarrowStyleIndent: 4 - let i = 14; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - setIndentSpaces(4); - setMaxLineChars(80); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 11", async function () { + // Test indent space setting + let i = 11; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(4); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 15", async function () { - // Test unicode - // MaxLineChars: 60 - // NarrowStyleIndent: 2 - let i = 15; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - setIndentSpaces(2); - setMaxLineChars(60); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 12", async function () { + // Test Closed Parenthesis In Same Line setting + let i = 12; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setClosedParenInSameLine('same line'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 16", async function () { - // Test invalid setting - // MaxLineChars: 30 - // NarrowStyleIndent: 8 - let i = 16; - try { - const [source, output, baseline] = getFileName(i); - let doc = ReadonlyDocument.open(source); - setIndentSpaces(8); - setMaxLineChars(30); - let fmt = LispFormatter.format(doc, null); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 13", async function () { + // Test Mixed settings + // MaxLineChars: 65 + // NarrowStyleIndent: 4 + // CloseParenthesisStyle: 'Same line' + // LongListFormatStyle: 'Single line' + let i = 13; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setClosedParenInSameLine('same line'); + await setIndentSpaces(4); + await setMaxLineChars(65); + await setLongListFormat('single column'); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 17", function () { - //Test format selection - let i = 17; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let anchor = new vscode.Position(4,2); - let active = new vscode.Position(20,4); - let selectedRange = new vscode.Selection(anchor,active); - let fmt = LispFormatter.format(doc, selectedRange); - fmt = doc.getText().replace(doc.getText(selectedRange),fmt); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 14", async function () { + // Test the comments after the brackets ") ;progn" + // MaxLineChars: 80 + // NarrowStyleIndent: 4 + let i = 14; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(4); + await setMaxLineChars(80); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 18", function () { - //Test format selection - inverse selection - let i = 18; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let anchor = new vscode.Position(11,12); - let active = new vscode.Position(4,4); - let selectedRange = new vscode.Selection(anchor,active); - let fmt = LispFormatter.format(doc, selectedRange); - fmt = doc.getText().replace(doc.getText(selectedRange),fmt); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 15", async function () { + // Test unicode + // MaxLineChars: 60 + // NarrowStyleIndent: 2 + let i = 15; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(2); + await setMaxLineChars(60); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - test("Lisp Formatter Test case 19", function () { - //Test format selection - plus some format setting - let i = 19; - try { - const [source, output, baseline] = getFileName(i); - const doc = ReadonlyDocument.open(source); - let anchor = new vscode.Position(7,6); - let active = new vscode.Position(16,2); - let selectedRange = new vscode.Selection(anchor,active); - setClosedParenInSameLine("same line"); - setIndentSpaces(4); - setMaxLineChars(65); - setLongListFormat("single column"); - let fmt = LispFormatter.format(doc, selectedRange); - fmt = doc.getText().replace(doc.getText(selectedRange),fmt); - comparefileSync(i, output, fmt, baseline); - } catch (err) { - assert.fail(`The lisp format test case ${i} failed`); - } - }); + test("Lisp Formatter Test case 16", async function () { + // Test invalid setting + // MaxLineChars: 30 + // NarrowStyleIndent: 8 + let i = 16; + try { + const [source, output, baseline] = getFileName(i); + let doc = await readFile2TextDocument(source); + await setIndentSpaces(8); + await setMaxLineChars(30); + let fmt = LispFormatter.format(doc, null); + comparefileSync(i, output, fmt, baseline); + } + catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); - function setIndentSpaces(indent: number) { - if (indentSpacesStub) { - indentSpacesStub.restore(); - } - indentSpacesStub = ImportMock.mockFunction( - fmtConfig, - "indentSpaces", - indent - ); - } - function setClosedParenInSameLine(closeParenStyle: string) { - if (closeParenStyleStub) { - closeParenStyleStub.restore(); - } - closeParenStyleStub = ImportMock.mockFunction( - fmtConfig, - "closeParenStyle", - closeParenStyle - ); - } - function setMaxLineChars(maxchar: number) { - if (maximumLineCharsStub) { - maximumLineCharsStub.restore(); - } - maximumLineCharsStub = ImportMock.mockFunction( - fmtConfig, - "maximumLineChars", - maxchar - ); - } - function setLongListFormat(LongListFormat: string) { - if (longListFormatStyleStub) { - longListFormatStyleStub.restore(); - } - longListFormatStyleStub = ImportMock.mockFunction( - fmtConfig, - "longListFormatStyle", - LongListFormat - ); - } - function resetDefault(){ - setClosedParenInSameLine('New line with outer indentation'); - setMaxLineChars(85); - setLongListFormat('Fill to margin'); - setIndentSpaces(2); - } + test("Lisp Formatter Test case 17", async function () { + //Test format selection + let i = 17; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let anchor = new vscode.Position(4,2); + let active = new vscode.Position(20,4); + let selectedRange = new vscode.Selection(anchor,active); + let fmt = LispFormatter.format(doc, selectedRange); + fmt = doc.getText().replace(doc.getText(selectedRange),fmt); + comparefileSync(i, output, fmt, baseline); + } catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 18", async function () { + //Test format selection - inverse selection + let i = 18; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let anchor = new vscode.Position(11,12); + let active = new vscode.Position(4,4); + let selectedRange = new vscode.Selection(anchor,active); + let fmt = LispFormatter.format(doc, selectedRange); + fmt = doc.getText().replace(doc.getText(selectedRange),fmt); + comparefileSync(i, output, fmt, baseline); + } catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + + test("Lisp Formatter Test case 19", async function () { + //Test format selection - plus some format setting + let i = 19; + try { + const [source, output, baseline] = getFileName(i); + const doc = await readFile2TextDocument(source); + let anchor = new vscode.Position(7,6); + let active = new vscode.Position(16,2); + let selectedRange = new vscode.Selection(anchor,active); + await setClosedParenInSameLine("same line"); + await setIndentSpaces(4); + await setMaxLineChars(65); + await setLongListFormat("single column"); + let fmt = LispFormatter.format(doc, selectedRange); + fmt = doc.getText().replace(doc.getText(selectedRange),fmt); + comparefileSync(i, output, fmt, baseline); + } catch (err) { + assert.fail(`The lisp format test case ${i} failed`); + } + }); + async function restoreConfig() { + try { + await config.update('format.CloseParenthesisStyle', 'New line with outer identation', true); + await config.update('format.MaxLineChars', 85, true); + await config.update('format.LongListFormatStyle', 'Fill to Margin', true); + await config.update('format.NarrowStyleIndent', 2, true); + } catch (error) { + console.log(error); + } + } + async function setClosedParenInSameLine(sameline: string) { + await config.update('format.CloseParenthesisStyle', sameline, true); + } + async function setMaxLineChars(maxchar: number) { + await config.update('format.MaxLineChars', maxchar, true); + } + async function setLongListFormat(singleCol: string) { + await config.update('format.LongListFormatStyle', singleCol, true); + } + async function setIndentSpaces(indent: number) { + await config.update('format.NarrowStyleIndent', indent, true); + } + function getFileName(i: number) { + const source = path.join(testDir + "/SourceFile/unFormatted" + i + ".lsp"); + const output = path.join(testDir + "/OutputFile/formatedOutputFile" + i + ".lsp"); + const baseline = path.join(testDir + "/Baseline/formatedBasefile" + i + ".lsp"); + return [source, output, baseline]; + } + function comparefileSync(i: number, output: string, fmt: string, baseline: string) { + try { + fs.writeFileSync(output, fmt); + let baseString = fs.readFileSync(baseline, { encoding: 'utf8', flag: 'r' }); + //Trick to pass the test is to ignore the \r + fmt = fmt.replace(/(\r)/gm, ""); + baseString = baseString.replace(/(\r)/gm, ""); + assert.isTrue(fmt === baseString); + } catch (err) { + assert.fail(`Format Test Case ${i} failed!`); + } + } }); From a3d850b038742f9bb0b1339e9c64f615cb9dd901 Mon Sep 17 00:00:00 2001 From: Nigma Liu Date: Fri, 7 May 2021 09:49:23 +0800 Subject: [PATCH 5/5] Add Semicolon --- extension/src/test/suite/Formatter.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/src/test/suite/Formatter.test.ts b/extension/src/test/suite/Formatter.test.ts index 30daed19..da18bf22 100644 --- a/extension/src/test/suite/Formatter.test.ts +++ b/extension/src/test/suite/Formatter.test.ts @@ -29,7 +29,7 @@ suite("Lisp Formatter Tests", function () { // Need to remove the \r to do the format output compare after(async () => { await restoreConfig(); - }) + }); beforeEach(async () => { await restoreConfig(); });