MCPcopy Create free account
hub / github.com/astral-sh/ruff / number_values

Function number_values

crates/ruff_python_parser/src/parser/tests.rs:88–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86
87#[test]
88fn number_values() {
89 let cases = [
90 ("1E400", Number::Float(f64::INFINITY)),
91 (
92 "1E400J",
93 Number::Complex {
94 real: 0.0,
95 imag: f64::INFINITY,
96 },
97 ),
98 (
99 "123_456_789_123_456_789_123_456_789_123_456_789",
100 Number::Int("123456789123456789123456789123456789".parse().unwrap()),
101 ),
102 (
103 "000_123_456_789_123_456_789_123_456_789_123_456_789J",
104 Number::Complex {
105 real: 0.0,
106 imag: 1.234_567_891_234_567_8e35,
107 },
108 ),
109 ];
110
111 for (source, expected) in cases {
112 let parsed = parse_expression(source).unwrap();
113 let Expr::NumberLiteral(number) = parsed.expr() else {
114 panic!(
115 "expected number expression for {source:?}, got {:?}",
116 parsed.expr()
117 );
118 };
119
120 assert_eq!(number.value, expected, "source: {source:?}");
121 }
122}
123
124#[test]
125fn malformed_radix_literals() {

Callers

nothing calls this directly

Calls 5

parse_expressionFunction · 0.85
FloatClass · 0.50
IntClass · 0.50
parseMethod · 0.45
exprMethod · 0.45

Tested by

no test coverage detected