/
formatter_test.ts
84 lines (78 loc) · 1.76 KB
/
formatter_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { sortImports } from "./formatter";
import { assertThat, eq } from "@selfage/test_matcher";
import { TEST_RUNNER } from "@selfage/test_runner";
TEST_RUNNER.run({
name: "FormatterTest",
cases: [
{
name: "SortWithCommentsAndClassAndLaterImports",
execute: () => {
// Execute
let content = sortImports("./test_data/formatter/imports_with_body.ts");
// Verify
assertThat(
content,
eq(`// Comment0
// Comment10
// Comment12
// Comment 11
// Comment1
// comment 2
import ts = require('ts');
import ts = require('typescript');
import a from 'a';
import b from 'b';
import c from 'c';
import ts from 'typescript';
import tss from 'typescripttypescript';
import * as ts from 'typescript';
import * as tss from 'typescripttypescript';
import { TestColor2 as TestColor,TestObject,TestObjectObject } from './test_interface';
import { TestObject } from './test_interface/ts';
import { a,b,d,e,f,g,i,z } from 'alphbet';
import 'ts';
import 'tsts';
// Comment 3
class X {
}
import fs = require('fs');
`),
"content",
);
},
},
{
name: "SortImportsOnly",
execute: () => {
// Execute
let content = sortImports("./test_data/formatter/imports_only.ts");
// Verify
assertThat(
content,
eq(`// Comment 1
// Comment 10
import { ast,bba } from './typescript';
import './side_effect';
`),
"content",
);
},
},
{
name: "SortNoImports",
execute: () => {
// Execute
let content = sortImports("./test_data/formatter/no_imports.ts");
// Verify
assertThat(
content,
eq(`class A {
public a = 10;
}
`),
"content",
);
},
},
],
});