Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[naga wgsl-in] Test hex float suffix handling corner case. #4745

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions naga/src/front/wgsl/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl<'a> Lexer<'a> {
}

#[cfg(test)]
#[track_caller]
fn sub_test(source: &str, expected_tokens: &[Token]) {
let mut lex = Lexer::new(source);
for &token in expected_tokens {
Expand Down Expand Up @@ -674,6 +675,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.0 + 0x2f as f32 / 256.0))),
Token::Number(Ok(Number::F32(1.0 + 0x2f as f32 / 256.0))),
Token::Number(Ok(Number::F32(1.125))),
Token::Word("h"),
Token::Number(Ok(Number::F32(1.125))),
Token::Word("H"),
],
)
}

#[test]
Expand Down
Loading