From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/glsl/tests/incorrect_statement.rs | 19 +++++++ third_party/rust/glsl/tests/left_associativity.rs | 58 ++++++++++++++++++++++ third_party/rust/glsl/tests/missing_zero_float.rs | 28 +++++++++++ 3 files changed, 105 insertions(+) create mode 100644 third_party/rust/glsl/tests/incorrect_statement.rs create mode 100644 third_party/rust/glsl/tests/left_associativity.rs create mode 100644 third_party/rust/glsl/tests/missing_zero_float.rs (limited to 'third_party/rust/glsl/tests') diff --git a/third_party/rust/glsl/tests/incorrect_statement.rs b/third_party/rust/glsl/tests/incorrect_statement.rs new file mode 100644 index 0000000000..2e39a7f536 --- /dev/null +++ b/third_party/rust/glsl/tests/incorrect_statement.rs @@ -0,0 +1,19 @@ +use glsl::parser::Parse; +use glsl::syntax; + +#[test] +fn incorrect_statement() { + let r = syntax::TranslationUnit::parse( + " + int fetch_transform(int id) { + return id; + } + + bool ray_plane() { + if 1 { + } + ", + ); + + assert!(r.is_err()); +} diff --git a/third_party/rust/glsl/tests/left_associativity.rs b/third_party/rust/glsl/tests/left_associativity.rs new file mode 100644 index 0000000000..7e2a19cfb4 --- /dev/null +++ b/third_party/rust/glsl/tests/left_associativity.rs @@ -0,0 +1,58 @@ +use glsl::parser::Parse; +use glsl::syntax; + +#[test] +fn left_associativity() { + for (opstr, opname) in [ + ("+", syntax::BinaryOp::Add), + ("&&", syntax::BinaryOp::And), + ("||", syntax::BinaryOp::Or), + ] + .iter() + { + let r = syntax::TranslationUnit::parse(format!( + " + void main() {{ + x = a {op} b {op} c; + }} + ", + op = opstr + )); + + let expected = syntax::TranslationUnit::from_non_empty_iter(vec![ + syntax::ExternalDeclaration::FunctionDefinition(syntax::FunctionDefinition { + prototype: syntax::FunctionPrototype { + ty: syntax::FullySpecifiedType { + qualifier: None, + ty: syntax::TypeSpecifier { + ty: syntax::TypeSpecifierNonArray::Void, + array_specifier: None, + }, + }, + name: "main".into(), + parameters: Vec::new(), + }, + statement: syntax::CompoundStatement { + statement_list: vec![syntax::Statement::Simple(Box::new( + syntax::SimpleStatement::Expression(Some(syntax::Expr::Assignment( + Box::new(syntax::Expr::Variable("x".into())), + syntax::AssignmentOp::Equal, + Box::new(syntax::Expr::Binary( + opname.clone(), + Box::new(syntax::Expr::Binary( + opname.clone(), + Box::new(syntax::Expr::Variable("a".into())), + Box::new(syntax::Expr::Variable("b".into())), + )), + Box::new(syntax::Expr::Variable("c".into())), + )), + ))), + ))], + }, + }), + ]) + .unwrap(); + + assert_eq!(r, Ok(expected)); + } +} diff --git a/third_party/rust/glsl/tests/missing_zero_float.rs b/third_party/rust/glsl/tests/missing_zero_float.rs new file mode 100644 index 0000000000..35ad5cf761 --- /dev/null +++ b/third_party/rust/glsl/tests/missing_zero_float.rs @@ -0,0 +1,28 @@ +extern crate glsl; + +use glsl::parser::Parse; +use glsl::syntax::TranslationUnit; + +#[test] +fn missing_zero_float_is_valid() { + let r = TranslationUnit::parse( + " + void main() { + float x = 1. * .5; + }", + ); + + assert!(r.is_ok()); +} + +#[test] +fn float_exp_is_valid() { + let r = TranslationUnit::parse( + " + void main() { + float x = 1e-5; + }", + ); + + assert!(r.is_ok()); +} -- cgit v1.2.3