test(linter): add fixer test for unicorn/no-zero-fractions (#4783)

Add fixer test.
Some of them have not passed yet, so I have temporarily made comments as
todo.
This commit is contained in:
heygsc 2024-08-09 21:16:24 +08:00 committed by GitHub
parent c3c5766601
commit 4dd29dbc2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -134,5 +134,35 @@ fn test() {
r"function foo(){return.0+.1}",
];
Tester::new(NoZeroFractions::NAME, pass, fail).test_and_snapshot();
let fix = vec![
(r"const foo = 1.0", r"const foo = 1"),
(r"const foo = 1.0 + 1", r"const foo = 1 + 1"),
(r"foo(1.0 + 1)", r"foo(1 + 1)"),
(r"const foo = 1.00", r"const foo = 1"),
(r"const foo = 1.00000", r"const foo = 1"),
(r"const foo = -1.0", r"const foo = -1"),
(r"const foo = 123123123.0", r"const foo = 123123123"),
(r"const foo = 123.11100000000", r"const foo = 123.111"),
(r"const foo = 1.", r"const foo = 1"),
(r"const foo = +1.", r"const foo = +1"),
(r"const foo = -1.", r"const foo = -1"),
// maybe todo
// In the following tests, the comments did not pass the fixer.
// (r"const foo = 1.e10", r"const foo = 1e10"),
// (r"const foo = +1.e-10", r"const foo = +1e-10"),
// (r"const foo = -1.e+10", r"const foo = -1e+10"),
(r"const foo = (1.).toString()", r"const foo = (1).toString()"),
// (r"1.00.toFixed(2)", r"(1).toFixed(2)"),
// (r"1.00 .toFixed(2)", r"(1) .toFixed(2)"),
(r"(1.00).toFixed(2)", r"(1).toFixed(2)"),
// (r"1.00?.toFixed(2)", r"(1)?.toFixed(2)"),
(r"a = .0;", r"a = 0;"),
// (r"a = .0.toString()", r"a = (0).toString()"),
// (r"function foo(){return.0}", r"function foo(){return 0}"),
// (r"function foo(){return.0.toString()}", r"function foo(){return (0).toString()}"),
// (r"function foo(){return.0+.1}", r"function foo(){return 0+.1}"),
];
Tester::new(NoZeroFractions::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}