-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 💡 split formatter test into categories
- Loading branch information
Showing
32 changed files
with
6,031 additions
and
5,876 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, test } from "vitest"; | ||
import * as util from "../support/util"; | ||
|
||
describe("formatter alpine test", () => { | ||
test("shorthand binding #557", async () => { | ||
const content = [ | ||
`@section('body')`, | ||
` <forms.radios legend="Meeting Schedule" name="meeting_type" value="single" v-model="form.meeting_type"`, | ||
` :inline="true"`, | ||
` :options="[`, | ||
` 'single' => ['label' => 'Default'],`, | ||
` 'series' => ['label' => 'Recurring meeting'],`, | ||
` 'scheduler' => ['label' => 'Find a meeting date'],`, | ||
`]" />`, | ||
"@endsection", | ||
].join("\n"); | ||
|
||
const expected = [ | ||
`@section('body')`, | ||
` <forms.radios legend="Meeting Schedule" name="meeting_type" value="single" v-model="form.meeting_type"`, | ||
` :inline="true"`, | ||
` :options="[`, | ||
` 'single' => ['label' => 'Default'],`, | ||
` 'series' => ['label' => 'Recurring meeting'],`, | ||
` 'scheduler' => ['label' => 'Find a meeting date'],`, | ||
` ]" />`, | ||
"@endsection", | ||
"", | ||
].join("\n"); | ||
|
||
await util.doubleFormatCheck(content, expected); | ||
}); | ||
|
||
test("x-bind binding", async () => { | ||
const content = [ | ||
`<div x-bind:class="imageLoaded?'blur-none':'blur-3xl'">`, | ||
"</div>", | ||
].join("\n"); | ||
|
||
const expected = [ | ||
`<div x-bind:class="imageLoaded ? 'blur-none' : 'blur-3xl'">`, | ||
"</div>", | ||
"", | ||
].join("\n"); | ||
|
||
await util.doubleFormatCheck(content, expected); | ||
}); | ||
}); |
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,47 @@ | ||
import assert from "node:assert"; | ||
import { describe, test } from "vitest"; | ||
import { BladeFormatter } from "../../src/main.js"; | ||
|
||
describe("formatter api test", () => { | ||
test("format API", async () => { | ||
const content = [ | ||
"<table>", | ||
"<th><?= $userName ?></th>", | ||
"</table>", | ||
"", | ||
].join("\n"); | ||
|
||
const expected = [ | ||
"<table>", | ||
" <th><?= $userName ?></th>", | ||
"</table>", | ||
"", | ||
].join("\n"); | ||
|
||
return new BladeFormatter().format(content).then((result: any) => { | ||
assert.equal(result, expected); | ||
}); | ||
}); | ||
|
||
test("format API with option", async () => { | ||
const content = [ | ||
"<table>", | ||
"<th><?= $userName ?></th>", | ||
"</table>", | ||
"", | ||
].join("\n"); | ||
|
||
const expected = [ | ||
"<table>", | ||
" <th><?= $userName ?></th>", | ||
"</table>", | ||
"", | ||
].join("\n"); | ||
|
||
return new BladeFormatter({ indentSize: 2 }) | ||
.format(content) | ||
.then((result: any) => { | ||
assert.equal(result, expected); | ||
}); | ||
}); | ||
}); |
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,47 @@ | ||
import { describe, test } from "vitest"; | ||
import * as util from "../support/util"; | ||
|
||
describe("formatter attributes test", () => { | ||
test("empty class atrbitue", async () => { | ||
let content = [`<div class=""></div>`].join("\n"); | ||
let expected = [`<div class=""></div>`, ""].join("\n"); | ||
|
||
await util.doubleFormatCheck(content, expected); | ||
|
||
content = [ | ||
`<input class="" type="file" name="product_images[]" multiple /> | ||
`, | ||
].join("\n"); | ||
expected = [ | ||
`<input class="" type="file" name="product_images[]" multiple />`, | ||
"", | ||
].join("\n"); | ||
|
||
await util.doubleFormatCheck(content, expected); | ||
}); | ||
|
||
test("keep html attribute indentation", async () => { | ||
const content = [ | ||
`@component('some.file')`, | ||
" <div>", | ||
` <input type="text" an-object="{`, | ||
` 'Some error': 1,`, | ||
` }" />`, | ||
" </div>", | ||
"@endcomponent", | ||
].join("\n"); | ||
|
||
const expected = [ | ||
`@component('some.file')`, | ||
" <div>", | ||
` <input type="text" an-object="{`, | ||
` 'Some error': 1,`, | ||
` }" />`, | ||
" </div>", | ||
"@endcomponent", | ||
"", | ||
].join("\n"); | ||
|
||
await util.doubleFormatCheck(content, expected); | ||
}); | ||
}); |
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,44 @@ | ||
import assert from "node:assert"; | ||
import { describe, test } from "vitest"; | ||
import { Formatter } from "../../src/main.js"; | ||
|
||
const formatter = () => { | ||
return new Formatter({ indentSize: 4 }); | ||
}; | ||
|
||
describe("basic formatter test", () => { | ||
test("can format plain text", () => { | ||
const content = "aaa\n"; | ||
const expected = "aaa\n"; | ||
|
||
return formatter() | ||
.formatContent(content) | ||
.then((result: any) => { | ||
assert.equal(result, expected); | ||
}); | ||
}); | ||
|
||
test("outputs end with new line", () => { | ||
const content = "aaa"; | ||
const expected = "aaa\n"; | ||
|
||
return formatter() | ||
.formatContent(content) | ||
.then((result: any) => { | ||
assert.equal(result, expected); | ||
}); | ||
}); | ||
|
||
test("can format simple html tag", () => { | ||
const content = "<html><body></body></html>"; | ||
const expected = ["<html>", "", "<body></body>", "", "</html>", ""].join( | ||
"\n", | ||
); | ||
|
||
return formatter() | ||
.formatContent(content) | ||
.then((result: any) => { | ||
assert.equal(result, expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.