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

Function number_values

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

Source from the content-addressed store, hash-verified

73
74#[test]
75fn number_values() {
76 let cases = [
77 ("1E400", Number::Float(f64::INFINITY)),
78 (
79 "1E400J",
80 Number::Complex {
81 real: 0.0,
82 imag: f64::INFINITY,
83 },
84 ),
85 (
86 "123_456_789_123_456_789_123_456_789_123_456_789",
87 Number::Int("123456789123456789123456789123456789".parse().unwrap()),
88 ),
89 (
90 "000_123_456_789_123_456_789_123_456_789_123_456_789J",
91 Number::Complex {
92 real: 0.0,
93 imag: 1.234_567_891_234_567_8e35,
94 },
95 ),
96 ];
97
98 for (source, expected) in cases {
99 let parsed = parse_expression(source).unwrap();
100 let Expr::NumberLiteral(number) = parsed.expr() else {
101 panic!(
102 "expected number expression for {source:?}, got {:?}",
103 parsed.expr()
104 );
105 };
106
107 assert_eq!(number.value, expected, "source: {source:?}");
108 }
109}
110
111#[test]
112fn 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