Skip to content

Commit

Permalink
fix(frontmatter-gen): 🐛 fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Nov 17, 2024
1 parent 6a25f82 commit 17f4d49
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ Content"#;
}

#[test]
fn test_numeric_values() {
let content = r#"---
fn test_numeric_values() {
let content = r#"---
integer: 42
float: 3.14
scientific: 1.23e-4
Expand All @@ -428,17 +428,41 @@ zero: 0
---
Content"#;

let (frontmatter, _) = extract(content).unwrap();
let (frontmatter, _) = extract(content).unwrap();

// Define a small margin of error for floating-point comparisons
let epsilon = 1e-6;
// Define a small margin of error for floating-point comparisons
let epsilon = 1e-6;

assert!((frontmatter.get("integer").unwrap().as_f64().unwrap() - 42.0).abs() < epsilon);
assert!((frontmatter.get("float").unwrap().as_f64().unwrap() - 3.14).abs() < epsilon); // Use 3.14 directly
assert!((frontmatter.get("scientific").unwrap().as_f64().unwrap() - 0.000123).abs() < epsilon);
assert!((frontmatter.get("negative").unwrap().as_f64().unwrap() - (-17.0)).abs() < epsilon);
assert!((frontmatter.get("zero").unwrap().as_f64().unwrap() - 0.0).abs() < epsilon);
}
assert!(
(frontmatter.get("integer").unwrap().as_f64().unwrap()
- 42.0)
.abs()
< epsilon
);
assert!(
(frontmatter.get("float").unwrap().as_f64().unwrap()
- 3.14)

Check failure on line 444 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Lint

approximate value of `f{32, 64}::consts::PI` found
.abs()
< epsilon
); // Use 3.14 directly
assert!(
(frontmatter.get("scientific").unwrap().as_f64().unwrap()
- 0.000123)
.abs()
< epsilon
);
assert!(
(frontmatter.get("negative").unwrap().as_f64().unwrap()
- (-17.0))
.abs()
< epsilon
);
assert!(
(frontmatter.get("zero").unwrap().as_f64().unwrap() - 0.0)
.abs()
< epsilon
);
}

#[test]
fn test_boolean_values() {
Expand Down

0 comments on commit 17f4d49

Please sign in to comment.