-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot tests to formatter (#545)
* Add snapshot tests for formatter * Add test runner to CI --------- Co-authored-by: David Kincaid <[email protected]>
- Loading branch information
1 parent
ec1d9c3
commit 0a794eb
Showing
43 changed files
with
749 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,12 @@ name: Continuous integration | |
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
os: [macos-latest, ubuntu-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
@@ -13,9 +17,32 @@ jobs: | |
with: | ||
node-version: 16.x | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run headless test | ||
uses: coactions/setup-xvfb@v1 | ||
with: | ||
run: | | ||
npm run compile | ||
npm test | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Node.js | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Lint and build extension | ||
run: | | ||
npm install | ||
npm run lint | ||
npm run package -- --out godot-tools.vsix | ||
ls -l godot-tools.vsix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,41 @@ | ||
import * as assert from "assert"; | ||
import * as vscode from "vscode"; | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
|
||
import { format_document } from "./textmate"; | ||
|
||
import * as chai from "chai"; | ||
const expect = chai.expect; | ||
|
||
const dots = ["..", "..", ".."]; | ||
const basePath = path.join(__filename, ...dots); | ||
|
||
suite("GDScript Formatter Tests", () => { | ||
test("Test Formatting", async () => { | ||
const uri = vscode.Uri.file(path.join(basePath, "src/formatter/tests/test1.in.gd")); | ||
const document = await vscode.workspace.openTextDocument(uri); | ||
const edits = format_document(document); | ||
assert.strictEqual(4, edits.length); | ||
// Search for all folders in the snapshots folder and run a test for each | ||
// comparing the output of the formatter with the expected output. | ||
// To add a new test, create a new folder in the snapshots folder | ||
// and add two files, `in.gd` and `out.gd` for the input and expected output. | ||
const snapshotsFolderPath = path.join(basePath, "src/formatter/snapshots"); | ||
const testFolders = fs.readdirSync(snapshotsFolderPath); | ||
|
||
testFolders.forEach((testFolder) => { | ||
const testFolderPath = path.join(snapshotsFolderPath, testFolder); | ||
if (fs.statSync(testFolderPath).isDirectory()) { | ||
test(`Snapshot Test: ${testFolder}`, async () => { | ||
const uriIn = vscode.Uri.file(path.join(testFolderPath, "in.gd")); | ||
const uriOut = vscode.Uri.file(path.join(testFolderPath, "out.gd")); | ||
const documentIn = await vscode.workspace.openTextDocument(uriIn); | ||
const documentOut = await vscode.workspace.openTextDocument(uriOut); | ||
const edits = format_document(documentIn); | ||
|
||
// Apply the formatting edits | ||
const workspaceEdit = new vscode.WorkspaceEdit(); | ||
workspaceEdit.set(uriIn, edits); | ||
await vscode.workspace.applyEdit(workspaceEdit); | ||
|
||
// Compare the result with the expected output | ||
expect(documentIn.getText()).to.equal(documentOut.getText()); | ||
}); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var a = 1 | ||
var b = 2 | ||
|
||
func f(): | ||
a = a+b | ||
a = .1+ 2 | ||
a= 1. +2 | ||
a =1.0 + .2 | ||
a = 1.0+ 2. | ||
|
||
a =a -b | ||
a = .1- 2 | ||
a= 1.-2 | ||
a = 1.0 - .2 | ||
a =1.0- 2. | ||
|
||
a= a/ b | ||
a = .1 /2 | ||
a =1. /2 | ||
a = 1.0 / .2 | ||
a =1.0/2. | ||
|
||
a = a *b | ||
a=.1* 2 | ||
a = 1. *2 | ||
a= 1.0* .2 | ||
a =1.0 * 2. | ||
|
||
a= a% b | ||
a =1%2 | ||
|
||
a =-1 | ||
a= +1 | ||
|
||
a = ((-1 + 2) * (3-4) / 5 * 6%( -7 + 8-9 - 10)) * (- 11 + 12) / (13*14 % 15 +16) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var a = 1 | ||
var b = 2 | ||
|
||
func f(): | ||
a = a + b | ||
a = .1 + 2 | ||
a = 1. + 2 | ||
a = 1.0 + .2 | ||
a = 1.0 + 2. | ||
|
||
a = a - b | ||
a = .1 - 2 | ||
a = 1. - 2 | ||
a = 1.0 - .2 | ||
a = 1.0 - 2. | ||
|
||
a = a / b | ||
a = .1 / 2 | ||
a = 1. / 2 | ||
a = 1.0 / .2 | ||
a = 1.0 / 2. | ||
|
||
a = a * b | ||
a = .1 * 2 | ||
a = 1. * 2 | ||
a = 1.0 * .2 | ||
a = 1.0 * 2. | ||
|
||
a = a % b | ||
a = 1 % 2 | ||
|
||
a = -1 | ||
a = +1 | ||
|
||
a = ((-1 + 2) * (3 - 4) / 5 * 6 % (-7 + 8 - 9 - 10)) * (-11 + 12) / (13 * 14 % 15 + 16) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var primes = [2, 3, 5, 7, 11, 13, 17 ] | ||
var primes2 = [ | ||
2 , | ||
3 , | ||
5, | ||
7 , | ||
11 , | ||
13, | ||
17 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var primes = [2, 3, 5, 7, 11, 13, 17] | ||
var primes2 = [ | ||
2, | ||
3, | ||
5, | ||
7, | ||
11, | ||
13, | ||
17 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
func f(): | ||
assert (1!= 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
func f(): | ||
assert(1 != 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
func f(): | ||
await delay(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
func f(): | ||
await delay(10) |
Oops, something went wrong.