Skip to content

Commit

Permalink
[naga wgsl-in] Test hex float suffix handling corner case.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimblandy committed Nov 22, 2023
1 parent 7246226 commit 28bf638
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions naga/src/front/wgsl/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,22 @@ fn test_tokens() {
Token::Operation('/'),
],
);

// Type suffixes are only allowed on hex float literals
// if you provided an exponent.
sub_test(
"0x1.2f 0x1.2f 0x1.2h 0x1.2H",
&[
// The 'f' suffixes are taken as a hex digit:
// the fractional part is 0x2f / 256.
Token::Number(Ok(Number::F32(1.18359375))),
Token::Number(Ok(Number::F32(1.18359375))),
Token::Number(Ok(Number::F32(1.125))),
Token::Word("h"),
Token::Number(Ok(Number::F32(1.125))),
Token::Word("H"),
],
)
}

#[test]
Expand Down

0 comments on commit 28bf638

Please sign in to comment.