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

Function number_values

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

Source from the content-addressed store, hash-verified

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