Skip to content

Commit

Permalink
test(linter): add fixer test for unicorn/no-zero-fractions (#4783)
Browse files Browse the repository at this point in the history
Add fixer test.
Some of them have not passed yet, so I have temporarily made comments as
todo.
  • Loading branch information
heygsc authored Aug 9, 2024
1 parent c3c5766 commit 4dd29db
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 4dd29db

Please sign in to comment.