Skip to content

Commit 28bf638

Browse files
committed
[naga wgsl-in] Test hex float suffix handling corner case.
Test Naga's WGSL front end's handling of `h` and `f` suffixes on hexadecimal float literals. WGSL permits these suffixes only if an exponent is present, because otherwise `f` suffixes can be confused with a hexadecimal digit.
1 parent 7246226 commit 28bf638

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

naga/src/front/wgsl/parse/lexer.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,22 @@ fn test_tokens() {
674674
Token::Operation('/'),
675675
],
676676
);
677+
678+
// Type suffixes are only allowed on hex float literals
679+
// if you provided an exponent.
680+
sub_test(
681+
"0x1.2f 0x1.2f 0x1.2h 0x1.2H",
682+
&[
683+
// The 'f' suffixes are taken as a hex digit:
684+
// the fractional part is 0x2f / 256.
685+
Token::Number(Ok(Number::F32(1.18359375))),
686+
Token::Number(Ok(Number::F32(1.18359375))),
687+
Token::Number(Ok(Number::F32(1.125))),
688+
Token::Word("h"),
689+
Token::Number(Ok(Number::F32(1.125))),
690+
Token::Word("H"),
691+
],
692+
)
677693
}
678694

679695
#[test]

0 commit comments

Comments
 (0)