From a2cd094b55e63b7ca84d6cfc79c6caf4b000843e Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 24 Jan 2024 14:54:13 +0530 Subject: [PATCH] refactor(lexer): fix warnings by 'cargo clippy' for lexer Signed-off-by: Abhishek Kumar --- kclvm/lexer/src/number.rs | 2 +- kclvm/lexer/src/tests.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kclvm/lexer/src/number.rs b/kclvm/lexer/src/number.rs index f9f7d9ab2..0458b1fd1 100644 --- a/kclvm/lexer/src/number.rs +++ b/kclvm/lexer/src/number.rs @@ -66,7 +66,7 @@ impl<'a> Cursor<'a> { // with a number self.bump(); let mut empty_exponent = false; - if self.peek().is_digit(10) { + if self.peek().is_ascii_digit() { self.eat_decimal_digits(); match self.peek() { 'e' | 'E' => { diff --git a/kclvm/lexer/src/tests.rs b/kclvm/lexer/src/tests.rs index 2bd614658..511b49854 100644 --- a/kclvm/lexer/src/tests.rs +++ b/kclvm/lexer/src/tests.rs @@ -1,10 +1,13 @@ use super::*; use expect_test::{expect, Expect}; +use std::fmt::Write; fn check_lexing(src: &str, expect: Expect) { let actual: String = tokenize(src) - .map(|token| format!("{:?}\n", token)) - .collect(); + .fold(String::new(), |mut acc, token| { + writeln!(acc, "{:?}", token).expect("Failed to write to string"); + acc + }); expect.assert_eq(&actual) }