Skip to content

Commit

Permalink
fix(linter): add tests for fixer of no-zero-fractions
Browse files Browse the repository at this point in the history
Adding tests for the fixer uncovered some bugs where it would produce
the wrong results or invalid JavaScript.

Related: oxc-project#4179
  • Loading branch information
jelly committed Jul 17, 2024
1 parent 96af459 commit ff72fcd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 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 @@ -137,5 +137,17 @@ fn test() {
r"function foo(){return.0+.1}",
];

Tester::new(NoZeroFractions::NAME, pass, fail).test_and_snapshot();
let fix = vec![
(r"a = .0.toString()", r"a = (0).toString()"),
(r"1.00.toFixed(2)", r"(1).toFixed(2)"),
(r"const foo = 1.", r"const foo = 1"),
(r"const foo = 123.11100000000", r"const foo = 123.111"),
(r"const foo = 1.00", r"const foo = 1"),
(r"const foo = -1.e+10", r"const foo = -1e+10"),
(r"const foo = 1.e10", r"const foo = 1e10"),
(r"const foo = .0", r"const foo = 0"),
(r"const foo = -1.0", r"const foo = -1"),
];

Tester::new(NoZeroFractions::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}

0 comments on commit ff72fcd

Please sign in to comment.