Skip to content

Commit

Permalink
test: add unit test for float number
Browse files Browse the repository at this point in the history
  • Loading branch information
sbwtw committed Dec 16, 2023
1 parent 8e7d9ea commit 90bbcab
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl<'input> StLexer<'input> {
let mut s = String::from(ch);
let start_with_zero = ch == '0';

if start_with_zero {
if start_with_zero && self.buffer.peek1() != Some('.') {
tok.tok = Tok::Literal(LiteralValue::Bit(BitValue::Zero));
return Some(Ok(tok));
}
Expand Down Expand Up @@ -454,7 +454,7 @@ impl<'input> StLexer<'input> {
}
_ => {
tok.length = s.len();
tok.tok = Tok::Literal(LiteralValue::Real(s.parse().unwrap()));
tok.tok = Tok::Literal(LiteralValue::LReal(s));
return Some(Ok(tok));
}
}
Expand Down Expand Up @@ -846,4 +846,15 @@ mod test {
Tok::AssignRight
));
}

#[test]
fn test_numbers() {
let s = "0.123";
let mut lexer = StLexerBuilder::new().build_str(s);

let x = lexer.next().unwrap().unwrap();
assert_eq!(x.pos.offset, 0);
assert_eq!(x.length, 5);
assert!(matches!(x.tok, Tok::Literal(LiteralValue::LReal(_))));
}
}

0 comments on commit 90bbcab

Please sign in to comment.