summaryrefslogtreecommitdiffstats
path: root/third_party/rust/glsl/tests/left_associativity.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/glsl/tests/left_associativity.rs')
-rw-r--r--third_party/rust/glsl/tests/left_associativity.rs58
1 files changed, 58 insertions, 0 deletions
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));
+ }
+}