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

Function number_values

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

Source from the content-addressed store, hash-verified

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