Debian Codegraph @

third_party/rust/glsl/tests/left_associativity.rs

raw
1 use glsl::parser::Parse;
2 use glsl::syntax;
3
4 #[test]
5 fn left_associativity() {
6 for (opstr, opname) in [
7 ("+", syntax::BinaryOp::Add),
8 ("&&", syntax::BinaryOp::And),
9 ("||", syntax::BinaryOp::Or),
10 ]
11 .iter()
12 {
13 let r = syntax::TranslationUnit::parse(format!(
14 "
15 void main() {{
16 x = a {op} b {op} c;
17 }}
18 ",
19 op = opstr
20 ));
21
22 let expected = syntax::TranslationUnit::from_non_empty_iter(vec![
23 syntax::ExternalDeclaration::FunctionDefinition(syntax::FunctionDefinition {
24 prototype: syntax::FunctionPrototype {
25 ty: syntax::FullySpecifiedType {
26 qualifier: None,
27 ty: syntax::TypeSpecifier {
28 ty: syntax::TypeSpecifierNonArray::Void,
29 array_specifier: None,
30 },
31 },
32 name: "main".into(),
33 parameters: Vec::new(),
34 },
35 statement: syntax::CompoundStatement {
36 statement_list: vec![syntax::Statement::Simple(Box::new(
37 syntax::SimpleStatement::Expression(Some(syntax::Expr::Assignment(
38 Box::new(syntax::Expr::Variable("x".into())),
39 syntax::AssignmentOp::Equal,
40 Box::new(syntax::Expr::Binary(
41 opname.clone(),
42 Box::new(syntax::Expr::Binary(
43 opname.clone(),
44 Box::new(syntax::Expr::Variable("a".into())),
45 Box::new(syntax::Expr::Variable("b".into())),
46 )),
47 Box::new(syntax::Expr::Variable("c".into())),
48 )),
49 ))),
50 ))],
51 },
52 }),
53 ])
54 .unwrap();
55
56 assert_eq!(r, Ok(expected));
57 }
58 }