mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Allow underscores in integers and floats (#7759)
# Description This PR makes changes that allow underscores in numbers. Example: ```nu # allows underscores to be placed arbitrarily to enhance readability. let pi = 3.1415_9265_3589_793 # works with integers let num = 1_000_000_000_000 let fav_color = 0x68_9d_6a ```
This commit is contained in:
@ -64,6 +64,29 @@ pub fn parse_int() {
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn parse_int_with_underscores() {
|
||||
let engine_state = EngineState::new();
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
|
||||
let (block, err) = parse(&mut working_set, None, b"420_69_2023", true, &[]);
|
||||
|
||||
assert!(err.is_none());
|
||||
assert_eq!(block.len(), 1);
|
||||
let expressions = &block[0];
|
||||
assert_eq!(expressions.len(), 1);
|
||||
assert!(matches!(
|
||||
expressions[0],
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Int(420692023),
|
||||
..
|
||||
}
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn parse_binary_with_hex_format() {
|
||||
let engine_state = EngineState::new();
|
||||
|
Reference in New Issue
Block a user