From 4772e170c013ec176aab691722ee61903ac1c1ed Mon Sep 17 00:00:00 2001 From: Andrei Matveiakin Date: Tue, 27 Feb 2024 19:48:20 +0400 Subject: [PATCH] More exponent tests for float_literal_trailing_zero option --- src/expr.rs | 15 ++++++++++++++ .../float_literal_trailing_zero/always.rs | 20 ++++++++++++------- .../if-no-postfix.rs | 20 ++++++++++++------- .../float_literal_trailing_zero/never.rs | 20 ++++++++++++------- .../float_literal_trailing_zero/always.rs | 20 ++++++++++++------- .../if-no-postfix.rs | 20 ++++++++++++------- .../float_literal_trailing_zero/never.rs | 20 ++++++++++++------- .../float_literal_trailing_zero/preserve.rs | 20 ++++++++++++------- 8 files changed, 106 insertions(+), 49 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 6e91c03bb12..f09bd58fd9a 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2346,11 +2346,26 @@ mod test { assert_eq!(parts.fractional_part, Some("456")); assert_eq!(parts.exponent, Some("e789")); + let parts = parse_float_symbol("123.456e+789"); + assert_eq!(parts.integer_part, "123"); + assert_eq!(parts.fractional_part, Some("456")); + assert_eq!(parts.exponent, Some("e+789")); + + let parts = parse_float_symbol("123.456e-789"); + assert_eq!(parts.integer_part, "123"); + assert_eq!(parts.fractional_part, Some("456")); + assert_eq!(parts.exponent, Some("e-789")); + let parts = parse_float_symbol("123e789"); assert_eq!(parts.integer_part, "123"); assert_eq!(parts.fractional_part, None); assert_eq!(parts.exponent, Some("e789")); + let parts = parse_float_symbol("123E789"); + assert_eq!(parts.integer_part, "123"); + assert_eq!(parts.fractional_part, None); + assert_eq!(parts.exponent, Some("E789")); + let parts = parse_float_symbol("123."); assert_eq!(parts.integer_part, "123"); assert_eq!(parts.fractional_part, None); diff --git a/tests/source/configs/float_literal_trailing_zero/always.rs b/tests/source/configs/float_literal_trailing_zero/always.rs index b63bc1091c6..aa5f84a9eaa 100644 --- a/tests/source/configs/float_literal_trailing_zero/always.rs +++ b/tests/source/configs/float_literal_trailing_zero/always.rs @@ -7,13 +7,19 @@ fn float_literals() { let d = 100.0; let e = 5e3; let f = 5.0e3; - let g = 7f32; - let h = 7.0f32; - let i = 9e3f32; - let j = 9.0e3f32; - let k = 1000.00; - let l = 1_000_.; - let m = 1_000_.000_000; + let g = 5e+3; + let h = 5.0e+3; + let i = 5e-3; + let j = 5.0e-3; + let k = 5E3; + let l = 5.0E3; + let m = 7f32; + let n = 7.0f32; + let o = 9e3f32; + let p = 9.0e3f32; + let q = 1000.00; + let r = 1_000_.; + let s = 1_000_.000_000; } fn line_wrapping() { diff --git a/tests/source/configs/float_literal_trailing_zero/if-no-postfix.rs b/tests/source/configs/float_literal_trailing_zero/if-no-postfix.rs index d47e336c628..be8af142af8 100644 --- a/tests/source/configs/float_literal_trailing_zero/if-no-postfix.rs +++ b/tests/source/configs/float_literal_trailing_zero/if-no-postfix.rs @@ -7,13 +7,19 @@ fn float_literals() { let d = 100.0; let e = 5e3; let f = 5.0e3; - let g = 7f32; - let h = 7.0f32; - let i = 9e3f32; - let j = 9.0e3f32; - let k = 1000.00; - let l = 1_000_.; - let m = 1_000_.000_000; + let g = 5e+3; + let h = 5.0e+3; + let i = 5e-3; + let j = 5.0e-3; + let k = 5E3; + let l = 5.0E3; + let m = 7f32; + let n = 7.0f32; + let o = 9e3f32; + let p = 9.0e3f32; + let q = 1000.00; + let r = 1_000_.; + let s = 1_000_.000_000; } fn line_wrapping() { diff --git a/tests/source/configs/float_literal_trailing_zero/never.rs b/tests/source/configs/float_literal_trailing_zero/never.rs index 22b599b007d..afd99dd0ac3 100644 --- a/tests/source/configs/float_literal_trailing_zero/never.rs +++ b/tests/source/configs/float_literal_trailing_zero/never.rs @@ -7,13 +7,19 @@ fn float_literals() { let d = 100.0; let e = 5e3; let f = 5.0e3; - let g = 7f32; - let h = 7.0f32; - let i = 9e3f32; - let j = 9.0e3f32; - let k = 1000.00; - let l = 1_000_.; - let m = 1_000_.000_000; + let g = 5e+3; + let h = 5.0e+3; + let i = 5e-3; + let j = 5.0e-3; + let k = 5E3; + let l = 5.0E3; + let m = 7f32; + let n = 7.0f32; + let o = 9e3f32; + let p = 9.0e3f32; + let q = 1000.00; + let r = 1_000_.; + let s = 1_000_.000_000; } fn line_wrapping() { diff --git a/tests/target/configs/float_literal_trailing_zero/always.rs b/tests/target/configs/float_literal_trailing_zero/always.rs index e25f032c717..4205db675a4 100644 --- a/tests/target/configs/float_literal_trailing_zero/always.rs +++ b/tests/target/configs/float_literal_trailing_zero/always.rs @@ -7,13 +7,19 @@ fn float_literals() { let d = 100.0; let e = 5.0e3; let f = 5.0e3; - let g = 7.0f32; - let h = 7.0f32; - let i = 9.0e3f32; - let j = 9.0e3f32; - let k = 1000.00; - let l = 1_000_.0; - let m = 1_000_.000_000; + let g = 5.0e+3; + let h = 5.0e+3; + let i = 5.0e-3; + let j = 5.0e-3; + let k = 5.0E3; + let l = 5.0E3; + let m = 7.0f32; + let n = 7.0f32; + let o = 9.0e3f32; + let p = 9.0e3f32; + let q = 1000.00; + let r = 1_000_.0; + let s = 1_000_.000_000; } fn line_wrapping() { diff --git a/tests/target/configs/float_literal_trailing_zero/if-no-postfix.rs b/tests/target/configs/float_literal_trailing_zero/if-no-postfix.rs index caf33ed6353..b534fa88593 100644 --- a/tests/target/configs/float_literal_trailing_zero/if-no-postfix.rs +++ b/tests/target/configs/float_literal_trailing_zero/if-no-postfix.rs @@ -7,13 +7,19 @@ fn float_literals() { let d = 100.0; let e = 5e3; let f = 5e3; - let g = 7f32; - let h = 7f32; - let i = 9e3f32; - let j = 9e3f32; - let k = 1000.00; - let l = 1_000_.0; - let m = 1_000_.000_000; + let g = 5e+3; + let h = 5e+3; + let i = 5e-3; + let j = 5e-3; + let k = 5E3; + let l = 5E3; + let m = 7f32; + let n = 7f32; + let o = 9e3f32; + let p = 9e3f32; + let q = 1000.00; + let r = 1_000_.0; + let s = 1_000_.000_000; } fn line_wrapping() { diff --git a/tests/target/configs/float_literal_trailing_zero/never.rs b/tests/target/configs/float_literal_trailing_zero/never.rs index 085ddc49ba1..9b211b41d14 100644 --- a/tests/target/configs/float_literal_trailing_zero/never.rs +++ b/tests/target/configs/float_literal_trailing_zero/never.rs @@ -7,13 +7,19 @@ fn float_literals() { let d = 100.; let e = 5e3; let f = 5e3; - let g = 7f32; - let h = 7f32; - let i = 9e3f32; - let j = 9e3f32; - let k = 1000.; - let l = 1_000_.; - let m = 1_000_.; + let g = 5e+3; + let h = 5e+3; + let i = 5e-3; + let j = 5e-3; + let k = 5E3; + let l = 5E3; + let m = 7f32; + let n = 7f32; + let o = 9e3f32; + let p = 9e3f32; + let q = 1000.; + let r = 1_000_.; + let s = 1_000_.; } fn line_wrapping() { diff --git a/tests/target/configs/float_literal_trailing_zero/preserve.rs b/tests/target/configs/float_literal_trailing_zero/preserve.rs index 971443ad1e2..17c3941f342 100644 --- a/tests/target/configs/float_literal_trailing_zero/preserve.rs +++ b/tests/target/configs/float_literal_trailing_zero/preserve.rs @@ -7,11 +7,17 @@ fn float_literals() { let d = 100.0; let e = 5e3; let f = 5.0e3; - let g = 7f32; - let h = 7.0f32; - let i = 9e3f32; - let j = 9.0e3f32; - let k = 1000.00; - let l = 1_000_.; - let m = 1_000_.000_000; + let g = 5e+3; + let h = 5.0e+3; + let i = 5e-3; + let j = 5.0e-3; + let k = 5E3; + let l = 5.0E3; + let m = 7f32; + let n = 7.0f32; + let o = 9e3f32; + let p = 9.0e3f32; + let q = 1000.00; + let r = 1_000_.; + let s = 1_000_.000_000; }