| 1 |
use crate::parsers::*; |
| 2 |
use crate::syntax; |
| 3 |
|
| 4 |
#[test] |
| 5 |
fn parse_uniline_comment() { |
| 6 |
assert_eq!(comment("// lol"), Ok(("", " lol"))); |
| 7 |
assert_eq!(comment("// lol\nfoo"), Ok(("foo", " lol"))); |
| 8 |
assert_eq!(comment("// lol\\\nfoo"), Ok(("", " lol\\\nfoo"))); |
| 9 |
assert_eq!( |
| 10 |
comment("// lol \\\n foo\n"), |
| 11 |
Ok(("", " lol \\\n foo")) |
| 12 |
); |
| 13 |
} |
| 14 |
|
| 15 |
#[test] |
| 16 |
fn parse_multiline_comment() { |
| 17 |
assert_eq!(comment("/* lol\nfoo\n*/bar"), Ok(("bar", " lol\nfoo\n"))); |
| 18 |
} |
| 19 |
|
| 20 |
#[test] |
| 21 |
fn parse_unsigned_suffix() { |
| 22 |
assert_eq!(unsigned_suffix("u"), Ok(("", 'u'))); |
| 23 |
assert_eq!(unsigned_suffix("U"), Ok(("", 'U'))); |
| 24 |
} |
| 25 |
|
| 26 |
#[test] |
| 27 |
fn parse_nonzero_digits() { |
| 28 |
assert_eq!(nonzero_digits("3"), Ok(("", "3"))); |
| 29 |
assert_eq!(nonzero_digits("12345953"), Ok(("", "12345953"))); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn parse_decimal_lit() { |
| 34 |
assert_eq!(decimal_lit("3"), Ok(("", Ok(3)))); |
| 35 |
assert_eq!(decimal_lit("3"), Ok(("", Ok(3)))); |
| 36 |
assert_eq!(decimal_lit("13"), Ok(("", Ok(13)))); |
| 37 |
assert_eq!(decimal_lit("42"), Ok(("", Ok(42)))); |
| 38 |
assert_eq!(decimal_lit("123456"), Ok(("", Ok(123456)))); |
| 39 |
} |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn parse_octal_lit() { |
| 43 |
assert_eq!(octal_lit("0"), Ok(("", Ok(0o0)))); |
| 44 |
assert_eq!(octal_lit("03 "), Ok((" ", Ok(0o3)))); |
| 45 |
assert_eq!(octal_lit("012 "), Ok((" ", Ok(0o12)))); |
| 46 |
assert_eq!(octal_lit("07654321 "), Ok((" ", Ok(0o7654321)))); |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
fn parse_hexadecimal_lit() { |
| 51 |
assert_eq!(hexadecimal_lit("0x3 "), Ok((" ", Ok(0x3)))); |
| 52 |
assert_eq!(hexadecimal_lit("0x0123789"), Ok(("", Ok(0x0123789)))); |
| 53 |
assert_eq!(hexadecimal_lit("0xABCDEF"), Ok(("", Ok(0xabcdef)))); |
| 54 |
assert_eq!(hexadecimal_lit("0xabcdef"), Ok(("", Ok(0xabcdef)))); |
| 55 |
} |
| 56 |
|
| 57 |
#[test] |
| 58 |
fn parse_integral_lit() { |
| 59 |
assert_eq!(integral_lit("0"), Ok(("", 0))); |
| 60 |
assert_eq!(integral_lit("3"), Ok(("", 3))); |
| 61 |
assert_eq!(integral_lit("3 "), Ok((" ", 3))); |
| 62 |
assert_eq!(integral_lit("03 "), Ok((" ", 3))); |
| 63 |
assert_eq!(integral_lit("076556 "), Ok((" ", 0o76556))); |
| 64 |
assert_eq!(integral_lit("012 "), Ok((" ", 0o12))); |
| 65 |
assert_eq!(integral_lit("0x3 "), Ok((" ", 0x3))); |
| 66 |
assert_eq!(integral_lit("0x9ABCDEF"), Ok(("", 0x9ABCDEF))); |
| 67 |
assert_eq!(integral_lit("0x9ABCDEF"), Ok(("", 0x9ABCDEF))); |
| 68 |
assert_eq!(integral_lit("0x9abcdef"), Ok(("", 0x9abcdef))); |
| 69 |
assert_eq!(integral_lit("0x9abcdef"), Ok(("", 0x9abcdef))); |
| 70 |
assert_eq!(integral_lit("0xffffffff"), Ok(("", 0xffffffffu32 as i32))); |
| 71 |
} |
| 72 |
|
| 73 |
#[test] |
| 74 |
fn parse_integral_neg_lit() { |
| 75 |
assert_eq!(integral_lit("-3"), Ok(("", -3))); |
| 76 |
assert_eq!(integral_lit("-3 "), Ok((" ", -3))); |
| 77 |
assert_eq!(integral_lit("-03 "), Ok((" ", -3))); |
| 78 |
assert_eq!(integral_lit("-076556 "), Ok((" ", -0o76556))); |
| 79 |
assert_eq!(integral_lit("-012 "), Ok((" ", -0o12))); |
| 80 |
assert_eq!(integral_lit("-0x3 "), Ok((" ", -0x3))); |
| 81 |
assert_eq!(integral_lit("-0x9ABCDEF"), Ok(("", -0x9ABCDEF))); |
| 82 |
assert_eq!(integral_lit("-0x9ABCDEF"), Ok(("", -0x9ABCDEF))); |
| 83 |
assert_eq!(integral_lit("-0x9abcdef"), Ok(("", -0x9abcdef))); |
| 84 |
assert_eq!(integral_lit("-0x9abcdef"), Ok(("", -0x9abcdef))); |
| 85 |
} |
| 86 |
|
| 87 |
#[test] |
| 88 |
fn parse_unsigned_lit() { |
| 89 |
assert_eq!(unsigned_lit("0xffffffffU"), Ok(("", 0xffffffff as u32))); |
| 90 |
assert_eq!(unsigned_lit("-1u"), Ok(("", 0xffffffff as u32))); |
| 91 |
assert!(unsigned_lit("0xfffffffffU").is_err()); |
| 92 |
} |
| 93 |
|
| 94 |
#[test] |
| 95 |
fn parse_float_lit() { |
| 96 |
assert_eq!(float_lit("0.;"), Ok((";", 0.))); |
| 97 |
assert_eq!(float_lit(".0;"), Ok((";", 0.))); |
| 98 |
assert_eq!(float_lit(".035 "), Ok((" ", 0.035))); |
| 99 |
assert_eq!(float_lit("0. "), Ok((" ", 0.))); |
| 100 |
assert_eq!(float_lit("0.035 "), Ok((" ", 0.035))); |
| 101 |
assert_eq!(float_lit(".035f"), Ok(("", 0.035))); |
| 102 |
assert_eq!(float_lit("0.f"), Ok(("", 0.))); |
| 103 |
assert_eq!(float_lit("314.f"), Ok(("", 314.))); |
| 104 |
assert_eq!(float_lit("0.035f"), Ok(("", 0.035))); |
| 105 |
assert_eq!(float_lit(".035F"), Ok(("", 0.035))); |
| 106 |
assert_eq!(float_lit("0.F"), Ok(("", 0.))); |
| 107 |
assert_eq!(float_lit("0.035F"), Ok(("", 0.035))); |
| 108 |
assert_eq!(float_lit("1.03e+34 "), Ok((" ", 1.03e+34))); |
| 109 |
assert_eq!(float_lit("1.03E+34 "), Ok((" ", 1.03E+34))); |
| 110 |
assert_eq!(float_lit("1.03e-34 "), Ok((" ", 1.03e-34))); |
| 111 |
assert_eq!(float_lit("1.03E-34 "), Ok((" ", 1.03E-34))); |
| 112 |
assert_eq!(float_lit("1.03e+34f"), Ok(("", 1.03e+34))); |
| 113 |
assert_eq!(float_lit("1.03E+34f"), Ok(("", 1.03E+34))); |
| 114 |
assert_eq!(float_lit("1.03e-34f"), Ok(("", 1.03e-34))); |
| 115 |
assert_eq!(float_lit("1.03E-34f"), Ok(("", 1.03E-34))); |
| 116 |
assert_eq!(float_lit("1.03e+34F"), Ok(("", 1.03e+34))); |
| 117 |
assert_eq!(float_lit("1.03E+34F"), Ok(("", 1.03E+34))); |
| 118 |
assert_eq!(float_lit("1.03e-34F"), Ok(("", 1.03e-34))); |
| 119 |
assert_eq!(float_lit("1.03E-34F"), Ok(("", 1.03E-34))); |
| 120 |
} |
| 121 |
|
| 122 |
#[test] |
| 123 |
fn parse_float_neg_lit() { |
| 124 |
assert_eq!(float_lit("-.035 "), Ok((" ", -0.035))); |
| 125 |
assert_eq!(float_lit("-0. "), Ok((" ", -0.))); |
| 126 |
assert_eq!(float_lit("-0.035 "), Ok((" ", -0.035))); |
| 127 |
assert_eq!(float_lit("-.035f"), Ok(("", -0.035))); |
| 128 |
assert_eq!(float_lit("-0.f"), Ok(("", -0.))); |
| 129 |
assert_eq!(float_lit("-0.035f"), Ok(("", -0.035))); |
| 130 |
assert_eq!(float_lit("-.035F"), Ok(("", -0.035))); |
| 131 |
assert_eq!(float_lit("-0.F"), Ok(("", -0.))); |
| 132 |
assert_eq!(float_lit("-0.035F"), Ok(("", -0.035))); |
| 133 |
assert_eq!(float_lit("-1.03e+34 "), Ok((" ", -1.03e+34))); |
| 134 |
assert_eq!(float_lit("-1.03E+34 "), Ok((" ", -1.03E+34))); |
| 135 |
assert_eq!(float_lit("-1.03e-34 "), Ok((" ", -1.03e-34))); |
| 136 |
assert_eq!(float_lit("-1.03E-34 "), Ok((" ", -1.03E-34))); |
| 137 |
assert_eq!(float_lit("-1.03e+34f"), Ok(("", -1.03e+34))); |
| 138 |
assert_eq!(float_lit("-1.03E+34f"), Ok(("", -1.03E+34))); |
| 139 |
assert_eq!(float_lit("-1.03e-34f"), Ok(("", -1.03e-34))); |
| 140 |
assert_eq!(float_lit("-1.03E-34f"), Ok(("", -1.03E-34))); |
| 141 |
assert_eq!(float_lit("-1.03e+34F"), Ok(("", -1.03e+34))); |
| 142 |
assert_eq!(float_lit("-1.03E+34F"), Ok(("", -1.03E+34))); |
| 143 |
assert_eq!(float_lit("-1.03e-34F"), Ok(("", -1.03e-34))); |
| 144 |
assert_eq!(float_lit("-1.03E-34F"), Ok(("", -1.03E-34))); |
| 145 |
} |
| 146 |
|
| 147 |
#[test] |
| 148 |
fn parse_double_lit() { |
| 149 |
assert_eq!(double_lit("0.;"), Ok((";", 0.))); |
| 150 |
assert_eq!(double_lit(".0;"), Ok((";", 0.))); |
| 151 |
assert_eq!(double_lit(".035 "), Ok((" ", 0.035))); |
| 152 |
assert_eq!(double_lit("0. "), Ok((" ", 0.))); |
| 153 |
assert_eq!(double_lit("0.035 "), Ok((" ", 0.035))); |
| 154 |
assert_eq!(double_lit("0.lf"), Ok(("", 0.))); |
| 155 |
assert_eq!(double_lit("0.035lf"), Ok(("", 0.035))); |
| 156 |
assert_eq!(double_lit(".035lf"), Ok(("", 0.035))); |
| 157 |
assert_eq!(double_lit(".035LF"), Ok(("", 0.035))); |
| 158 |
assert_eq!(double_lit("0.LF"), Ok(("", 0.))); |
| 159 |
assert_eq!(double_lit("0.035LF"), Ok(("", 0.035))); |
| 160 |
assert_eq!(double_lit("1.03e+34lf"), Ok(("", 1.03e+34))); |
| 161 |
assert_eq!(double_lit("1.03E+34lf"), Ok(("", 1.03E+34))); |
| 162 |
assert_eq!(double_lit("1.03e-34lf"), Ok(("", 1.03e-34))); |
| 163 |
assert_eq!(double_lit("1.03E-34lf"), Ok(("", 1.03E-34))); |
| 164 |
assert_eq!(double_lit("1.03e+34LF"), Ok(("", 1.03e+34))); |
| 165 |
assert_eq!(double_lit("1.03E+34LF"), Ok(("", 1.03E+34))); |
| 166 |
assert_eq!(double_lit("1.03e-34LF"), Ok(("", 1.03e-34))); |
| 167 |
assert_eq!(double_lit("1.03E-34LF"), Ok(("", 1.03E-34))); |
| 168 |
} |
| 169 |
|
| 170 |
#[test] |
| 171 |
fn parse_double_neg_lit() { |
| 172 |
assert_eq!(double_lit("-0.;"), Ok((";", -0.))); |
| 173 |
assert_eq!(double_lit("-.0;"), Ok((";", -0.))); |
| 174 |
assert_eq!(double_lit("-.035 "), Ok((" ", -0.035))); |
| 175 |
assert_eq!(double_lit("-0. "), Ok((" ", -0.))); |
| 176 |
assert_eq!(double_lit("-0.035 "), Ok((" ", -0.035))); |
| 177 |
assert_eq!(double_lit("-0.lf"), Ok(("", -0.))); |
| 178 |
assert_eq!(double_lit("-0.035lf"), Ok(("", -0.035))); |
| 179 |
assert_eq!(double_lit("-.035lf"), Ok(("", -0.035))); |
| 180 |
assert_eq!(double_lit("-.035LF"), Ok(("", -0.035))); |
| 181 |
assert_eq!(double_lit("-0.LF"), Ok(("", -0.))); |
| 182 |
assert_eq!(double_lit("-0.035LF"), Ok(("", -0.035))); |
| 183 |
assert_eq!(double_lit("-1.03e+34lf"), Ok(("", -1.03e+34))); |
| 184 |
assert_eq!(double_lit("-1.03E+34lf"), Ok(("", -1.03E+34))); |
| 185 |
assert_eq!(double_lit("-1.03e-34lf"), Ok(("", -1.03e-34))); |
| 186 |
assert_eq!(double_lit("-1.03E-34lf"), Ok(("", -1.03E-34))); |
| 187 |
assert_eq!(double_lit("-1.03e+34LF"), Ok(("", -1.03e+34))); |
| 188 |
assert_eq!(double_lit("-1.03E+34LF"), Ok(("", -1.03E+34))); |
| 189 |
assert_eq!(double_lit("-1.03e-34LF"), Ok(("", -1.03e-34))); |
| 190 |
assert_eq!(double_lit("-1.03E-34LF"), Ok(("", -1.03E-34))); |
| 191 |
} |
| 192 |
|
| 193 |
#[test] |
| 194 |
fn parse_bool_lit() { |
| 195 |
assert_eq!(bool_lit("false"), Ok(("", false))); |
| 196 |
assert_eq!(bool_lit("true"), Ok(("", true))); |
| 197 |
} |
| 198 |
|
| 199 |
#[test] |
| 200 |
fn parse_identifier() { |
| 201 |
assert_eq!(identifier("a"), Ok(("", "a".into()))); |
| 202 |
assert_eq!(identifier("ab_cd"), Ok(("", "ab_cd".into()))); |
| 203 |
assert_eq!(identifier("Ab_cd"), Ok(("", "Ab_cd".into()))); |
| 204 |
assert_eq!(identifier("Ab_c8d"), Ok(("", "Ab_c8d".into()))); |
| 205 |
assert_eq!(identifier("Ab_c8d9"), Ok(("", "Ab_c8d9".into()))); |
| 206 |
} |
| 207 |
|
| 208 |
#[test] |
| 209 |
fn parse_unary_op_add() { |
| 210 |
assert_eq!(unary_op("+ "), Ok((" ", syntax::UnaryOp::Add))); |
| 211 |
} |
| 212 |
|
| 213 |
#[test] |
| 214 |
fn parse_unary_op_minus() { |
| 215 |
assert_eq!(unary_op("- "), Ok((" ", syntax::UnaryOp::Minus))); |
| 216 |
} |
| 217 |
|
| 218 |
#[test] |
| 219 |
fn parse_unary_op_not() { |
| 220 |
assert_eq!(unary_op("!"), Ok(("", syntax::UnaryOp::Not))); |
| 221 |
} |
| 222 |
|
| 223 |
#[test] |
| 224 |
fn parse_unary_op_complement() { |
| 225 |
assert_eq!(unary_op("~"), Ok(("", syntax::UnaryOp::Complement))); |
| 226 |
} |
| 227 |
|
| 228 |
#[test] |
| 229 |
fn parse_unary_op_inc() { |
| 230 |
assert_eq!(unary_op("++"), Ok(("", syntax::UnaryOp::Inc))); |
| 231 |
} |
| 232 |
|
| 233 |
#[test] |
| 234 |
fn parse_unary_op_dec() { |
| 235 |
assert_eq!(unary_op("--"), Ok(("", syntax::UnaryOp::Dec))); |
| 236 |
} |
| 237 |
|
| 238 |
#[test] |
| 239 |
fn parse_array_specifier_dimension_unsized() { |
| 240 |
assert_eq!( |
| 241 |
array_specifier_dimension("[]"), |
| 242 |
Ok(("", syntax::ArraySpecifierDimension::Unsized)) |
| 243 |
); |
| 244 |
assert_eq!( |
| 245 |
array_specifier_dimension("[ ]"), |
| 246 |
Ok(("", syntax::ArraySpecifierDimension::Unsized)) |
| 247 |
); |
| 248 |
assert_eq!( |
| 249 |
array_specifier_dimension("[\n]"), |
| 250 |
Ok(("", syntax::ArraySpecifierDimension::Unsized)) |
| 251 |
); |
| 252 |
} |
| 253 |
|
| 254 |
#[test] |
| 255 |
fn parse_array_specifier_dimension_sized() { |
| 256 |
let ix = syntax::Expr::IntConst(0); |
| 257 |
|
| 258 |
assert_eq!( |
| 259 |
array_specifier_dimension("[0]"), |
| 260 |
Ok(( |
| 261 |
"", |
| 262 |
syntax::ArraySpecifierDimension::ExplicitlySized(Box::new(ix.clone())) |
| 263 |
)) |
| 264 |
); |
| 265 |
assert_eq!( |
| 266 |
array_specifier_dimension("[\n0 \t]"), |
| 267 |
Ok(( |
| 268 |
"", |
| 269 |
syntax::ArraySpecifierDimension::ExplicitlySized(Box::new(ix)) |
| 270 |
)) |
| 271 |
); |
| 272 |
} |
| 273 |
|
| 274 |
#[test] |
| 275 |
fn parse_array_specifier_unsized() { |
| 276 |
assert_eq!( |
| 277 |
array_specifier("[]"), |
| 278 |
Ok(( |
| 279 |
"", |
| 280 |
syntax::ArraySpecifier { |
| 281 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::Unsized]) |
| 282 |
} |
| 283 |
)) |
| 284 |
) |
| 285 |
} |
| 286 |
|
| 287 |
#[test] |
| 288 |
fn parse_array_specifier_sized() { |
| 289 |
let ix = syntax::Expr::IntConst(123); |
| 290 |
|
| 291 |
assert_eq!( |
| 292 |
array_specifier("[123]"), |
| 293 |
Ok(( |
| 294 |
"", |
| 295 |
syntax::ArraySpecifier { |
| 296 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::ExplicitlySized( |
| 297 |
Box::new(ix) |
| 298 |
)]) |
| 299 |
} |
| 300 |
)) |
| 301 |
) |
| 302 |
} |
| 303 |
|
| 304 |
#[test] |
| 305 |
fn parse_array_specifier_sized_multiple() { |
| 306 |
let a = syntax::Expr::IntConst(2); |
| 307 |
let b = syntax::Expr::IntConst(100); |
| 308 |
let d = syntax::Expr::IntConst(5); |
| 309 |
|
| 310 |
assert_eq!( |
| 311 |
array_specifier("[2][100][][5]"), |
| 312 |
Ok(( |
| 313 |
"", |
| 314 |
syntax::ArraySpecifier { |
| 315 |
dimensions: syntax::NonEmpty(vec![ |
| 316 |
syntax::ArraySpecifierDimension::ExplicitlySized(Box::new(a)), |
| 317 |
syntax::ArraySpecifierDimension::ExplicitlySized(Box::new(b)), |
| 318 |
syntax::ArraySpecifierDimension::Unsized, |
| 319 |
syntax::ArraySpecifierDimension::ExplicitlySized(Box::new(d)), |
| 320 |
]) |
| 321 |
} |
| 322 |
)) |
| 323 |
) |
| 324 |
} |
| 325 |
|
| 326 |
#[test] |
| 327 |
fn parse_precise_qualifier() { |
| 328 |
assert_eq!(precise_qualifier("precise "), Ok((" ", ()))); |
| 329 |
} |
| 330 |
|
| 331 |
#[test] |
| 332 |
fn parse_invariant_qualifier() { |
| 333 |
assert_eq!(invariant_qualifier("invariant "), Ok((" ", ()))); |
| 334 |
} |
| 335 |
|
| 336 |
#[test] |
| 337 |
fn parse_interpolation_qualifier() { |
| 338 |
assert_eq!( |
| 339 |
interpolation_qualifier("smooth "), |
| 340 |
Ok((" ", syntax::InterpolationQualifier::Smooth)) |
| 341 |
); |
| 342 |
assert_eq!( |
| 343 |
interpolation_qualifier("flat "), |
| 344 |
Ok((" ", syntax::InterpolationQualifier::Flat)) |
| 345 |
); |
| 346 |
assert_eq!( |
| 347 |
interpolation_qualifier("noperspective "), |
| 348 |
Ok((" ", syntax::InterpolationQualifier::NoPerspective)) |
| 349 |
); |
| 350 |
} |
| 351 |
|
| 352 |
#[test] |
| 353 |
fn parse_precision_qualifier() { |
| 354 |
assert_eq!( |
| 355 |
precision_qualifier("highp "), |
| 356 |
Ok((" ", syntax::PrecisionQualifier::High)) |
| 357 |
); |
| 358 |
assert_eq!( |
| 359 |
precision_qualifier("mediump "), |
| 360 |
Ok((" ", syntax::PrecisionQualifier::Medium)) |
| 361 |
); |
| 362 |
assert_eq!( |
| 363 |
precision_qualifier("lowp "), |
| 364 |
Ok((" ", syntax::PrecisionQualifier::Low)) |
| 365 |
); |
| 366 |
} |
| 367 |
|
| 368 |
#[test] |
| 369 |
fn parse_storage_qualifier() { |
| 370 |
assert_eq!( |
| 371 |
storage_qualifier("const "), |
| 372 |
Ok((" ", syntax::StorageQualifier::Const)) |
| 373 |
); |
| 374 |
assert_eq!( |
| 375 |
storage_qualifier("inout "), |
| 376 |
Ok((" ", syntax::StorageQualifier::InOut)) |
| 377 |
); |
| 378 |
assert_eq!( |
| 379 |
storage_qualifier("in "), |
| 380 |
Ok((" ", syntax::StorageQualifier::In)) |
| 381 |
); |
| 382 |
assert_eq!( |
| 383 |
storage_qualifier("out "), |
| 384 |
Ok((" ", syntax::StorageQualifier::Out)) |
| 385 |
); |
| 386 |
assert_eq!( |
| 387 |
storage_qualifier("centroid "), |
| 388 |
Ok((" ", syntax::StorageQualifier::Centroid)) |
| 389 |
); |
| 390 |
assert_eq!( |
| 391 |
storage_qualifier("patch "), |
| 392 |
Ok((" ", syntax::StorageQualifier::Patch)) |
| 393 |
); |
| 394 |
assert_eq!( |
| 395 |
storage_qualifier("sample "), |
| 396 |
Ok((" ", syntax::StorageQualifier::Sample)) |
| 397 |
); |
| 398 |
assert_eq!( |
| 399 |
storage_qualifier("uniform "), |
| 400 |
Ok((" ", syntax::StorageQualifier::Uniform)) |
| 401 |
); |
| 402 |
assert_eq!( |
| 403 |
storage_qualifier("attribute "), |
| 404 |
Ok((" ", syntax::StorageQualifier::Attribute)) |
| 405 |
); |
| 406 |
assert_eq!( |
| 407 |
storage_qualifier("varying "), |
| 408 |
Ok((" ", syntax::StorageQualifier::Varying)) |
| 409 |
); |
| 410 |
assert_eq!( |
| 411 |
storage_qualifier("buffer "), |
| 412 |
Ok((" ", syntax::StorageQualifier::Buffer)) |
| 413 |
); |
| 414 |
assert_eq!( |
| 415 |
storage_qualifier("shared "), |
| 416 |
Ok((" ", syntax::StorageQualifier::Shared)) |
| 417 |
); |
| 418 |
assert_eq!( |
| 419 |
storage_qualifier("coherent "), |
| 420 |
Ok((" ", syntax::StorageQualifier::Coherent)) |
| 421 |
); |
| 422 |
assert_eq!( |
| 423 |
storage_qualifier("volatile "), |
| 424 |
Ok((" ", syntax::StorageQualifier::Volatile)) |
| 425 |
); |
| 426 |
assert_eq!( |
| 427 |
storage_qualifier("restrict "), |
| 428 |
Ok((" ", syntax::StorageQualifier::Restrict)) |
| 429 |
); |
| 430 |
assert_eq!( |
| 431 |
storage_qualifier("readonly "), |
| 432 |
Ok((" ", syntax::StorageQualifier::ReadOnly)) |
| 433 |
); |
| 434 |
assert_eq!( |
| 435 |
storage_qualifier("writeonly "), |
| 436 |
Ok((" ", syntax::StorageQualifier::WriteOnly)) |
| 437 |
); |
| 438 |
assert_eq!( |
| 439 |
storage_qualifier("subroutine a"), |
| 440 |
Ok((" a", syntax::StorageQualifier::Subroutine(vec![]))) |
| 441 |
); |
| 442 |
|
| 443 |
let a = syntax::TypeName("vec3".to_owned()); |
| 444 |
let b = syntax::TypeName("float".to_owned()); |
| 445 |
let c = syntax::TypeName("dmat43".to_owned()); |
| 446 |
let types = vec![a, b, c]; |
| 447 |
assert_eq!( |
| 448 |
storage_qualifier("subroutine ( vec3 , float \\\n, dmat43)"), |
| 449 |
Ok(("", syntax::StorageQualifier::Subroutine(types))) |
| 450 |
); |
| 451 |
} |
| 452 |
|
| 453 |
#[test] |
| 454 |
fn parse_layout_qualifier_std430() { |
| 455 |
let expected = syntax::LayoutQualifier { |
| 456 |
ids: syntax::NonEmpty(vec![syntax::LayoutQualifierSpec::Identifier( |
| 457 |
"std430".into(), |
| 458 |
None, |
| 459 |
)]), |
| 460 |
}; |
| 461 |
|
| 462 |
assert_eq!( |
| 463 |
layout_qualifier("layout (std430)"), |
| 464 |
Ok(("", expected.clone())) |
| 465 |
); |
| 466 |
assert_eq!( |
| 467 |
layout_qualifier("layout (std430 )"), |
| 468 |
Ok(("", expected.clone())) |
| 469 |
); |
| 470 |
assert_eq!( |
| 471 |
layout_qualifier("layout \n\t ( std430 )"), |
| 472 |
Ok(("", expected.clone())) |
| 473 |
); |
| 474 |
assert_eq!(layout_qualifier("layout(std430)"), Ok(("", expected))); |
| 475 |
} |
| 476 |
|
| 477 |
#[test] |
| 478 |
fn parse_layout_qualifier_shared() { |
| 479 |
let expected = syntax::LayoutQualifier { |
| 480 |
ids: syntax::NonEmpty(vec![syntax::LayoutQualifierSpec::Shared]), |
| 481 |
}; |
| 482 |
|
| 483 |
assert_eq!( |
| 484 |
layout_qualifier("layout (shared)"), |
| 485 |
Ok(("", expected.clone())) |
| 486 |
); |
| 487 |
assert_eq!( |
| 488 |
layout_qualifier("layout ( shared )"), |
| 489 |
Ok(("", expected.clone())) |
| 490 |
); |
| 491 |
assert_eq!(layout_qualifier("layout(shared)"), Ok(("", expected))); |
| 492 |
} |
| 493 |
|
| 494 |
#[test] |
| 495 |
fn parse_layout_qualifier_list() { |
| 496 |
let id_0 = syntax::LayoutQualifierSpec::Shared; |
| 497 |
let id_1 = syntax::LayoutQualifierSpec::Identifier("std140".into(), None); |
| 498 |
let id_2 = syntax::LayoutQualifierSpec::Identifier( |
| 499 |
"max_vertices".into(), |
| 500 |
Some(Box::new(syntax::Expr::IntConst(3))), |
| 501 |
); |
| 502 |
let expected = syntax::LayoutQualifier { |
| 503 |
ids: syntax::NonEmpty(vec![id_0, id_1, id_2]), |
| 504 |
}; |
| 505 |
|
| 506 |
assert_eq!( |
| 507 |
layout_qualifier("layout (shared, std140, max_vertices = 3)"), |
| 508 |
Ok(("", expected.clone())) |
| 509 |
); |
| 510 |
assert_eq!( |
| 511 |
layout_qualifier("layout(shared,std140,max_vertices=3)"), |
| 512 |
Ok(("", expected.clone())) |
| 513 |
); |
| 514 |
assert_eq!( |
| 515 |
layout_qualifier("layout\n\n\t ( shared , std140, max_vertices= 3)"), |
| 516 |
Ok(("", expected.clone())) |
| 517 |
); |
| 518 |
} |
| 519 |
|
| 520 |
#[test] |
| 521 |
fn parse_type_qualifier() { |
| 522 |
let storage_qual = syntax::TypeQualifierSpec::Storage(syntax::StorageQualifier::Const); |
| 523 |
let id_0 = syntax::LayoutQualifierSpec::Shared; |
| 524 |
let id_1 = syntax::LayoutQualifierSpec::Identifier("std140".into(), None); |
| 525 |
let id_2 = syntax::LayoutQualifierSpec::Identifier( |
| 526 |
"max_vertices".into(), |
| 527 |
Some(Box::new(syntax::Expr::IntConst(3))), |
| 528 |
); |
| 529 |
let layout_qual = syntax::TypeQualifierSpec::Layout(syntax::LayoutQualifier { |
| 530 |
ids: syntax::NonEmpty(vec![id_0, id_1, id_2]), |
| 531 |
}); |
| 532 |
let expected = syntax::TypeQualifier { |
| 533 |
qualifiers: syntax::NonEmpty(vec![storage_qual, layout_qual]), |
| 534 |
}; |
| 535 |
|
| 536 |
assert_eq!( |
| 537 |
type_qualifier("const layout (shared, std140, max_vertices = 3)"), |
| 538 |
Ok(("", expected.clone())) |
| 539 |
); |
| 540 |
assert_eq!( |
| 541 |
type_qualifier("const layout(shared,std140,max_vertices=3)"), |
| 542 |
Ok(("", expected)) |
| 543 |
); |
| 544 |
} |
| 545 |
|
| 546 |
#[test] |
| 547 |
fn parse_struct_field_specifier() { |
| 548 |
let expected = syntax::StructFieldSpecifier { |
| 549 |
qualifier: None, |
| 550 |
ty: syntax::TypeSpecifier { |
| 551 |
ty: syntax::TypeSpecifierNonArray::Vec4, |
| 552 |
array_specifier: None, |
| 553 |
}, |
| 554 |
identifiers: syntax::NonEmpty(vec!["foo".into()]), |
| 555 |
}; |
| 556 |
|
| 557 |
assert_eq!( |
| 558 |
struct_field_specifier("vec4 foo;"), |
| 559 |
Ok(("", expected.clone())) |
| 560 |
); |
| 561 |
assert_eq!( |
| 562 |
struct_field_specifier("vec4 foo ; "), |
| 563 |
Ok((" ", expected.clone())) |
| 564 |
); |
| 565 |
} |
| 566 |
|
| 567 |
#[test] |
| 568 |
fn parse_struct_field_specifier_type_name() { |
| 569 |
let expected = syntax::StructFieldSpecifier { |
| 570 |
qualifier: None, |
| 571 |
ty: syntax::TypeSpecifier { |
| 572 |
ty: syntax::TypeSpecifierNonArray::TypeName("S0238_3".into()), |
| 573 |
array_specifier: None, |
| 574 |
}, |
| 575 |
identifiers: syntax::NonEmpty(vec!["x".into()]), |
| 576 |
}; |
| 577 |
|
| 578 |
assert_eq!( |
| 579 |
struct_field_specifier("S0238_3 x;"), |
| 580 |
Ok(("", expected.clone())) |
| 581 |
); |
| 582 |
assert_eq!( |
| 583 |
struct_field_specifier("S0238_3 x ;"), |
| 584 |
Ok(("", expected.clone())) |
| 585 |
); |
| 586 |
} |
| 587 |
|
| 588 |
#[test] |
| 589 |
fn parse_struct_field_specifier_several() { |
| 590 |
let expected = syntax::StructFieldSpecifier { |
| 591 |
qualifier: None, |
| 592 |
ty: syntax::TypeSpecifier { |
| 593 |
ty: syntax::TypeSpecifierNonArray::Vec4, |
| 594 |
array_specifier: None, |
| 595 |
}, |
| 596 |
identifiers: syntax::NonEmpty(vec!["foo".into(), "bar".into(), "zoo".into()]), |
| 597 |
}; |
| 598 |
|
| 599 |
assert_eq!( |
| 600 |
struct_field_specifier("vec4 foo, bar, zoo;"), |
| 601 |
Ok(("", expected.clone())) |
| 602 |
); |
| 603 |
assert_eq!( |
| 604 |
struct_field_specifier("vec4 foo , bar , zoo ;"), |
| 605 |
Ok(("", expected.clone())) |
| 606 |
); |
| 607 |
} |
| 608 |
|
| 609 |
#[test] |
| 610 |
fn parse_struct_specifier_one_field() { |
| 611 |
let field = syntax::StructFieldSpecifier { |
| 612 |
qualifier: None, |
| 613 |
ty: syntax::TypeSpecifier { |
| 614 |
ty: syntax::TypeSpecifierNonArray::Vec4, |
| 615 |
array_specifier: None, |
| 616 |
}, |
| 617 |
identifiers: syntax::NonEmpty(vec!["foo".into()]), |
| 618 |
}; |
| 619 |
let expected = syntax::StructSpecifier { |
| 620 |
name: Some("TestStruct".into()), |
| 621 |
fields: syntax::NonEmpty(vec![field]), |
| 622 |
}; |
| 623 |
|
| 624 |
assert_eq!( |
| 625 |
struct_specifier("struct TestStruct { vec4 foo; }"), |
| 626 |
Ok(("", expected.clone())) |
| 627 |
); |
| 628 |
assert_eq!( |
| 629 |
struct_specifier("struct TestStruct \n \n\n {\n vec4 foo ;}"), |
| 630 |
Ok(("", expected)) |
| 631 |
); |
| 632 |
} |
| 633 |
|
| 634 |
#[test] |
| 635 |
fn parse_struct_specifier_multi_fields() { |
| 636 |
let a = syntax::StructFieldSpecifier { |
| 637 |
qualifier: None, |
| 638 |
ty: syntax::TypeSpecifier { |
| 639 |
ty: syntax::TypeSpecifierNonArray::Vec4, |
| 640 |
array_specifier: None, |
| 641 |
}, |
| 642 |
identifiers: syntax::NonEmpty(vec!["foo".into()]), |
| 643 |
}; |
| 644 |
let b = syntax::StructFieldSpecifier { |
| 645 |
qualifier: None, |
| 646 |
ty: syntax::TypeSpecifier { |
| 647 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 648 |
array_specifier: None, |
| 649 |
}, |
| 650 |
identifiers: syntax::NonEmpty(vec!["bar".into()]), |
| 651 |
}; |
| 652 |
let c = syntax::StructFieldSpecifier { |
| 653 |
qualifier: None, |
| 654 |
ty: syntax::TypeSpecifier { |
| 655 |
ty: syntax::TypeSpecifierNonArray::UInt, |
| 656 |
array_specifier: None, |
| 657 |
}, |
| 658 |
identifiers: syntax::NonEmpty(vec!["zoo".into()]), |
| 659 |
}; |
| 660 |
let d = syntax::StructFieldSpecifier { |
| 661 |
qualifier: None, |
| 662 |
ty: syntax::TypeSpecifier { |
| 663 |
ty: syntax::TypeSpecifierNonArray::BVec3, |
| 664 |
array_specifier: None, |
| 665 |
}, |
| 666 |
identifiers: syntax::NonEmpty(vec!["foo_BAR_zoo3497_34".into()]), |
| 667 |
}; |
| 668 |
let e = syntax::StructFieldSpecifier { |
| 669 |
qualifier: None, |
| 670 |
ty: syntax::TypeSpecifier { |
| 671 |
ty: syntax::TypeSpecifierNonArray::TypeName("S0238_3".into()), |
| 672 |
array_specifier: None, |
| 673 |
}, |
| 674 |
identifiers: syntax::NonEmpty(vec!["x".into()]), |
| 675 |
}; |
| 676 |
let expected = syntax::StructSpecifier { |
| 677 |
name: Some("_TestStruct_934i".into()), |
| 678 |
fields: syntax::NonEmpty(vec![a, b, c, d, e]), |
| 679 |
}; |
| 680 |
|
| 681 |
assert_eq!( |
| 682 |
struct_specifier( |
| 683 |
"struct _TestStruct_934i { vec4 foo; float bar; uint zoo; bvec3 foo_BAR_zoo3497_34; S0238_3 x; }" |
| 684 |
), |
| 685 |
Ok(("", expected.clone())) |
| 686 |
); |
| 687 |
assert_eq!( |
| 688 |
struct_specifier( |
| 689 |
"struct _TestStruct_934i{vec4 foo;float bar;uint zoo;bvec3 foo_BAR_zoo3497_34;S0238_3 x;}" |
| 690 |
), |
| 691 |
Ok(("", expected.clone())) |
| 692 |
); |
| 693 |
assert_eq!(struct_specifier("struct _TestStruct_934i\n { vec4\nfoo ; \n\t float\n\t\t bar ; \nuint zoo; \n bvec3 foo_BAR_zoo3497_34\n\n\t\n\t\n ; S0238_3 x;}"), Ok(("", expected))); |
| 694 |
} |
| 695 |
|
| 696 |
#[test] |
| 697 |
fn parse_type_specifier_non_array() { |
| 698 |
assert_eq!( |
| 699 |
type_specifier_non_array("bool"), |
| 700 |
Ok(("", syntax::TypeSpecifierNonArray::Bool)) |
| 701 |
); |
| 702 |
assert_eq!( |
| 703 |
type_specifier_non_array("int"), |
| 704 |
Ok(("", syntax::TypeSpecifierNonArray::Int)) |
| 705 |
); |
| 706 |
assert_eq!( |
| 707 |
type_specifier_non_array("uint"), |
| 708 |
Ok(("", syntax::TypeSpecifierNonArray::UInt)) |
| 709 |
); |
| 710 |
assert_eq!( |
| 711 |
type_specifier_non_array("float"), |
| 712 |
Ok(("", syntax::TypeSpecifierNonArray::Float)) |
| 713 |
); |
| 714 |
assert_eq!( |
| 715 |
type_specifier_non_array("double"), |
| 716 |
Ok(("", syntax::TypeSpecifierNonArray::Double)) |
| 717 |
); |
| 718 |
assert_eq!( |
| 719 |
type_specifier_non_array("vec2"), |
| 720 |
Ok(("", syntax::TypeSpecifierNonArray::Vec2)) |
| 721 |
); |
| 722 |
assert_eq!( |
| 723 |
type_specifier_non_array("vec3"), |
| 724 |
Ok(("", syntax::TypeSpecifierNonArray::Vec3)) |
| 725 |
); |
| 726 |
assert_eq!( |
| 727 |
type_specifier_non_array("vec4"), |
| 728 |
Ok(("", syntax::TypeSpecifierNonArray::Vec4)) |
| 729 |
); |
| 730 |
assert_eq!( |
| 731 |
type_specifier_non_array("dvec2"), |
| 732 |
Ok(("", syntax::TypeSpecifierNonArray::DVec2)) |
| 733 |
); |
| 734 |
assert_eq!( |
| 735 |
type_specifier_non_array("dvec3"), |
| 736 |
Ok(("", syntax::TypeSpecifierNonArray::DVec3)) |
| 737 |
); |
| 738 |
assert_eq!( |
| 739 |
type_specifier_non_array("dvec4"), |
| 740 |
Ok(("", syntax::TypeSpecifierNonArray::DVec4)) |
| 741 |
); |
| 742 |
assert_eq!( |
| 743 |
type_specifier_non_array("bvec2"), |
| 744 |
Ok(("", syntax::TypeSpecifierNonArray::BVec2)) |
| 745 |
); |
| 746 |
assert_eq!( |
| 747 |
type_specifier_non_array("bvec3"), |
| 748 |
Ok(("", syntax::TypeSpecifierNonArray::BVec3)) |
| 749 |
); |
| 750 |
assert_eq!( |
| 751 |
type_specifier_non_array("bvec4"), |
| 752 |
Ok(("", syntax::TypeSpecifierNonArray::BVec4)) |
| 753 |
); |
| 754 |
assert_eq!( |
| 755 |
type_specifier_non_array("ivec2"), |
| 756 |
Ok(("", syntax::TypeSpecifierNonArray::IVec2)) |
| 757 |
); |
| 758 |
assert_eq!( |
| 759 |
type_specifier_non_array("ivec3"), |
| 760 |
Ok(("", syntax::TypeSpecifierNonArray::IVec3)) |
| 761 |
); |
| 762 |
assert_eq!( |
| 763 |
type_specifier_non_array("ivec4"), |
| 764 |
Ok(("", syntax::TypeSpecifierNonArray::IVec4)) |
| 765 |
); |
| 766 |
assert_eq!( |
| 767 |
type_specifier_non_array("uvec2"), |
| 768 |
Ok(("", syntax::TypeSpecifierNonArray::UVec2)) |
| 769 |
); |
| 770 |
assert_eq!( |
| 771 |
type_specifier_non_array("uvec3"), |
| 772 |
Ok(("", syntax::TypeSpecifierNonArray::UVec3)) |
| 773 |
); |
| 774 |
assert_eq!( |
| 775 |
type_specifier_non_array("uvec4"), |
| 776 |
Ok(("", syntax::TypeSpecifierNonArray::UVec4)) |
| 777 |
); |
| 778 |
assert_eq!( |
| 779 |
type_specifier_non_array("mat2"), |
| 780 |
Ok(("", syntax::TypeSpecifierNonArray::Mat2)) |
| 781 |
); |
| 782 |
assert_eq!( |
| 783 |
type_specifier_non_array("mat3"), |
| 784 |
Ok(("", syntax::TypeSpecifierNonArray::Mat3)) |
| 785 |
); |
| 786 |
assert_eq!( |
| 787 |
type_specifier_non_array("mat4"), |
| 788 |
Ok(("", syntax::TypeSpecifierNonArray::Mat4)) |
| 789 |
); |
| 790 |
assert_eq!( |
| 791 |
type_specifier_non_array("mat2x2"), |
| 792 |
Ok(("", syntax::TypeSpecifierNonArray::Mat2)) |
| 793 |
); |
| 794 |
assert_eq!( |
| 795 |
type_specifier_non_array("mat2x3"), |
| 796 |
Ok(("", syntax::TypeSpecifierNonArray::Mat23)) |
| 797 |
); |
| 798 |
assert_eq!( |
| 799 |
type_specifier_non_array("mat2x4"), |
| 800 |
Ok(("", syntax::TypeSpecifierNonArray::Mat24)) |
| 801 |
); |
| 802 |
assert_eq!( |
| 803 |
type_specifier_non_array("mat3x2"), |
| 804 |
Ok(("", syntax::TypeSpecifierNonArray::Mat32)) |
| 805 |
); |
| 806 |
assert_eq!( |
| 807 |
type_specifier_non_array("mat3x3"), |
| 808 |
Ok(("", syntax::TypeSpecifierNonArray::Mat3)) |
| 809 |
); |
| 810 |
assert_eq!( |
| 811 |
type_specifier_non_array("mat3x4"), |
| 812 |
Ok(("", syntax::TypeSpecifierNonArray::Mat34)) |
| 813 |
); |
| 814 |
assert_eq!( |
| 815 |
type_specifier_non_array("mat4x2"), |
| 816 |
Ok(("", syntax::TypeSpecifierNonArray::Mat42)) |
| 817 |
); |
| 818 |
assert_eq!( |
| 819 |
type_specifier_non_array("mat4x3"), |
| 820 |
Ok(("", syntax::TypeSpecifierNonArray::Mat43)) |
| 821 |
); |
| 822 |
assert_eq!( |
| 823 |
type_specifier_non_array("mat4x4"), |
| 824 |
Ok(("", syntax::TypeSpecifierNonArray::Mat4)) |
| 825 |
); |
| 826 |
assert_eq!( |
| 827 |
type_specifier_non_array("dmat2"), |
| 828 |
Ok(("", syntax::TypeSpecifierNonArray::DMat2)) |
| 829 |
); |
| 830 |
assert_eq!( |
| 831 |
type_specifier_non_array("dmat3"), |
| 832 |
Ok(("", syntax::TypeSpecifierNonArray::DMat3)) |
| 833 |
); |
| 834 |
assert_eq!( |
| 835 |
type_specifier_non_array("dmat4"), |
| 836 |
Ok(("", syntax::TypeSpecifierNonArray::DMat4)) |
| 837 |
); |
| 838 |
assert_eq!( |
| 839 |
type_specifier_non_array("dmat2x2"), |
| 840 |
Ok(("", syntax::TypeSpecifierNonArray::DMat2)) |
| 841 |
); |
| 842 |
assert_eq!( |
| 843 |
type_specifier_non_array("dmat2x3"), |
| 844 |
Ok(("", syntax::TypeSpecifierNonArray::DMat23)) |
| 845 |
); |
| 846 |
assert_eq!( |
| 847 |
type_specifier_non_array("dmat2x4"), |
| 848 |
Ok(("", syntax::TypeSpecifierNonArray::DMat24)) |
| 849 |
); |
| 850 |
assert_eq!( |
| 851 |
type_specifier_non_array("dmat3x2"), |
| 852 |
Ok(("", syntax::TypeSpecifierNonArray::DMat32)) |
| 853 |
); |
| 854 |
assert_eq!( |
| 855 |
type_specifier_non_array("dmat3x3"), |
| 856 |
Ok(("", syntax::TypeSpecifierNonArray::DMat3)) |
| 857 |
); |
| 858 |
assert_eq!( |
| 859 |
type_specifier_non_array("dmat3x4"), |
| 860 |
Ok(("", syntax::TypeSpecifierNonArray::DMat34)) |
| 861 |
); |
| 862 |
assert_eq!( |
| 863 |
type_specifier_non_array("dmat4x2"), |
| 864 |
Ok(("", syntax::TypeSpecifierNonArray::DMat42)) |
| 865 |
); |
| 866 |
assert_eq!( |
| 867 |
type_specifier_non_array("dmat4x3"), |
| 868 |
Ok(("", syntax::TypeSpecifierNonArray::DMat43)) |
| 869 |
); |
| 870 |
assert_eq!( |
| 871 |
type_specifier_non_array("dmat4x4"), |
| 872 |
Ok(("", syntax::TypeSpecifierNonArray::DMat4)) |
| 873 |
); |
| 874 |
assert_eq!( |
| 875 |
type_specifier_non_array("sampler1D"), |
| 876 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler1D)) |
| 877 |
); |
| 878 |
assert_eq!( |
| 879 |
type_specifier_non_array("image1D"), |
| 880 |
Ok(("", syntax::TypeSpecifierNonArray::Image1D)) |
| 881 |
); |
| 882 |
assert_eq!( |
| 883 |
type_specifier_non_array("sampler2D"), |
| 884 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2D)) |
| 885 |
); |
| 886 |
assert_eq!( |
| 887 |
type_specifier_non_array("image2D"), |
| 888 |
Ok(("", syntax::TypeSpecifierNonArray::Image2D)) |
| 889 |
); |
| 890 |
assert_eq!( |
| 891 |
type_specifier_non_array("sampler3D"), |
| 892 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler3D)) |
| 893 |
); |
| 894 |
assert_eq!( |
| 895 |
type_specifier_non_array("image3D"), |
| 896 |
Ok(("", syntax::TypeSpecifierNonArray::Image3D)) |
| 897 |
); |
| 898 |
assert_eq!( |
| 899 |
type_specifier_non_array("samplerCube"), |
| 900 |
Ok(("", syntax::TypeSpecifierNonArray::SamplerCube)) |
| 901 |
); |
| 902 |
assert_eq!( |
| 903 |
type_specifier_non_array("imageCube"), |
| 904 |
Ok(("", syntax::TypeSpecifierNonArray::ImageCube)) |
| 905 |
); |
| 906 |
assert_eq!( |
| 907 |
type_specifier_non_array("sampler2DRect"), |
| 908 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DRect)) |
| 909 |
); |
| 910 |
assert_eq!( |
| 911 |
type_specifier_non_array("image2DRect"), |
| 912 |
Ok(("", syntax::TypeSpecifierNonArray::Image2DRect)) |
| 913 |
); |
| 914 |
assert_eq!( |
| 915 |
type_specifier_non_array("sampler1DArray"), |
| 916 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler1DArray)) |
| 917 |
); |
| 918 |
assert_eq!( |
| 919 |
type_specifier_non_array("image1DArray"), |
| 920 |
Ok(("", syntax::TypeSpecifierNonArray::Image1DArray)) |
| 921 |
); |
| 922 |
assert_eq!( |
| 923 |
type_specifier_non_array("sampler2DArray"), |
| 924 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DArray)) |
| 925 |
); |
| 926 |
assert_eq!( |
| 927 |
type_specifier_non_array("image2DArray"), |
| 928 |
Ok(("", syntax::TypeSpecifierNonArray::Image2DArray)) |
| 929 |
); |
| 930 |
assert_eq!( |
| 931 |
type_specifier_non_array("samplerBuffer"), |
| 932 |
Ok(("", syntax::TypeSpecifierNonArray::SamplerBuffer)) |
| 933 |
); |
| 934 |
assert_eq!( |
| 935 |
type_specifier_non_array("imageBuffer"), |
| 936 |
Ok(("", syntax::TypeSpecifierNonArray::ImageBuffer)) |
| 937 |
); |
| 938 |
assert_eq!( |
| 939 |
type_specifier_non_array("sampler2DMS"), |
| 940 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DMS)) |
| 941 |
); |
| 942 |
assert_eq!( |
| 943 |
type_specifier_non_array("image2DMS"), |
| 944 |
Ok(("", syntax::TypeSpecifierNonArray::Image2DMS)) |
| 945 |
); |
| 946 |
assert_eq!( |
| 947 |
type_specifier_non_array("sampler2DMSArray"), |
| 948 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DMSArray)) |
| 949 |
); |
| 950 |
assert_eq!( |
| 951 |
type_specifier_non_array("image2DMSArray"), |
| 952 |
Ok(("", syntax::TypeSpecifierNonArray::Image2DMSArray)) |
| 953 |
); |
| 954 |
assert_eq!( |
| 955 |
type_specifier_non_array("samplerCubeArray"), |
| 956 |
Ok(("", syntax::TypeSpecifierNonArray::SamplerCubeArray)) |
| 957 |
); |
| 958 |
assert_eq!( |
| 959 |
type_specifier_non_array("imageCubeArray"), |
| 960 |
Ok(("", syntax::TypeSpecifierNonArray::ImageCubeArray)) |
| 961 |
); |
| 962 |
assert_eq!( |
| 963 |
type_specifier_non_array("sampler1DShadow"), |
| 964 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler1DShadow)) |
| 965 |
); |
| 966 |
assert_eq!( |
| 967 |
type_specifier_non_array("sampler2DShadow"), |
| 968 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DShadow)) |
| 969 |
); |
| 970 |
assert_eq!( |
| 971 |
type_specifier_non_array("sampler2DRectShadow"), |
| 972 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DRectShadow)) |
| 973 |
); |
| 974 |
assert_eq!( |
| 975 |
type_specifier_non_array("sampler1DArrayShadow"), |
| 976 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler1DArrayShadow)) |
| 977 |
); |
| 978 |
assert_eq!( |
| 979 |
type_specifier_non_array("sampler2DArrayShadow"), |
| 980 |
Ok(("", syntax::TypeSpecifierNonArray::Sampler2DArrayShadow)) |
| 981 |
); |
| 982 |
assert_eq!( |
| 983 |
type_specifier_non_array("samplerCubeShadow"), |
| 984 |
Ok(("", syntax::TypeSpecifierNonArray::SamplerCubeShadow)) |
| 985 |
); |
| 986 |
assert_eq!( |
| 987 |
type_specifier_non_array("samplerCubeArrayShadow"), |
| 988 |
Ok(("", syntax::TypeSpecifierNonArray::SamplerCubeArrayShadow)) |
| 989 |
); |
| 990 |
assert_eq!( |
| 991 |
type_specifier_non_array("isampler1D"), |
| 992 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler1D)) |
| 993 |
); |
| 994 |
assert_eq!( |
| 995 |
type_specifier_non_array("iimage1D"), |
| 996 |
Ok(("", syntax::TypeSpecifierNonArray::IImage1D)) |
| 997 |
); |
| 998 |
assert_eq!( |
| 999 |
type_specifier_non_array("isampler2D"), |
| 1000 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler2D)) |
| 1001 |
); |
| 1002 |
assert_eq!( |
| 1003 |
type_specifier_non_array("iimage2D"), |
| 1004 |
Ok(("", syntax::TypeSpecifierNonArray::IImage2D)) |
| 1005 |
); |
| 1006 |
assert_eq!( |
| 1007 |
type_specifier_non_array("isampler3D"), |
| 1008 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler3D)) |
| 1009 |
); |
| 1010 |
assert_eq!( |
| 1011 |
type_specifier_non_array("iimage3D"), |
| 1012 |
Ok(("", syntax::TypeSpecifierNonArray::IImage3D)) |
| 1013 |
); |
| 1014 |
assert_eq!( |
| 1015 |
type_specifier_non_array("isamplerCube"), |
| 1016 |
Ok(("", syntax::TypeSpecifierNonArray::ISamplerCube)) |
| 1017 |
); |
| 1018 |
assert_eq!( |
| 1019 |
type_specifier_non_array("iimageCube"), |
| 1020 |
Ok(("", syntax::TypeSpecifierNonArray::IImageCube)) |
| 1021 |
); |
| 1022 |
assert_eq!( |
| 1023 |
type_specifier_non_array("isampler2DRect"), |
| 1024 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler2DRect)) |
| 1025 |
); |
| 1026 |
assert_eq!( |
| 1027 |
type_specifier_non_array("iimage2DRect"), |
| 1028 |
Ok(("", syntax::TypeSpecifierNonArray::IImage2DRect)) |
| 1029 |
); |
| 1030 |
assert_eq!( |
| 1031 |
type_specifier_non_array("isampler1DArray"), |
| 1032 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler1DArray)) |
| 1033 |
); |
| 1034 |
assert_eq!( |
| 1035 |
type_specifier_non_array("iimage1DArray"), |
| 1036 |
Ok(("", syntax::TypeSpecifierNonArray::IImage1DArray)) |
| 1037 |
); |
| 1038 |
assert_eq!( |
| 1039 |
type_specifier_non_array("isampler2DArray"), |
| 1040 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler2DArray)) |
| 1041 |
); |
| 1042 |
assert_eq!( |
| 1043 |
type_specifier_non_array("iimage2DArray"), |
| 1044 |
Ok(("", syntax::TypeSpecifierNonArray::IImage2DArray)) |
| 1045 |
); |
| 1046 |
assert_eq!( |
| 1047 |
type_specifier_non_array("isamplerBuffer"), |
| 1048 |
Ok(("", syntax::TypeSpecifierNonArray::ISamplerBuffer)) |
| 1049 |
); |
| 1050 |
assert_eq!( |
| 1051 |
type_specifier_non_array("iimageBuffer"), |
| 1052 |
Ok(("", syntax::TypeSpecifierNonArray::IImageBuffer)) |
| 1053 |
); |
| 1054 |
assert_eq!( |
| 1055 |
type_specifier_non_array("isampler2DMS"), |
| 1056 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler2DMS)) |
| 1057 |
); |
| 1058 |
assert_eq!( |
| 1059 |
type_specifier_non_array("iimage2DMS"), |
| 1060 |
Ok(("", syntax::TypeSpecifierNonArray::IImage2DMS)) |
| 1061 |
); |
| 1062 |
assert_eq!( |
| 1063 |
type_specifier_non_array("isampler2DMSArray"), |
| 1064 |
Ok(("", syntax::TypeSpecifierNonArray::ISampler2DMSArray)) |
| 1065 |
); |
| 1066 |
assert_eq!( |
| 1067 |
type_specifier_non_array("iimage2DMSArray"), |
| 1068 |
Ok(("", syntax::TypeSpecifierNonArray::IImage2DMSArray)) |
| 1069 |
); |
| 1070 |
assert_eq!( |
| 1071 |
type_specifier_non_array("isamplerCubeArray"), |
| 1072 |
Ok(("", syntax::TypeSpecifierNonArray::ISamplerCubeArray)) |
| 1073 |
); |
| 1074 |
assert_eq!( |
| 1075 |
type_specifier_non_array("iimageCubeArray"), |
| 1076 |
Ok(("", syntax::TypeSpecifierNonArray::IImageCubeArray)) |
| 1077 |
); |
| 1078 |
assert_eq!( |
| 1079 |
type_specifier_non_array("atomic_uint"), |
| 1080 |
Ok(("", syntax::TypeSpecifierNonArray::AtomicUInt)) |
| 1081 |
); |
| 1082 |
assert_eq!( |
| 1083 |
type_specifier_non_array("usampler1D"), |
| 1084 |
Ok(("", syntax::TypeSpecifierNonArray::USampler1D)) |
| 1085 |
); |
| 1086 |
assert_eq!( |
| 1087 |
type_specifier_non_array("uimage1D"), |
| 1088 |
Ok(("", syntax::TypeSpecifierNonArray::UImage1D)) |
| 1089 |
); |
| 1090 |
assert_eq!( |
| 1091 |
type_specifier_non_array("usampler2D"), |
| 1092 |
Ok(("", syntax::TypeSpecifierNonArray::USampler2D)) |
| 1093 |
); |
| 1094 |
assert_eq!( |
| 1095 |
type_specifier_non_array("uimage2D"), |
| 1096 |
Ok(("", syntax::TypeSpecifierNonArray::UImage2D)) |
| 1097 |
); |
| 1098 |
assert_eq!( |
| 1099 |
type_specifier_non_array("usampler3D"), |
| 1100 |
Ok(("", syntax::TypeSpecifierNonArray::USampler3D)) |
| 1101 |
); |
| 1102 |
assert_eq!( |
| 1103 |
type_specifier_non_array("uimage3D"), |
| 1104 |
Ok(("", syntax::TypeSpecifierNonArray::UImage3D)) |
| 1105 |
); |
| 1106 |
assert_eq!( |
| 1107 |
type_specifier_non_array("usamplerCube"), |
| 1108 |
Ok(("", syntax::TypeSpecifierNonArray::USamplerCube)) |
| 1109 |
); |
| 1110 |
assert_eq!( |
| 1111 |
type_specifier_non_array("uimageCube"), |
| 1112 |
Ok(("", syntax::TypeSpecifierNonArray::UImageCube)) |
| 1113 |
); |
| 1114 |
assert_eq!( |
| 1115 |
type_specifier_non_array("usampler2DRect"), |
| 1116 |
Ok(("", syntax::TypeSpecifierNonArray::USampler2DRect)) |
| 1117 |
); |
| 1118 |
assert_eq!( |
| 1119 |
type_specifier_non_array("uimage2DRect"), |
| 1120 |
Ok(("", syntax::TypeSpecifierNonArray::UImage2DRect)) |
| 1121 |
); |
| 1122 |
assert_eq!( |
| 1123 |
type_specifier_non_array("usampler1DArray"), |
| 1124 |
Ok(("", syntax::TypeSpecifierNonArray::USampler1DArray)) |
| 1125 |
); |
| 1126 |
assert_eq!( |
| 1127 |
type_specifier_non_array("uimage1DArray"), |
| 1128 |
Ok(("", syntax::TypeSpecifierNonArray::UImage1DArray)) |
| 1129 |
); |
| 1130 |
assert_eq!( |
| 1131 |
type_specifier_non_array("usampler2DArray"), |
| 1132 |
Ok(("", syntax::TypeSpecifierNonArray::USampler2DArray)) |
| 1133 |
); |
| 1134 |
assert_eq!( |
| 1135 |
type_specifier_non_array("uimage2DArray"), |
| 1136 |
Ok(("", syntax::TypeSpecifierNonArray::UImage2DArray)) |
| 1137 |
); |
| 1138 |
assert_eq!( |
| 1139 |
type_specifier_non_array("usamplerBuffer"), |
| 1140 |
Ok(("", syntax::TypeSpecifierNonArray::USamplerBuffer)) |
| 1141 |
); |
| 1142 |
assert_eq!( |
| 1143 |
type_specifier_non_array("uimageBuffer"), |
| 1144 |
Ok(("", syntax::TypeSpecifierNonArray::UImageBuffer)) |
| 1145 |
); |
| 1146 |
assert_eq!( |
| 1147 |
type_specifier_non_array("usampler2DMS"), |
| 1148 |
Ok(("", syntax::TypeSpecifierNonArray::USampler2DMS)) |
| 1149 |
); |
| 1150 |
assert_eq!( |
| 1151 |
type_specifier_non_array("uimage2DMS"), |
| 1152 |
Ok(("", syntax::TypeSpecifierNonArray::UImage2DMS)) |
| 1153 |
); |
| 1154 |
assert_eq!( |
| 1155 |
type_specifier_non_array("usampler2DMSArray"), |
| 1156 |
Ok(("", syntax::TypeSpecifierNonArray::USampler2DMSArray)) |
| 1157 |
); |
| 1158 |
assert_eq!( |
| 1159 |
type_specifier_non_array("uimage2DMSArray"), |
| 1160 |
Ok(("", syntax::TypeSpecifierNonArray::UImage2DMSArray)) |
| 1161 |
); |
| 1162 |
assert_eq!( |
| 1163 |
type_specifier_non_array("usamplerCubeArray"), |
| 1164 |
Ok(("", syntax::TypeSpecifierNonArray::USamplerCubeArray)) |
| 1165 |
); |
| 1166 |
assert_eq!( |
| 1167 |
type_specifier_non_array("uimageCubeArray"), |
| 1168 |
Ok(("", syntax::TypeSpecifierNonArray::UImageCubeArray)) |
| 1169 |
); |
| 1170 |
assert_eq!( |
| 1171 |
type_specifier_non_array("ReturnType"), |
| 1172 |
Ok(( |
| 1173 |
"", |
| 1174 |
syntax::TypeSpecifierNonArray::TypeName(syntax::TypeName::new("ReturnType").unwrap()) |
| 1175 |
)) |
| 1176 |
); |
| 1177 |
} |
| 1178 |
|
| 1179 |
#[test] |
| 1180 |
fn parse_type_specifier() { |
| 1181 |
assert_eq!( |
| 1182 |
type_specifier("uint;"), |
| 1183 |
Ok(( |
| 1184 |
";", |
| 1185 |
syntax::TypeSpecifier { |
| 1186 |
ty: syntax::TypeSpecifierNonArray::UInt, |
| 1187 |
array_specifier: None |
| 1188 |
} |
| 1189 |
)) |
| 1190 |
); |
| 1191 |
assert_eq!( |
| 1192 |
type_specifier("iimage2DMSArray[35];"), |
| 1193 |
Ok(( |
| 1194 |
";", |
| 1195 |
syntax::TypeSpecifier { |
| 1196 |
ty: syntax::TypeSpecifierNonArray::IImage2DMSArray, |
| 1197 |
array_specifier: Some(syntax::ArraySpecifier { |
| 1198 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::ExplicitlySized( |
| 1199 |
Box::new(syntax::Expr::IntConst(35)) |
| 1200 |
)]) |
| 1201 |
}) |
| 1202 |
} |
| 1203 |
)) |
| 1204 |
); |
| 1205 |
} |
| 1206 |
|
| 1207 |
#[test] |
| 1208 |
fn parse_fully_specified_type() { |
| 1209 |
let ty = syntax::TypeSpecifier { |
| 1210 |
ty: syntax::TypeSpecifierNonArray::IImage2DMSArray, |
| 1211 |
array_specifier: None, |
| 1212 |
}; |
| 1213 |
let expected = syntax::FullySpecifiedType { |
| 1214 |
qualifier: None, |
| 1215 |
ty, |
| 1216 |
}; |
| 1217 |
|
| 1218 |
assert_eq!( |
| 1219 |
fully_specified_type("iimage2DMSArray;"), |
| 1220 |
Ok((";", expected.clone())) |
| 1221 |
); |
| 1222 |
} |
| 1223 |
|
| 1224 |
#[test] |
| 1225 |
fn parse_fully_specified_type_with_qualifier() { |
| 1226 |
let qual_spec = syntax::TypeQualifierSpec::Storage(syntax::StorageQualifier::Subroutine(vec![ |
| 1227 |
"vec2".into(), |
| 1228 |
"S032_29k".into(), |
| 1229 |
])); |
| 1230 |
let qual = syntax::TypeQualifier { |
| 1231 |
qualifiers: syntax::NonEmpty(vec![qual_spec]), |
| 1232 |
}; |
| 1233 |
let ty = syntax::TypeSpecifier { |
| 1234 |
ty: syntax::TypeSpecifierNonArray::IImage2DMSArray, |
| 1235 |
array_specifier: None, |
| 1236 |
}; |
| 1237 |
let expected = syntax::FullySpecifiedType { |
| 1238 |
qualifier: Some(qual), |
| 1239 |
ty, |
| 1240 |
}; |
| 1241 |
|
| 1242 |
assert_eq!( |
| 1243 |
fully_specified_type("subroutine (vec2, S032_29k) iimage2DMSArray;"), |
| 1244 |
Ok((";", expected.clone())) |
| 1245 |
); |
| 1246 |
assert_eq!( |
| 1247 |
fully_specified_type("subroutine ( vec2\t\n \t , \n S032_29k )\n iimage2DMSArray ;"), |
| 1248 |
Ok((" ;", expected.clone())) |
| 1249 |
); |
| 1250 |
assert_eq!( |
| 1251 |
fully_specified_type("subroutine(vec2,S032_29k)iimage2DMSArray;"), |
| 1252 |
Ok((";", expected)) |
| 1253 |
); |
| 1254 |
} |
| 1255 |
|
| 1256 |
#[test] |
| 1257 |
fn parse_primary_expr_intconst() { |
| 1258 |
assert_eq!(primary_expr("0 "), Ok((" ", syntax::Expr::IntConst(0)))); |
| 1259 |
assert_eq!(primary_expr("1 "), Ok((" ", syntax::Expr::IntConst(1)))); |
| 1260 |
} |
| 1261 |
|
| 1262 |
#[test] |
| 1263 |
fn parse_primary_expr_uintconst() { |
| 1264 |
assert_eq!(primary_expr("0u "), Ok((" ", syntax::Expr::UIntConst(0)))); |
| 1265 |
assert_eq!(primary_expr("1u "), Ok((" ", syntax::Expr::UIntConst(1)))); |
| 1266 |
} |
| 1267 |
|
| 1268 |
#[test] |
| 1269 |
fn parse_primary_expr_floatconst() { |
| 1270 |
assert_eq!( |
| 1271 |
primary_expr("0.f "), |
| 1272 |
Ok((" ", syntax::Expr::FloatConst(0.))) |
| 1273 |
); |
| 1274 |
assert_eq!( |
| 1275 |
primary_expr("1.f "), |
| 1276 |
Ok((" ", syntax::Expr::FloatConst(1.))) |
| 1277 |
); |
| 1278 |
assert_eq!( |
| 1279 |
primary_expr("0.F "), |
| 1280 |
Ok((" ", syntax::Expr::FloatConst(0.))) |
| 1281 |
); |
| 1282 |
assert_eq!( |
| 1283 |
primary_expr("1.F "), |
| 1284 |
Ok((" ", syntax::Expr::FloatConst(1.))) |
| 1285 |
); |
| 1286 |
} |
| 1287 |
|
| 1288 |
#[test] |
| 1289 |
fn parse_primary_expr_doubleconst() { |
| 1290 |
assert_eq!(primary_expr("0. "), Ok((" ", syntax::Expr::FloatConst(0.)))); |
| 1291 |
assert_eq!(primary_expr("1. "), Ok((" ", syntax::Expr::FloatConst(1.)))); |
| 1292 |
assert_eq!( |
| 1293 |
primary_expr("0.lf "), |
| 1294 |
Ok((" ", syntax::Expr::DoubleConst(0.))) |
| 1295 |
); |
| 1296 |
assert_eq!( |
| 1297 |
primary_expr("1.lf "), |
| 1298 |
Ok((" ", syntax::Expr::DoubleConst(1.))) |
| 1299 |
); |
| 1300 |
assert_eq!( |
| 1301 |
primary_expr("0.LF "), |
| 1302 |
Ok((" ", syntax::Expr::DoubleConst(0.))) |
| 1303 |
); |
| 1304 |
assert_eq!( |
| 1305 |
primary_expr("1.LF "), |
| 1306 |
Ok((" ", syntax::Expr::DoubleConst(1.))) |
| 1307 |
); |
| 1308 |
} |
| 1309 |
|
| 1310 |
#[test] |
| 1311 |
fn parse_primary_expr_boolconst() { |
| 1312 |
assert_eq!( |
| 1313 |
primary_expr("false"), |
| 1314 |
Ok(("", syntax::Expr::BoolConst(false.to_owned()))) |
| 1315 |
); |
| 1316 |
assert_eq!( |
| 1317 |
primary_expr("true"), |
| 1318 |
Ok(("", syntax::Expr::BoolConst(true.to_owned()))) |
| 1319 |
); |
| 1320 |
} |
| 1321 |
|
| 1322 |
#[test] |
| 1323 |
fn parse_primary_expr_parens() { |
| 1324 |
assert_eq!(primary_expr("(0)"), Ok(("", syntax::Expr::IntConst(0)))); |
| 1325 |
assert_eq!(primary_expr("( 0 )"), Ok(("", syntax::Expr::IntConst(0)))); |
| 1326 |
assert_eq!( |
| 1327 |
primary_expr("( .0 )"), |
| 1328 |
Ok(("", syntax::Expr::FloatConst(0.))) |
| 1329 |
); |
| 1330 |
assert_eq!( |
| 1331 |
primary_expr("( (.0) )"), |
| 1332 |
Ok(("", syntax::Expr::FloatConst(0.))) |
| 1333 |
); |
| 1334 |
assert_eq!( |
| 1335 |
primary_expr("(true) "), |
| 1336 |
Ok((" ", syntax::Expr::BoolConst(true))) |
| 1337 |
); |
| 1338 |
} |
| 1339 |
|
| 1340 |
#[test] |
| 1341 |
fn parse_postfix_function_call_no_args() { |
| 1342 |
let fun = syntax::FunIdentifier::Identifier("vec3".into()); |
| 1343 |
let args = Vec::new(); |
| 1344 |
let expected = syntax::Expr::FunCall(fun, args); |
| 1345 |
|
| 1346 |
assert_eq!(postfix_expr("vec3();"), Ok((";", expected.clone()))); |
| 1347 |
assert_eq!(postfix_expr("vec3 ( ) ;"), Ok((" ;", expected.clone()))); |
| 1348 |
assert_eq!(postfix_expr("vec3 (\nvoid\n) ;"), Ok((" ;", expected))); |
| 1349 |
} |
| 1350 |
|
| 1351 |
#[test] |
| 1352 |
fn parse_postfix_function_call_one_arg() { |
| 1353 |
let fun = syntax::FunIdentifier::Identifier("foo".into()); |
| 1354 |
let args = vec![syntax::Expr::IntConst(0)]; |
| 1355 |
let expected = syntax::Expr::FunCall(fun, args); |
| 1356 |
|
| 1357 |
assert_eq!(postfix_expr("foo(0);"), Ok((";", expected.clone()))); |
| 1358 |
assert_eq!(postfix_expr("foo ( 0 ) ;"), Ok((" ;", expected.clone()))); |
| 1359 |
assert_eq!(postfix_expr("foo (\n0\t\n) ;"), Ok((" ;", expected))); |
| 1360 |
} |
| 1361 |
|
| 1362 |
#[test] |
| 1363 |
fn parse_postfix_function_call_multi_arg() { |
| 1364 |
let fun = syntax::FunIdentifier::Identifier("foo".into()); |
| 1365 |
let args = vec![ |
| 1366 |
syntax::Expr::IntConst(0), |
| 1367 |
syntax::Expr::BoolConst(false), |
| 1368 |
syntax::Expr::Variable("bar".into()), |
| 1369 |
]; |
| 1370 |
let expected = syntax::Expr::FunCall(fun, args); |
| 1371 |
|
| 1372 |
assert_eq!( |
| 1373 |
postfix_expr("foo(0, false, bar);"), |
| 1374 |
Ok((";", expected.clone())) |
| 1375 |
); |
| 1376 |
assert_eq!( |
| 1377 |
postfix_expr("foo ( 0\t, false ,\t\tbar) ;"), |
| 1378 |
Ok((" ;", expected)) |
| 1379 |
); |
| 1380 |
} |
| 1381 |
|
| 1382 |
#[test] |
| 1383 |
fn parse_postfix_expr_bracket() { |
| 1384 |
let id = syntax::Expr::Variable("foo".into()); |
| 1385 |
let array_spec = syntax::ArraySpecifier { |
| 1386 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::ExplicitlySized( |
| 1387 |
Box::new(syntax::Expr::IntConst(7354)), |
| 1388 |
)]), |
| 1389 |
}; |
| 1390 |
let expected = syntax::Expr::Bracket(Box::new(id), array_spec); |
| 1391 |
|
| 1392 |
assert_eq!(postfix_expr("foo[7354];"), Ok((";", expected.clone()))); |
| 1393 |
assert_eq!(postfix_expr("foo[\n 7354 ] ;"), Ok((";", expected))); |
| 1394 |
} |
| 1395 |
|
| 1396 |
#[test] |
| 1397 |
fn parse_postfix_expr_dot() { |
| 1398 |
let foo = Box::new(syntax::Expr::Variable("foo".into())); |
| 1399 |
let expected = syntax::Expr::Dot(foo, "bar".into()); |
| 1400 |
|
| 1401 |
assert_eq!(postfix_expr("foo.bar;"), Ok((";", expected.clone()))); |
| 1402 |
assert_eq!(postfix_expr("(foo).bar;"), Ok((";", expected))); |
| 1403 |
} |
| 1404 |
|
| 1405 |
#[test] |
| 1406 |
fn parse_postfix_expr_dot_several() { |
| 1407 |
let foo = Box::new(syntax::Expr::Variable("foo".into())); |
| 1408 |
let expected = syntax::Expr::Dot(Box::new(syntax::Expr::Dot(foo, "bar".into())), "zoo".into()); |
| 1409 |
|
| 1410 |
assert_eq!(postfix_expr("foo.bar.zoo;"), Ok((";", expected.clone()))); |
| 1411 |
assert_eq!(postfix_expr("(foo).bar.zoo;"), Ok((";", expected.clone()))); |
| 1412 |
assert_eq!(postfix_expr("(foo.bar).zoo;"), Ok((";", expected))); |
| 1413 |
} |
| 1414 |
|
| 1415 |
#[test] |
| 1416 |
fn parse_postfix_postinc() { |
| 1417 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1418 |
let expected = syntax::Expr::PostInc(Box::new(foo)); |
| 1419 |
|
| 1420 |
assert_eq!(postfix_expr("foo++;"), Ok((";", expected.clone()))); |
| 1421 |
} |
| 1422 |
|
| 1423 |
#[test] |
| 1424 |
fn parse_postfix_postdec() { |
| 1425 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1426 |
let expected = syntax::Expr::PostDec(Box::new(foo)); |
| 1427 |
|
| 1428 |
assert_eq!(postfix_expr("foo--;"), Ok((";", expected.clone()))); |
| 1429 |
} |
| 1430 |
|
| 1431 |
#[test] |
| 1432 |
fn parse_unary_add() { |
| 1433 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1434 |
let expected = syntax::Expr::Unary(syntax::UnaryOp::Add, Box::new(foo)); |
| 1435 |
|
| 1436 |
assert_eq!(unary_expr("+foo;"), Ok((";", expected.clone()))); |
| 1437 |
} |
| 1438 |
|
| 1439 |
#[test] |
| 1440 |
fn parse_unary_minus() { |
| 1441 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1442 |
let expected = syntax::Expr::Unary(syntax::UnaryOp::Minus, Box::new(foo)); |
| 1443 |
|
| 1444 |
assert_eq!(unary_expr("-foo;"), Ok((";", expected.clone()))); |
| 1445 |
} |
| 1446 |
|
| 1447 |
#[test] |
| 1448 |
fn parse_unary_not() { |
| 1449 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1450 |
let expected = syntax::Expr::Unary(syntax::UnaryOp::Not, Box::new(foo)); |
| 1451 |
|
| 1452 |
assert_eq!(unary_expr("!foo;"), Ok((";", expected))); |
| 1453 |
} |
| 1454 |
|
| 1455 |
#[test] |
| 1456 |
fn parse_unary_complement() { |
| 1457 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1458 |
let expected = syntax::Expr::Unary(syntax::UnaryOp::Complement, Box::new(foo)); |
| 1459 |
|
| 1460 |
assert_eq!(unary_expr("~foo;"), Ok((";", expected.clone()))); |
| 1461 |
} |
| 1462 |
|
| 1463 |
#[test] |
| 1464 |
fn parse_unary_inc() { |
| 1465 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1466 |
let expected = syntax::Expr::Unary(syntax::UnaryOp::Inc, Box::new(foo)); |
| 1467 |
|
| 1468 |
assert_eq!(unary_expr("++foo;"), Ok((";", expected.clone()))); |
| 1469 |
} |
| 1470 |
|
| 1471 |
#[test] |
| 1472 |
fn parse_unary_dec() { |
| 1473 |
let foo = syntax::Expr::Variable("foo".into()); |
| 1474 |
let expected = syntax::Expr::Unary(syntax::UnaryOp::Dec, Box::new(foo)); |
| 1475 |
|
| 1476 |
assert_eq!(unary_expr("--foo;"), Ok((";", expected.clone()))); |
| 1477 |
} |
| 1478 |
|
| 1479 |
#[test] |
| 1480 |
fn parse_expr_float() { |
| 1481 |
assert_eq!(expr("314.;"), Ok((";", syntax::Expr::FloatConst(314.)))); |
| 1482 |
assert_eq!(expr("314.f;"), Ok((";", syntax::Expr::FloatConst(314.)))); |
| 1483 |
assert_eq!(expr("314.LF;"), Ok((";", syntax::Expr::DoubleConst(314.)))); |
| 1484 |
} |
| 1485 |
|
| 1486 |
#[test] |
| 1487 |
fn parse_expr_add_2() { |
| 1488 |
let one = Box::new(syntax::Expr::IntConst(1)); |
| 1489 |
let expected = syntax::Expr::Binary(syntax::BinaryOp::Add, one.clone(), one); |
| 1490 |
|
| 1491 |
assert_eq!(expr("1 + 1;"), Ok((";", expected.clone()))); |
| 1492 |
assert_eq!(expr("1+1;"), Ok((";", expected.clone()))); |
| 1493 |
assert_eq!(expr("(1 + 1);"), Ok((";", expected))); |
| 1494 |
} |
| 1495 |
|
| 1496 |
#[test] |
| 1497 |
fn parse_expr_add_3() { |
| 1498 |
let one = Box::new(syntax::Expr::UIntConst(1)); |
| 1499 |
let two = Box::new(syntax::Expr::UIntConst(2)); |
| 1500 |
let three = Box::new(syntax::Expr::UIntConst(3)); |
| 1501 |
let expected = syntax::Expr::Binary( |
| 1502 |
syntax::BinaryOp::Add, |
| 1503 |
Box::new(syntax::Expr::Binary(syntax::BinaryOp::Add, one, two)), |
| 1504 |
three, |
| 1505 |
); |
| 1506 |
|
| 1507 |
assert_eq!(expr("1u + 2u + 3u"), Ok(("", expected.clone()))); |
| 1508 |
assert_eq!(expr("1u + 2u + 3u "), Ok((" ", expected.clone()))); |
| 1509 |
assert_eq!(expr("1u+2u+3u"), Ok(("", expected.clone()))); |
| 1510 |
assert_eq!(expr("((1u + 2u) + 3u)"), Ok(("", expected))); |
| 1511 |
} |
| 1512 |
|
| 1513 |
#[test] |
| 1514 |
fn parse_expr_add_mult_3() { |
| 1515 |
let one = Box::new(syntax::Expr::UIntConst(1)); |
| 1516 |
let two = Box::new(syntax::Expr::UIntConst(2)); |
| 1517 |
let three = Box::new(syntax::Expr::UIntConst(3)); |
| 1518 |
let expected = syntax::Expr::Binary( |
| 1519 |
syntax::BinaryOp::Add, |
| 1520 |
Box::new(syntax::Expr::Binary(syntax::BinaryOp::Mult, one, two)), |
| 1521 |
three, |
| 1522 |
); |
| 1523 |
|
| 1524 |
assert_eq!(expr("1u * 2u + 3u ;"), Ok((" ;", expected.clone()))); |
| 1525 |
assert_eq!(expr("1u*2u+3u;"), Ok((";", expected.clone()))); |
| 1526 |
assert_eq!(expr("(1u * 2u) + 3u;"), Ok((";", expected))); |
| 1527 |
} |
| 1528 |
|
| 1529 |
#[test] |
| 1530 |
fn parse_expr_add_sub_mult_div() { |
| 1531 |
let one = Box::new(syntax::Expr::IntConst(1)); |
| 1532 |
let two = Box::new(syntax::Expr::IntConst(2)); |
| 1533 |
let three = Box::new(syntax::Expr::IntConst(3)); |
| 1534 |
let four = Box::new(syntax::Expr::IntConst(4)); |
| 1535 |
let five = Box::new(syntax::Expr::IntConst(5)); |
| 1536 |
let six = Box::new(syntax::Expr::IntConst(6)); |
| 1537 |
let expected = syntax::Expr::Binary( |
| 1538 |
syntax::BinaryOp::Add, |
| 1539 |
Box::new(syntax::Expr::Binary( |
| 1540 |
syntax::BinaryOp::Mult, |
| 1541 |
one, |
| 1542 |
Box::new(syntax::Expr::Binary(syntax::BinaryOp::Add, two, three)), |
| 1543 |
)), |
| 1544 |
Box::new(syntax::Expr::Binary( |
| 1545 |
syntax::BinaryOp::Div, |
| 1546 |
four, |
| 1547 |
Box::new(syntax::Expr::Binary(syntax::BinaryOp::Add, five, six)), |
| 1548 |
)), |
| 1549 |
); |
| 1550 |
|
| 1551 |
assert_eq!( |
| 1552 |
expr("1 * (2 + 3) + 4 / (5 + 6);"), |
| 1553 |
Ok((";", expected.clone())) |
| 1554 |
); |
| 1555 |
} |
| 1556 |
|
| 1557 |
#[test] |
| 1558 |
fn parse_complex_expr() { |
| 1559 |
let input = "normalize((inverse(view) * vec4(ray.dir, 0.)).xyz);"; |
| 1560 |
let zero = syntax::Expr::FloatConst(0.); |
| 1561 |
let ray = syntax::Expr::Variable("ray".into()); |
| 1562 |
let raydir = syntax::Expr::Dot(Box::new(ray), "dir".into()); |
| 1563 |
let vec4 = syntax::Expr::FunCall( |
| 1564 |
syntax::FunIdentifier::Identifier("vec4".into()), |
| 1565 |
vec![raydir, zero], |
| 1566 |
); |
| 1567 |
let view = syntax::Expr::Variable("view".into()); |
| 1568 |
let iview = syntax::Expr::FunCall( |
| 1569 |
syntax::FunIdentifier::Identifier("inverse".into()), |
| 1570 |
vec![view], |
| 1571 |
); |
| 1572 |
let mul = syntax::Expr::Binary(syntax::BinaryOp::Mult, Box::new(iview), Box::new(vec4)); |
| 1573 |
let xyz = syntax::Expr::Dot(Box::new(mul), "xyz".into()); |
| 1574 |
let normalize = syntax::Expr::FunCall( |
| 1575 |
syntax::FunIdentifier::Identifier("normalize".into()), |
| 1576 |
vec![xyz], |
| 1577 |
); |
| 1578 |
let expected = normalize; |
| 1579 |
|
| 1580 |
assert_eq!(expr(&input[..]), Ok((";", expected))); |
| 1581 |
} |
| 1582 |
|
| 1583 |
#[test] |
| 1584 |
fn parse_function_identifier_typename() { |
| 1585 |
let expected = syntax::FunIdentifier::Identifier("foo".into()); |
| 1586 |
assert_eq!(function_identifier("foo("), Ok(("(", expected.clone()))); |
| 1587 |
assert_eq!(function_identifier("foo\n\t("), Ok(("(", expected.clone()))); |
| 1588 |
assert_eq!(function_identifier("foo\n ("), Ok(("(", expected))); |
| 1589 |
} |
| 1590 |
|
| 1591 |
#[test] |
| 1592 |
fn parse_function_identifier_cast() { |
| 1593 |
let expected = syntax::FunIdentifier::Identifier("vec3".into()); |
| 1594 |
assert_eq!(function_identifier("vec3("), Ok(("(", expected.clone()))); |
| 1595 |
assert_eq!(function_identifier("vec3 ("), Ok(("(", expected.clone()))); |
| 1596 |
assert_eq!(function_identifier("vec3\t\n\n \t ("), Ok(("(", expected))); |
| 1597 |
} |
| 1598 |
|
| 1599 |
#[test] |
| 1600 |
fn parse_function_identifier_cast_array_unsized() { |
| 1601 |
let expected = syntax::FunIdentifier::Expr(Box::new(syntax::Expr::Bracket( |
| 1602 |
Box::new(syntax::Expr::Variable("vec3".into())), |
| 1603 |
syntax::ArraySpecifier { |
| 1604 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::Unsized]), |
| 1605 |
}, |
| 1606 |
))); |
| 1607 |
|
| 1608 |
assert_eq!(function_identifier("vec3[]("), Ok(("(", expected.clone()))); |
| 1609 |
assert_eq!(function_identifier("vec3 [\t\n]("), Ok(("(", expected))); |
| 1610 |
} |
| 1611 |
|
| 1612 |
#[test] |
| 1613 |
fn parse_function_identifier_cast_array_sized() { |
| 1614 |
let expected = syntax::FunIdentifier::Expr(Box::new(syntax::Expr::Bracket( |
| 1615 |
Box::new(syntax::Expr::Variable("vec3".into())), |
| 1616 |
syntax::ArraySpecifier { |
| 1617 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::ExplicitlySized( |
| 1618 |
Box::new(syntax::Expr::IntConst(12)), |
| 1619 |
)]), |
| 1620 |
}, |
| 1621 |
))); |
| 1622 |
|
| 1623 |
assert_eq!( |
| 1624 |
function_identifier("vec3[12]("), |
| 1625 |
Ok(("(", expected.clone())) |
| 1626 |
); |
| 1627 |
assert_eq!(function_identifier("vec3 [\t 12\n]("), Ok(("(", expected))); |
| 1628 |
} |
| 1629 |
|
| 1630 |
#[test] |
| 1631 |
fn parse_void() { |
| 1632 |
assert_eq!(void("void "), Ok((" ", ()))); |
| 1633 |
} |
| 1634 |
|
| 1635 |
#[test] |
| 1636 |
fn parse_assignment_op_equal() { |
| 1637 |
assert_eq!(assignment_op("= "), Ok((" ", syntax::AssignmentOp::Equal))); |
| 1638 |
} |
| 1639 |
|
| 1640 |
#[test] |
| 1641 |
fn parse_assignment_op_mult() { |
| 1642 |
assert_eq!(assignment_op("*= "), Ok((" ", syntax::AssignmentOp::Mult))); |
| 1643 |
} |
| 1644 |
|
| 1645 |
#[test] |
| 1646 |
fn parse_assignment_op_div() { |
| 1647 |
assert_eq!(assignment_op("/= "), Ok((" ", syntax::AssignmentOp::Div))); |
| 1648 |
} |
| 1649 |
|
| 1650 |
#[test] |
| 1651 |
fn parse_assignment_op_mod() { |
| 1652 |
assert_eq!(assignment_op("%= "), Ok((" ", syntax::AssignmentOp::Mod))); |
| 1653 |
} |
| 1654 |
|
| 1655 |
#[test] |
| 1656 |
fn parse_assignment_op_add() { |
| 1657 |
assert_eq!(assignment_op("+= "), Ok((" ", syntax::AssignmentOp::Add))); |
| 1658 |
} |
| 1659 |
|
| 1660 |
#[test] |
| 1661 |
fn parse_assignment_op_sub() { |
| 1662 |
assert_eq!(assignment_op("-= "), Ok((" ", syntax::AssignmentOp::Sub))); |
| 1663 |
} |
| 1664 |
|
| 1665 |
#[test] |
| 1666 |
fn parse_assignment_op_lshift() { |
| 1667 |
assert_eq!( |
| 1668 |
assignment_op("<<= "), |
| 1669 |
Ok((" ", syntax::AssignmentOp::LShift)) |
| 1670 |
); |
| 1671 |
} |
| 1672 |
|
| 1673 |
#[test] |
| 1674 |
fn parse_assignment_op_rshift() { |
| 1675 |
assert_eq!( |
| 1676 |
assignment_op(">>= "), |
| 1677 |
Ok((" ", syntax::AssignmentOp::RShift)) |
| 1678 |
); |
| 1679 |
} |
| 1680 |
|
| 1681 |
#[test] |
| 1682 |
fn parse_assignment_op_and() { |
| 1683 |
assert_eq!(assignment_op("&= "), Ok((" ", syntax::AssignmentOp::And))); |
| 1684 |
} |
| 1685 |
|
| 1686 |
#[test] |
| 1687 |
fn parse_assignment_op_xor() { |
| 1688 |
assert_eq!(assignment_op("^= "), Ok((" ", syntax::AssignmentOp::Xor))); |
| 1689 |
} |
| 1690 |
|
| 1691 |
#[test] |
| 1692 |
fn parse_assignment_op_or() { |
| 1693 |
assert_eq!(assignment_op("|= "), Ok((" ", syntax::AssignmentOp::Or))); |
| 1694 |
} |
| 1695 |
|
| 1696 |
#[test] |
| 1697 |
fn parse_expr_statement() { |
| 1698 |
let expected = Some(syntax::Expr::Assignment( |
| 1699 |
Box::new(syntax::Expr::Variable("foo".into())), |
| 1700 |
syntax::AssignmentOp::Equal, |
| 1701 |
Box::new(syntax::Expr::FloatConst(314.)), |
| 1702 |
)); |
| 1703 |
|
| 1704 |
assert_eq!(expr_statement("foo = 314.f;"), Ok(("", expected.clone()))); |
| 1705 |
assert_eq!(expr_statement("foo=314.f;"), Ok(("", expected.clone()))); |
| 1706 |
assert_eq!(expr_statement("foo\n\t= \n314.f;"), Ok(("", expected))); |
| 1707 |
} |
| 1708 |
|
| 1709 |
#[test] |
| 1710 |
fn parse_declaration_function_prototype() { |
| 1711 |
let rt = syntax::FullySpecifiedType { |
| 1712 |
qualifier: None, |
| 1713 |
ty: syntax::TypeSpecifier { |
| 1714 |
ty: syntax::TypeSpecifierNonArray::Vec3, |
| 1715 |
array_specifier: None, |
| 1716 |
}, |
| 1717 |
}; |
| 1718 |
let arg0_ty = syntax::TypeSpecifier { |
| 1719 |
ty: syntax::TypeSpecifierNonArray::Vec2, |
| 1720 |
array_specifier: None, |
| 1721 |
}; |
| 1722 |
let arg0 = syntax::FunctionParameterDeclaration::Unnamed(None, arg0_ty); |
| 1723 |
let qual_spec = syntax::TypeQualifierSpec::Storage(syntax::StorageQualifier::Out); |
| 1724 |
let qual = syntax::TypeQualifier { |
| 1725 |
qualifiers: syntax::NonEmpty(vec![qual_spec]), |
| 1726 |
}; |
| 1727 |
let arg1 = syntax::FunctionParameterDeclaration::Named( |
| 1728 |
Some(qual), |
| 1729 |
syntax::FunctionParameterDeclarator { |
| 1730 |
ty: syntax::TypeSpecifier { |
| 1731 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 1732 |
array_specifier: None, |
| 1733 |
}, |
| 1734 |
ident: "the_arg".into(), |
| 1735 |
}, |
| 1736 |
); |
| 1737 |
let fp = syntax::FunctionPrototype { |
| 1738 |
ty: rt, |
| 1739 |
name: "foo".into(), |
| 1740 |
parameters: vec![arg0, arg1], |
| 1741 |
}; |
| 1742 |
let expected = syntax::Declaration::FunctionPrototype(fp); |
| 1743 |
|
| 1744 |
assert_eq!( |
| 1745 |
declaration("vec3 foo(vec2, out float the_arg);"), |
| 1746 |
Ok(("", expected.clone())) |
| 1747 |
); |
| 1748 |
assert_eq!( |
| 1749 |
declaration("vec3 \nfoo ( vec2\n, out float \n\tthe_arg )\n;"), |
| 1750 |
Ok(("", expected.clone())) |
| 1751 |
); |
| 1752 |
assert_eq!( |
| 1753 |
declaration("vec3 foo(vec2,out float the_arg);"), |
| 1754 |
Ok(("", expected)) |
| 1755 |
); |
| 1756 |
} |
| 1757 |
|
| 1758 |
#[test] |
| 1759 |
fn parse_declaration_init_declarator_list_single() { |
| 1760 |
let ty = syntax::FullySpecifiedType { |
| 1761 |
qualifier: None, |
| 1762 |
ty: syntax::TypeSpecifier { |
| 1763 |
ty: syntax::TypeSpecifierNonArray::Int, |
| 1764 |
array_specifier: None, |
| 1765 |
}, |
| 1766 |
}; |
| 1767 |
let sd = syntax::SingleDeclaration { |
| 1768 |
ty, |
| 1769 |
name: Some("foo".into()), |
| 1770 |
array_specifier: None, |
| 1771 |
initializer: Some(syntax::Initializer::Simple(Box::new( |
| 1772 |
syntax::Expr::IntConst(34), |
| 1773 |
))), |
| 1774 |
}; |
| 1775 |
let idl = syntax::InitDeclaratorList { |
| 1776 |
head: sd, |
| 1777 |
tail: Vec::new(), |
| 1778 |
}; |
| 1779 |
let expected = syntax::Declaration::InitDeclaratorList(idl); |
| 1780 |
|
| 1781 |
assert_eq!(declaration("int foo = 34;"), Ok(("", expected.clone()))); |
| 1782 |
assert_eq!(declaration("int foo=34;"), Ok(("", expected.clone()))); |
| 1783 |
assert_eq!(declaration("int \t \nfoo =\t34 ;"), Ok(("", expected))); |
| 1784 |
} |
| 1785 |
|
| 1786 |
#[test] |
| 1787 |
fn parse_declaration_init_declarator_list_complex() { |
| 1788 |
let ty = syntax::FullySpecifiedType { |
| 1789 |
qualifier: None, |
| 1790 |
ty: syntax::TypeSpecifier { |
| 1791 |
ty: syntax::TypeSpecifierNonArray::Int, |
| 1792 |
array_specifier: None, |
| 1793 |
}, |
| 1794 |
}; |
| 1795 |
let sd = syntax::SingleDeclaration { |
| 1796 |
ty, |
| 1797 |
name: Some("foo".into()), |
| 1798 |
array_specifier: None, |
| 1799 |
initializer: Some(syntax::Initializer::Simple(Box::new( |
| 1800 |
syntax::Expr::IntConst(34), |
| 1801 |
))), |
| 1802 |
}; |
| 1803 |
let sdnt = syntax::SingleDeclarationNoType { |
| 1804 |
ident: "bar".into(), |
| 1805 |
initializer: Some(syntax::Initializer::Simple(Box::new( |
| 1806 |
syntax::Expr::IntConst(12), |
| 1807 |
))), |
| 1808 |
}; |
| 1809 |
let expected = syntax::Declaration::InitDeclaratorList(syntax::InitDeclaratorList { |
| 1810 |
head: sd, |
| 1811 |
tail: vec![sdnt], |
| 1812 |
}); |
| 1813 |
|
| 1814 |
assert_eq!( |
| 1815 |
declaration("int foo = 34, bar = 12;"), |
| 1816 |
Ok(("", expected.clone())) |
| 1817 |
); |
| 1818 |
assert_eq!( |
| 1819 |
declaration("int foo=34,bar=12;"), |
| 1820 |
Ok(("", expected.clone())) |
| 1821 |
); |
| 1822 |
assert_eq!( |
| 1823 |
declaration("int \t \nfoo =\t34 \n,\tbar= 12\n ;"), |
| 1824 |
Ok(("", expected)) |
| 1825 |
); |
| 1826 |
} |
| 1827 |
|
| 1828 |
#[test] |
| 1829 |
fn parse_declaration_precision_low() { |
| 1830 |
let qual = syntax::PrecisionQualifier::Low; |
| 1831 |
let ty = syntax::TypeSpecifier { |
| 1832 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 1833 |
array_specifier: None, |
| 1834 |
}; |
| 1835 |
let expected = syntax::Declaration::Precision(qual, ty); |
| 1836 |
|
| 1837 |
assert_eq!(declaration("precision lowp float;"), Ok(("", expected))); |
| 1838 |
} |
| 1839 |
|
| 1840 |
#[test] |
| 1841 |
fn parse_declaration_precision_medium() { |
| 1842 |
let qual = syntax::PrecisionQualifier::Medium; |
| 1843 |
let ty = syntax::TypeSpecifier { |
| 1844 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 1845 |
array_specifier: None, |
| 1846 |
}; |
| 1847 |
let expected = syntax::Declaration::Precision(qual, ty); |
| 1848 |
|
| 1849 |
assert_eq!(declaration("precision mediump float;"), Ok(("", expected))); |
| 1850 |
} |
| 1851 |
|
| 1852 |
#[test] |
| 1853 |
fn parse_declaration_precision_high() { |
| 1854 |
let qual = syntax::PrecisionQualifier::High; |
| 1855 |
let ty = syntax::TypeSpecifier { |
| 1856 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 1857 |
array_specifier: None, |
| 1858 |
}; |
| 1859 |
let expected = syntax::Declaration::Precision(qual, ty); |
| 1860 |
|
| 1861 |
assert_eq!(declaration("precision highp float;"), Ok(("", expected))); |
| 1862 |
} |
| 1863 |
|
| 1864 |
#[test] |
| 1865 |
fn parse_declaration_uniform_block() { |
| 1866 |
let qual_spec = syntax::TypeQualifierSpec::Storage(syntax::StorageQualifier::Uniform); |
| 1867 |
let qual = syntax::TypeQualifier { |
| 1868 |
qualifiers: syntax::NonEmpty(vec![qual_spec]), |
| 1869 |
}; |
| 1870 |
let f0 = syntax::StructFieldSpecifier { |
| 1871 |
qualifier: None, |
| 1872 |
ty: syntax::TypeSpecifier { |
| 1873 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 1874 |
array_specifier: None, |
| 1875 |
}, |
| 1876 |
identifiers: syntax::NonEmpty(vec!["a".into()]), |
| 1877 |
}; |
| 1878 |
let f1 = syntax::StructFieldSpecifier { |
| 1879 |
qualifier: None, |
| 1880 |
ty: syntax::TypeSpecifier { |
| 1881 |
ty: syntax::TypeSpecifierNonArray::Vec3, |
| 1882 |
array_specifier: None, |
| 1883 |
}, |
| 1884 |
identifiers: syntax::NonEmpty(vec!["b".into()]), |
| 1885 |
}; |
| 1886 |
let f2 = syntax::StructFieldSpecifier { |
| 1887 |
qualifier: None, |
| 1888 |
ty: syntax::TypeSpecifier { |
| 1889 |
ty: syntax::TypeSpecifierNonArray::TypeName("foo".into()), |
| 1890 |
array_specifier: None, |
| 1891 |
}, |
| 1892 |
identifiers: syntax::NonEmpty(vec!["c".into(), "d".into()]), |
| 1893 |
}; |
| 1894 |
let expected = syntax::Declaration::Block(syntax::Block { |
| 1895 |
qualifier: qual, |
| 1896 |
name: "UniformBlockTest".into(), |
| 1897 |
fields: vec![f0, f1, f2], |
| 1898 |
identifier: None, |
| 1899 |
}); |
| 1900 |
|
| 1901 |
assert_eq!( |
| 1902 |
declaration("uniform UniformBlockTest { float a; vec3 b; foo c, d; };"), |
| 1903 |
Ok(("", expected.clone())) |
| 1904 |
); |
| 1905 |
assert_eq!(declaration("uniform \nUniformBlockTest\n {\n \t float a \n; \nvec3 b\n; foo \nc\n, \nd\n;\n }\n\t\n\t\t \t;"), Ok(("", expected))); |
| 1906 |
} |
| 1907 |
|
| 1908 |
#[test] |
| 1909 |
fn parse_declaration_buffer_block() { |
| 1910 |
let qual_spec = syntax::TypeQualifierSpec::Storage(syntax::StorageQualifier::Buffer); |
| 1911 |
let qual = syntax::TypeQualifier { |
| 1912 |
qualifiers: syntax::NonEmpty(vec![qual_spec]), |
| 1913 |
}; |
| 1914 |
let f0 = syntax::StructFieldSpecifier { |
| 1915 |
qualifier: None, |
| 1916 |
ty: syntax::TypeSpecifier { |
| 1917 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 1918 |
array_specifier: None, |
| 1919 |
}, |
| 1920 |
identifiers: syntax::NonEmpty(vec!["a".into()]), |
| 1921 |
}; |
| 1922 |
let f1 = syntax::StructFieldSpecifier { |
| 1923 |
qualifier: None, |
| 1924 |
ty: syntax::TypeSpecifier { |
| 1925 |
ty: syntax::TypeSpecifierNonArray::Vec3, |
| 1926 |
array_specifier: None, |
| 1927 |
}, |
| 1928 |
identifiers: syntax::NonEmpty(vec![syntax::ArrayedIdentifier::new( |
| 1929 |
"b", |
| 1930 |
Some(syntax::ArraySpecifier { |
| 1931 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::Unsized]), |
| 1932 |
}), |
| 1933 |
)]), |
| 1934 |
}; |
| 1935 |
let f2 = syntax::StructFieldSpecifier { |
| 1936 |
qualifier: None, |
| 1937 |
ty: syntax::TypeSpecifier { |
| 1938 |
ty: syntax::TypeSpecifierNonArray::TypeName("foo".into()), |
| 1939 |
array_specifier: None, |
| 1940 |
}, |
| 1941 |
identifiers: syntax::NonEmpty(vec!["c".into(), "d".into()]), |
| 1942 |
}; |
| 1943 |
let expected = syntax::Declaration::Block(syntax::Block { |
| 1944 |
qualifier: qual, |
| 1945 |
name: "UniformBlockTest".into(), |
| 1946 |
fields: vec![f0, f1, f2], |
| 1947 |
identifier: None, |
| 1948 |
}); |
| 1949 |
|
| 1950 |
assert_eq!( |
| 1951 |
declaration("buffer UniformBlockTest { float a; vec3 b[]; foo c, d; };"), |
| 1952 |
Ok(("", expected.clone())) |
| 1953 |
); |
| 1954 |
assert_eq!(declaration("buffer \nUniformBlockTest\n {\n \t float a \n; \nvec3 b [ ]\n; foo \nc\n, \nd\n;\n }\n\t\n\t\t \t;"), Ok(("", expected))); |
| 1955 |
} |
| 1956 |
|
| 1957 |
#[test] |
| 1958 |
fn parse_selection_statement_if() { |
| 1959 |
let cond = syntax::Expr::Binary( |
| 1960 |
syntax::BinaryOp::LT, |
| 1961 |
Box::new(syntax::Expr::Variable("foo".into())), |
| 1962 |
Box::new(syntax::Expr::IntConst(10)), |
| 1963 |
); |
| 1964 |
let ret = Box::new(syntax::Expr::BoolConst(false)); |
| 1965 |
let st = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Jump( |
| 1966 |
syntax::JumpStatement::Return(Some(ret)), |
| 1967 |
))); |
| 1968 |
let body = syntax::Statement::Compound(Box::new(syntax::CompoundStatement { |
| 1969 |
statement_list: vec![st], |
| 1970 |
})); |
| 1971 |
let rest = syntax::SelectionRestStatement::Statement(Box::new(body)); |
| 1972 |
let expected = syntax::SelectionStatement { |
| 1973 |
cond: Box::new(cond), |
| 1974 |
rest, |
| 1975 |
}; |
| 1976 |
|
| 1977 |
assert_eq!( |
| 1978 |
selection_statement("if (foo < 10) { return false; }K"), |
| 1979 |
Ok(("K", expected.clone())) |
| 1980 |
); |
| 1981 |
assert_eq!( |
| 1982 |
selection_statement("if \n(foo<10\n) \t{return false;}K"), |
| 1983 |
Ok(("K", expected)) |
| 1984 |
); |
| 1985 |
} |
| 1986 |
|
| 1987 |
#[test] |
| 1988 |
fn parse_selection_statement_if_else() { |
| 1989 |
let cond = syntax::Expr::Binary( |
| 1990 |
syntax::BinaryOp::LT, |
| 1991 |
Box::new(syntax::Expr::Variable("foo".into())), |
| 1992 |
Box::new(syntax::Expr::IntConst(10)), |
| 1993 |
); |
| 1994 |
let if_ret = Box::new(syntax::Expr::FloatConst(0.)); |
| 1995 |
let if_st = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Jump( |
| 1996 |
syntax::JumpStatement::Return(Some(if_ret)), |
| 1997 |
))); |
| 1998 |
let if_body = syntax::Statement::Compound(Box::new(syntax::CompoundStatement { |
| 1999 |
statement_list: vec![if_st], |
| 2000 |
})); |
| 2001 |
let else_ret = Box::new(syntax::Expr::Variable("foo".into())); |
| 2002 |
let else_st = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Jump( |
| 2003 |
syntax::JumpStatement::Return(Some(else_ret)), |
| 2004 |
))); |
| 2005 |
let else_body = syntax::Statement::Compound(Box::new(syntax::CompoundStatement { |
| 2006 |
statement_list: vec![else_st], |
| 2007 |
})); |
| 2008 |
let rest = syntax::SelectionRestStatement::Else(Box::new(if_body), Box::new(else_body)); |
| 2009 |
let expected = syntax::SelectionStatement { |
| 2010 |
cond: Box::new(cond), |
| 2011 |
rest, |
| 2012 |
}; |
| 2013 |
|
| 2014 |
assert_eq!( |
| 2015 |
selection_statement("if (foo < 10) { return 0.f; } else { return foo; }"), |
| 2016 |
Ok(("", expected.clone())) |
| 2017 |
); |
| 2018 |
assert_eq!( |
| 2019 |
selection_statement("if \n(foo<10\n) \t{return 0.f\t;\n\n}\n else{\n\t return foo ;}"), |
| 2020 |
Ok(("", expected)) |
| 2021 |
); |
| 2022 |
} |
| 2023 |
|
| 2024 |
#[test] |
| 2025 |
fn parse_switch_statement_empty() { |
| 2026 |
let head = Box::new(syntax::Expr::Variable("foo".into())); |
| 2027 |
let expected = syntax::SwitchStatement { |
| 2028 |
head, |
| 2029 |
body: Vec::new(), |
| 2030 |
}; |
| 2031 |
|
| 2032 |
assert_eq!( |
| 2033 |
switch_statement("switch (foo) {}"), |
| 2034 |
Ok(("", expected.clone())) |
| 2035 |
); |
| 2036 |
assert_eq!( |
| 2037 |
switch_statement("switch(foo){}"), |
| 2038 |
Ok(("", expected.clone())) |
| 2039 |
); |
| 2040 |
assert_eq!( |
| 2041 |
switch_statement("switch\n\n ( foo \t \n) { \n\n }"), |
| 2042 |
Ok(("", expected)) |
| 2043 |
); |
| 2044 |
} |
| 2045 |
|
| 2046 |
#[test] |
| 2047 |
fn parse_switch_statement_cases() { |
| 2048 |
let head = Box::new(syntax::Expr::Variable("foo".into())); |
| 2049 |
let case0 = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::CaseLabel( |
| 2050 |
syntax::CaseLabel::Case(Box::new(syntax::Expr::IntConst(0))), |
| 2051 |
))); |
| 2052 |
let case1 = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::CaseLabel( |
| 2053 |
syntax::CaseLabel::Case(Box::new(syntax::Expr::IntConst(1))), |
| 2054 |
))); |
| 2055 |
let ret = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Jump( |
| 2056 |
syntax::JumpStatement::Return(Some(Box::new(syntax::Expr::UIntConst(12)))), |
| 2057 |
))); |
| 2058 |
let expected = syntax::SwitchStatement { |
| 2059 |
head, |
| 2060 |
body: vec![case0, case1, ret], |
| 2061 |
}; |
| 2062 |
|
| 2063 |
assert_eq!( |
| 2064 |
switch_statement("switch (foo) { case 0: case 1: return 12u; }"), |
| 2065 |
Ok(("", expected.clone())) |
| 2066 |
); |
| 2067 |
} |
| 2068 |
|
| 2069 |
#[test] |
| 2070 |
fn parse_case_label_def() { |
| 2071 |
assert_eq!(case_label("default:"), Ok(("", syntax::CaseLabel::Def))); |
| 2072 |
assert_eq!(case_label("default :"), Ok(("", syntax::CaseLabel::Def))); |
| 2073 |
} |
| 2074 |
|
| 2075 |
#[test] |
| 2076 |
fn parse_case_label() { |
| 2077 |
let expected = syntax::CaseLabel::Case(Box::new(syntax::Expr::IntConst(3))); |
| 2078 |
|
| 2079 |
assert_eq!(case_label("case 3:"), Ok(("", expected.clone()))); |
| 2080 |
assert_eq!(case_label("case\n\t 3 :"), Ok(("", expected))); |
| 2081 |
} |
| 2082 |
|
| 2083 |
#[test] |
| 2084 |
fn parse_iteration_statement_while_empty() { |
| 2085 |
let cond = syntax::Condition::Expr(Box::new(syntax::Expr::Binary( |
| 2086 |
syntax::BinaryOp::GTE, |
| 2087 |
Box::new(syntax::Expr::Variable("a".into())), |
| 2088 |
Box::new(syntax::Expr::Variable("b".into())), |
| 2089 |
))); |
| 2090 |
let st = syntax::Statement::Compound(Box::new(syntax::CompoundStatement { |
| 2091 |
statement_list: Vec::new(), |
| 2092 |
})); |
| 2093 |
let expected = syntax::IterationStatement::While(cond, Box::new(st)); |
| 2094 |
|
| 2095 |
assert_eq!( |
| 2096 |
iteration_statement("while (a >= b) {}"), |
| 2097 |
Ok(("", expected.clone())) |
| 2098 |
); |
| 2099 |
assert_eq!( |
| 2100 |
iteration_statement("while(a>=b){}"), |
| 2101 |
Ok(("", expected.clone())) |
| 2102 |
); |
| 2103 |
assert_eq!( |
| 2104 |
iteration_statement("while ( a >=\n\tb )\t { \n}"), |
| 2105 |
Ok(("", expected)) |
| 2106 |
); |
| 2107 |
} |
| 2108 |
|
| 2109 |
#[test] |
| 2110 |
fn parse_iteration_statement_do_while_empty() { |
| 2111 |
let st = syntax::Statement::Compound(Box::new(syntax::CompoundStatement { |
| 2112 |
statement_list: Vec::new(), |
| 2113 |
})); |
| 2114 |
let cond = Box::new(syntax::Expr::Binary( |
| 2115 |
syntax::BinaryOp::GTE, |
| 2116 |
Box::new(syntax::Expr::Variable("a".into())), |
| 2117 |
Box::new(syntax::Expr::Variable("b".into())), |
| 2118 |
)); |
| 2119 |
let expected = syntax::IterationStatement::DoWhile(Box::new(st), cond); |
| 2120 |
|
| 2121 |
assert_eq!( |
| 2122 |
iteration_statement("do {} while (a >= b);"), |
| 2123 |
Ok(("", expected.clone())) |
| 2124 |
); |
| 2125 |
assert_eq!( |
| 2126 |
iteration_statement("do{}while(a>=b);"), |
| 2127 |
Ok(("", expected.clone())) |
| 2128 |
); |
| 2129 |
assert_eq!( |
| 2130 |
iteration_statement("do \n {\n} while ( a >=\n\tb )\t \n;"), |
| 2131 |
Ok(("", expected)) |
| 2132 |
); |
| 2133 |
} |
| 2134 |
|
| 2135 |
#[test] |
| 2136 |
fn parse_iteration_statement_for_empty() { |
| 2137 |
let init = syntax::ForInitStatement::Declaration(Box::new( |
| 2138 |
syntax::Declaration::InitDeclaratorList(syntax::InitDeclaratorList { |
| 2139 |
head: syntax::SingleDeclaration { |
| 2140 |
ty: syntax::FullySpecifiedType { |
| 2141 |
qualifier: None, |
| 2142 |
ty: syntax::TypeSpecifier { |
| 2143 |
ty: syntax::TypeSpecifierNonArray::Float, |
| 2144 |
array_specifier: None, |
| 2145 |
}, |
| 2146 |
}, |
| 2147 |
name: Some("i".into()), |
| 2148 |
array_specifier: None, |
| 2149 |
initializer: Some(syntax::Initializer::Simple(Box::new( |
| 2150 |
syntax::Expr::FloatConst(0.), |
| 2151 |
))), |
| 2152 |
}, |
| 2153 |
tail: Vec::new(), |
| 2154 |
}), |
| 2155 |
)); |
| 2156 |
let rest = syntax::ForRestStatement { |
| 2157 |
condition: Some(syntax::Condition::Expr(Box::new(syntax::Expr::Binary( |
| 2158 |
syntax::BinaryOp::LTE, |
| 2159 |
Box::new(syntax::Expr::Variable("i".into())), |
| 2160 |
Box::new(syntax::Expr::FloatConst(10.)), |
| 2161 |
)))), |
| 2162 |
post_expr: Some(Box::new(syntax::Expr::Unary( |
| 2163 |
syntax::UnaryOp::Inc, |
| 2164 |
Box::new(syntax::Expr::Variable("i".into())), |
| 2165 |
))), |
| 2166 |
}; |
| 2167 |
let st = syntax::Statement::Compound(Box::new(syntax::CompoundStatement { |
| 2168 |
statement_list: Vec::new(), |
| 2169 |
})); |
| 2170 |
let expected = syntax::IterationStatement::For(init, rest, Box::new(st)); |
| 2171 |
|
| 2172 |
assert_eq!( |
| 2173 |
iteration_statement("for (float i = 0.f; i <= 10.f; ++i) {}"), |
| 2174 |
Ok(("", expected.clone())) |
| 2175 |
); |
| 2176 |
assert_eq!( |
| 2177 |
iteration_statement("for(float i=0.f;i<=10.f;++i){}"), |
| 2178 |
Ok(("", expected.clone())) |
| 2179 |
); |
| 2180 |
assert_eq!( |
| 2181 |
iteration_statement("for\n\t ( \t\n\nfloat \ni \t=\n0.f\n;\ni\t<= 10.f; \n++i\n)\n{\n}"), |
| 2182 |
Ok(("", expected)) |
| 2183 |
); |
| 2184 |
} |
| 2185 |
|
| 2186 |
#[test] |
| 2187 |
fn parse_jump_continue() { |
| 2188 |
assert_eq!( |
| 2189 |
jump_statement("continue;"), |
| 2190 |
Ok(("", syntax::JumpStatement::Continue)) |
| 2191 |
); |
| 2192 |
} |
| 2193 |
|
| 2194 |
#[test] |
| 2195 |
fn parse_jump_break() { |
| 2196 |
assert_eq!( |
| 2197 |
jump_statement("break;"), |
| 2198 |
Ok(("", syntax::JumpStatement::Break)) |
| 2199 |
); |
| 2200 |
} |
| 2201 |
|
| 2202 |
#[test] |
| 2203 |
fn parse_jump_return() { |
| 2204 |
let expected = syntax::JumpStatement::Return(Some(Box::new(syntax::Expr::IntConst(3)))); |
| 2205 |
assert_eq!(jump_statement("return 3;"), Ok(("", expected))); |
| 2206 |
} |
| 2207 |
|
| 2208 |
#[test] |
| 2209 |
fn parse_jump_empty_return() { |
| 2210 |
let expected = syntax::SimpleStatement::Jump(syntax::JumpStatement::Return(None)); |
| 2211 |
assert_eq!(simple_statement("return;"), Ok(("", expected))); |
| 2212 |
} |
| 2213 |
|
| 2214 |
#[test] |
| 2215 |
fn parse_jump_discard() { |
| 2216 |
assert_eq!( |
| 2217 |
jump_statement("discard;"), |
| 2218 |
Ok(("", syntax::JumpStatement::Discard)) |
| 2219 |
); |
| 2220 |
} |
| 2221 |
|
| 2222 |
#[test] |
| 2223 |
fn parse_simple_statement_return() { |
| 2224 |
let e = syntax::Expr::BoolConst(false); |
| 2225 |
let expected = syntax::SimpleStatement::Jump(syntax::JumpStatement::Return(Some(Box::new(e)))); |
| 2226 |
|
| 2227 |
assert_eq!(simple_statement("return false;"), Ok(("", expected))); |
| 2228 |
} |
| 2229 |
|
| 2230 |
#[test] |
| 2231 |
fn parse_compound_statement_empty() { |
| 2232 |
let expected = syntax::CompoundStatement { |
| 2233 |
statement_list: Vec::new(), |
| 2234 |
}; |
| 2235 |
|
| 2236 |
assert_eq!(compound_statement("{}"), Ok(("", expected))); |
| 2237 |
} |
| 2238 |
|
| 2239 |
#[test] |
| 2240 |
fn parse_compound_statement() { |
| 2241 |
let st0 = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Selection( |
| 2242 |
syntax::SelectionStatement { |
| 2243 |
cond: Box::new(syntax::Expr::BoolConst(true)), |
| 2244 |
rest: syntax::SelectionRestStatement::Statement(Box::new(syntax::Statement::Compound( |
| 2245 |
Box::new(syntax::CompoundStatement { |
| 2246 |
statement_list: Vec::new(), |
| 2247 |
}), |
| 2248 |
))), |
| 2249 |
}, |
| 2250 |
))); |
| 2251 |
let st1 = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Declaration( |
| 2252 |
syntax::Declaration::InitDeclaratorList(syntax::InitDeclaratorList { |
| 2253 |
head: syntax::SingleDeclaration { |
| 2254 |
ty: syntax::FullySpecifiedType { |
| 2255 |
qualifier: None, |
| 2256 |
ty: syntax::TypeSpecifier { |
| 2257 |
ty: syntax::TypeSpecifierNonArray::ISampler3D, |
| 2258 |
array_specifier: None, |
| 2259 |
}, |
| 2260 |
}, |
| 2261 |
name: Some("x".into()), |
| 2262 |
array_specifier: None, |
| 2263 |
initializer: None, |
| 2264 |
}, |
| 2265 |
tail: Vec::new(), |
| 2266 |
}), |
| 2267 |
))); |
| 2268 |
let st2 = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Jump( |
| 2269 |
syntax::JumpStatement::Return(Some(Box::new(syntax::Expr::IntConst(42)))), |
| 2270 |
))); |
| 2271 |
let expected = syntax::CompoundStatement { |
| 2272 |
statement_list: vec![st0, st1, st2], |
| 2273 |
}; |
| 2274 |
|
| 2275 |
assert_eq!( |
| 2276 |
compound_statement("{ if (true) {} isampler3D x; return 42 ; }"), |
| 2277 |
Ok(("", expected.clone())) |
| 2278 |
); |
| 2279 |
assert_eq!( |
| 2280 |
compound_statement("{if(true){}isampler3D x;return 42;}"), |
| 2281 |
Ok(("", expected)) |
| 2282 |
); |
| 2283 |
} |
| 2284 |
|
| 2285 |
#[test] |
| 2286 |
fn parse_function_definition() { |
| 2287 |
let rt = syntax::FullySpecifiedType { |
| 2288 |
qualifier: None, |
| 2289 |
ty: syntax::TypeSpecifier { |
| 2290 |
ty: syntax::TypeSpecifierNonArray::IImage2DArray, |
| 2291 |
array_specifier: None, |
| 2292 |
}, |
| 2293 |
}; |
| 2294 |
let fp = syntax::FunctionPrototype { |
| 2295 |
ty: rt, |
| 2296 |
name: "foo".into(), |
| 2297 |
parameters: Vec::new(), |
| 2298 |
}; |
| 2299 |
let st0 = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Jump( |
| 2300 |
syntax::JumpStatement::Return(Some(Box::new(syntax::Expr::Variable("bar".into())))), |
| 2301 |
))); |
| 2302 |
let expected = syntax::FunctionDefinition { |
| 2303 |
prototype: fp, |
| 2304 |
statement: syntax::CompoundStatement { |
| 2305 |
statement_list: vec![st0], |
| 2306 |
}, |
| 2307 |
}; |
| 2308 |
|
| 2309 |
assert_eq!( |
| 2310 |
function_definition("iimage2DArray foo() { return bar; }"), |
| 2311 |
Ok(("", expected.clone())) |
| 2312 |
); |
| 2313 |
assert_eq!( |
| 2314 |
function_definition("iimage2DArray \tfoo\n()\n \n{\n return \nbar\n;}"), |
| 2315 |
Ok(("", expected.clone())) |
| 2316 |
); |
| 2317 |
assert_eq!( |
| 2318 |
function_definition("iimage2DArray foo(){return bar;}"), |
| 2319 |
Ok(("", expected)) |
| 2320 |
); |
| 2321 |
} |
| 2322 |
|
| 2323 |
#[test] |
| 2324 |
fn parse_buffer_block_0() { |
| 2325 |
let src = include_str!("../data/tests/buffer_block_0.glsl"); |
| 2326 |
let main_fn = syntax::ExternalDeclaration::FunctionDefinition(syntax::FunctionDefinition { |
| 2327 |
prototype: syntax::FunctionPrototype { |
| 2328 |
ty: syntax::FullySpecifiedType { |
| 2329 |
qualifier: None, |
| 2330 |
ty: syntax::TypeSpecifier { |
| 2331 |
ty: syntax::TypeSpecifierNonArray::Void, |
| 2332 |
array_specifier: None, |
| 2333 |
}, |
| 2334 |
}, |
| 2335 |
name: "main".into(), |
| 2336 |
parameters: Vec::new(), |
| 2337 |
}, |
| 2338 |
statement: syntax::CompoundStatement { |
| 2339 |
statement_list: Vec::new(), |
| 2340 |
}, |
| 2341 |
}); |
| 2342 |
let buffer_block = |
| 2343 |
syntax::ExternalDeclaration::Declaration(syntax::Declaration::Block(syntax::Block { |
| 2344 |
qualifier: syntax::TypeQualifier { |
| 2345 |
qualifiers: syntax::NonEmpty(vec![syntax::TypeQualifierSpec::Storage( |
| 2346 |
syntax::StorageQualifier::Buffer, |
| 2347 |
)]), |
| 2348 |
}, |
| 2349 |
name: "Foo".into(), |
| 2350 |
fields: vec![syntax::StructFieldSpecifier { |
| 2351 |
qualifier: None, |
| 2352 |
ty: syntax::TypeSpecifier { |
| 2353 |
ty: syntax::TypeSpecifierNonArray::TypeName("char".into()), |
| 2354 |
array_specifier: None, |
| 2355 |
}, |
| 2356 |
identifiers: syntax::NonEmpty(vec![syntax::ArrayedIdentifier::new( |
| 2357 |
"tiles", |
| 2358 |
Some(syntax::ArraySpecifier { |
| 2359 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::Unsized]), |
| 2360 |
}), |
| 2361 |
)]), |
| 2362 |
}], |
| 2363 |
identifier: Some("main_tiles".into()), |
| 2364 |
})); |
| 2365 |
let expected = syntax::TranslationUnit(syntax::NonEmpty(vec![buffer_block, main_fn])); |
| 2366 |
|
| 2367 |
assert_eq!(translation_unit(src), Ok(("", expected))); |
| 2368 |
} |
| 2369 |
|
| 2370 |
#[test] |
| 2371 |
fn parse_layout_buffer_block_0() { |
| 2372 |
let src = include_str!("../data/tests/layout_buffer_block_0.glsl"); |
| 2373 |
let layout = syntax::LayoutQualifier { |
| 2374 |
ids: syntax::NonEmpty(vec![ |
| 2375 |
syntax::LayoutQualifierSpec::Identifier( |
| 2376 |
"set".into(), |
| 2377 |
Some(Box::new(syntax::Expr::IntConst(0))), |
| 2378 |
), |
| 2379 |
syntax::LayoutQualifierSpec::Identifier( |
| 2380 |
"binding".into(), |
| 2381 |
Some(Box::new(syntax::Expr::IntConst(0))), |
| 2382 |
), |
| 2383 |
]), |
| 2384 |
}; |
| 2385 |
let type_qual = syntax::TypeQualifier { |
| 2386 |
qualifiers: syntax::NonEmpty(vec![ |
| 2387 |
syntax::TypeQualifierSpec::Layout(layout), |
| 2388 |
syntax::TypeQualifierSpec::Storage(syntax::StorageQualifier::Buffer), |
| 2389 |
]), |
| 2390 |
}; |
| 2391 |
let block = syntax::ExternalDeclaration::Declaration(syntax::Declaration::Block(syntax::Block { |
| 2392 |
qualifier: type_qual, |
| 2393 |
name: "Foo".into(), |
| 2394 |
fields: vec![syntax::StructFieldSpecifier { |
| 2395 |
qualifier: None, |
| 2396 |
ty: syntax::TypeSpecifier { |
| 2397 |
ty: syntax::TypeSpecifierNonArray::TypeName("char".into()), |
| 2398 |
array_specifier: None, |
| 2399 |
}, |
| 2400 |
identifiers: syntax::NonEmpty(vec!["a".into()]), |
| 2401 |
}], |
| 2402 |
identifier: Some("foo".into()), |
| 2403 |
})); |
| 2404 |
|
| 2405 |
let expected = syntax::TranslationUnit(syntax::NonEmpty(vec![block])); |
| 2406 |
|
| 2407 |
assert_eq!(translation_unit(src), Ok(("", expected))); |
| 2408 |
} |
| 2409 |
|
| 2410 |
#[test] |
| 2411 |
fn parse_pp_space0() { |
| 2412 |
assert_eq!(pp_space0(" \\\n "), Ok(("", " \\\n "))); |
| 2413 |
assert_eq!(pp_space0(""), Ok(("", ""))); |
| 2414 |
} |
| 2415 |
|
| 2416 |
#[test] |
| 2417 |
fn parse_pp_version_number() { |
| 2418 |
assert_eq!(pp_version_number("450"), Ok(("", 450))); |
| 2419 |
} |
| 2420 |
|
| 2421 |
#[test] |
| 2422 |
fn parse_pp_version_profile() { |
| 2423 |
assert_eq!( |
| 2424 |
pp_version_profile("core"), |
| 2425 |
Ok(("", syntax::PreprocessorVersionProfile::Core)) |
| 2426 |
); |
| 2427 |
assert_eq!( |
| 2428 |
pp_version_profile("compatibility"), |
| 2429 |
Ok(("", syntax::PreprocessorVersionProfile::Compatibility)) |
| 2430 |
); |
| 2431 |
assert_eq!( |
| 2432 |
pp_version_profile("es"), |
| 2433 |
Ok(("", syntax::PreprocessorVersionProfile::ES)) |
| 2434 |
); |
| 2435 |
} |
| 2436 |
|
| 2437 |
#[test] |
| 2438 |
fn parse_pp_version() { |
| 2439 |
assert_eq!( |
| 2440 |
preprocessor("#version 450\n"), |
| 2441 |
Ok(( |
| 2442 |
"", |
| 2443 |
syntax::Preprocessor::Version(syntax::PreprocessorVersion { |
| 2444 |
version: 450, |
| 2445 |
profile: None, |
| 2446 |
}) |
| 2447 |
)) |
| 2448 |
); |
| 2449 |
|
| 2450 |
assert_eq!( |
| 2451 |
preprocessor("#version 450 core\n"), |
| 2452 |
Ok(( |
| 2453 |
"", |
| 2454 |
syntax::Preprocessor::Version(syntax::PreprocessorVersion { |
| 2455 |
version: 450, |
| 2456 |
profile: Some(syntax::PreprocessorVersionProfile::Core) |
| 2457 |
}) |
| 2458 |
)) |
| 2459 |
); |
| 2460 |
} |
| 2461 |
|
| 2462 |
#[test] |
| 2463 |
fn parse_pp_version_newline() { |
| 2464 |
assert_eq!( |
| 2465 |
preprocessor("#version 450\n"), |
| 2466 |
Ok(( |
| 2467 |
"", |
| 2468 |
syntax::Preprocessor::Version(syntax::PreprocessorVersion { |
| 2469 |
version: 450, |
| 2470 |
profile: None, |
| 2471 |
}) |
| 2472 |
)) |
| 2473 |
); |
| 2474 |
|
| 2475 |
assert_eq!( |
| 2476 |
preprocessor("#version 450 core\n"), |
| 2477 |
Ok(( |
| 2478 |
"", |
| 2479 |
syntax::Preprocessor::Version(syntax::PreprocessorVersion { |
| 2480 |
version: 450, |
| 2481 |
profile: Some(syntax::PreprocessorVersionProfile::Core) |
| 2482 |
}) |
| 2483 |
)) |
| 2484 |
); |
| 2485 |
} |
| 2486 |
|
| 2487 |
#[test] |
| 2488 |
fn parse_pp_define() { |
| 2489 |
let expect = |v: &str| { |
| 2490 |
Ok(( |
| 2491 |
"", |
| 2492 |
syntax::Preprocessor::Define(syntax::PreprocessorDefine::ObjectLike { |
| 2493 |
ident: "test".into(), |
| 2494 |
value: v.to_owned(), |
| 2495 |
}), |
| 2496 |
)) |
| 2497 |
}; |
| 2498 |
|
| 2499 |
assert_eq!(preprocessor("#define test 1.0"), expect("1.0")); |
| 2500 |
assert_eq!(preprocessor("#define test \\\n 1.0"), expect("1.0")); |
| 2501 |
assert_eq!(preprocessor("#define test 1.0\n"), expect("1.0")); |
| 2502 |
|
| 2503 |
assert_eq!( |
| 2504 |
preprocessor("#define test123 .0f\n"), |
| 2505 |
Ok(( |
| 2506 |
"", |
| 2507 |
syntax::Preprocessor::Define(syntax::PreprocessorDefine::ObjectLike { |
| 2508 |
ident: "test123".into(), |
| 2509 |
value: ".0f".to_owned() |
| 2510 |
}) |
| 2511 |
)) |
| 2512 |
); |
| 2513 |
|
| 2514 |
assert_eq!( |
| 2515 |
preprocessor("#define test 1\n"), |
| 2516 |
Ok(( |
| 2517 |
"", |
| 2518 |
syntax::Preprocessor::Define(syntax::PreprocessorDefine::ObjectLike { |
| 2519 |
ident: "test".into(), |
| 2520 |
value: "1".to_owned() |
| 2521 |
}) |
| 2522 |
)) |
| 2523 |
); |
| 2524 |
} |
| 2525 |
|
| 2526 |
#[test] |
| 2527 |
fn parse_pp_define_with_args() { |
| 2528 |
let expected = syntax::Preprocessor::Define(syntax::PreprocessorDefine::FunctionLike { |
| 2529 |
ident: "add".into(), |
| 2530 |
args: vec![ |
| 2531 |
syntax::Identifier::new("x").unwrap(), |
| 2532 |
syntax::Identifier::new("y").unwrap(), |
| 2533 |
], |
| 2534 |
value: "(x + y)".to_owned(), |
| 2535 |
}); |
| 2536 |
|
| 2537 |
assert_eq!( |
| 2538 |
preprocessor("#define \\\n add(x, y) \\\n (x + y)"), |
| 2539 |
Ok(("", expected.clone())) |
| 2540 |
); |
| 2541 |
|
| 2542 |
assert_eq!( |
| 2543 |
preprocessor("#define \\\n add( x, y ) \\\n (x + y)"), |
| 2544 |
Ok(("", expected)) |
| 2545 |
); |
| 2546 |
} |
| 2547 |
|
| 2548 |
#[test] |
| 2549 |
fn parse_pp_define_multiline() { |
| 2550 |
assert_eq!( |
| 2551 |
preprocessor( |
| 2552 |
r#"#define foo \ |
| 2553 |
32"# |
| 2554 |
), |
| 2555 |
Ok(( |
| 2556 |
"", |
| 2557 |
syntax::Preprocessor::Define(syntax::PreprocessorDefine::ObjectLike { |
| 2558 |
ident: "foo".into(), |
| 2559 |
value: "32".to_owned(), |
| 2560 |
}) |
| 2561 |
)) |
| 2562 |
); |
| 2563 |
} |
| 2564 |
|
| 2565 |
#[test] |
| 2566 |
fn parse_pp_else() { |
| 2567 |
assert_eq!( |
| 2568 |
preprocessor("# else\n"), |
| 2569 |
Ok(("", syntax::Preprocessor::Else)) |
| 2570 |
); |
| 2571 |
} |
| 2572 |
|
| 2573 |
#[test] |
| 2574 |
fn parse_pp_elseif() { |
| 2575 |
assert_eq!( |
| 2576 |
preprocessor("# elseif \\\n42\n"), |
| 2577 |
Ok(( |
| 2578 |
"", |
| 2579 |
syntax::Preprocessor::ElseIf(syntax::PreprocessorElseIf { |
| 2580 |
condition: "42".to_owned() |
| 2581 |
}) |
| 2582 |
)) |
| 2583 |
); |
| 2584 |
} |
| 2585 |
|
| 2586 |
#[test] |
| 2587 |
fn parse_pp_endif() { |
| 2588 |
assert_eq!( |
| 2589 |
preprocessor("#\\\nendif"), |
| 2590 |
Ok(("", syntax::Preprocessor::EndIf)) |
| 2591 |
); |
| 2592 |
} |
| 2593 |
|
| 2594 |
#[test] |
| 2595 |
fn parse_pp_error() { |
| 2596 |
assert_eq!( |
| 2597 |
preprocessor("#error \\\n some message"), |
| 2598 |
Ok(( |
| 2599 |
"", |
| 2600 |
syntax::Preprocessor::Error(syntax::PreprocessorError { |
| 2601 |
message: "some message".to_owned() |
| 2602 |
}) |
| 2603 |
)) |
| 2604 |
); |
| 2605 |
} |
| 2606 |
|
| 2607 |
#[test] |
| 2608 |
fn parse_pp_if() { |
| 2609 |
assert_eq!( |
| 2610 |
preprocessor("# \\\nif 42"), |
| 2611 |
Ok(( |
| 2612 |
"", |
| 2613 |
syntax::Preprocessor::If(syntax::PreprocessorIf { |
| 2614 |
condition: "42".to_owned() |
| 2615 |
}) |
| 2616 |
)) |
| 2617 |
); |
| 2618 |
} |
| 2619 |
|
| 2620 |
#[test] |
| 2621 |
fn parse_pp_ifdef() { |
| 2622 |
assert_eq!( |
| 2623 |
preprocessor("#ifdef FOO\n"), |
| 2624 |
Ok(( |
| 2625 |
"", |
| 2626 |
syntax::Preprocessor::IfDef(syntax::PreprocessorIfDef { |
| 2627 |
ident: syntax::Identifier("FOO".to_owned()) |
| 2628 |
}) |
| 2629 |
)) |
| 2630 |
); |
| 2631 |
} |
| 2632 |
|
| 2633 |
#[test] |
| 2634 |
fn parse_pp_ifndef() { |
| 2635 |
assert_eq!( |
| 2636 |
preprocessor("#\\\nifndef \\\n FOO\n"), |
| 2637 |
Ok(( |
| 2638 |
"", |
| 2639 |
syntax::Preprocessor::IfNDef(syntax::PreprocessorIfNDef { |
| 2640 |
ident: syntax::Identifier("FOO".to_owned()) |
| 2641 |
}) |
| 2642 |
)) |
| 2643 |
); |
| 2644 |
} |
| 2645 |
|
| 2646 |
#[test] |
| 2647 |
fn parse_pp_include() { |
| 2648 |
assert_eq!( |
| 2649 |
preprocessor("#include <filename>\n"), |
| 2650 |
Ok(( |
| 2651 |
"", |
| 2652 |
syntax::Preprocessor::Include(syntax::PreprocessorInclude { |
| 2653 |
path: syntax::Path::Absolute("filename".to_owned()) |
| 2654 |
}) |
| 2655 |
)) |
| 2656 |
); |
| 2657 |
|
| 2658 |
assert_eq!( |
| 2659 |
preprocessor("#include \\\n\"filename\"\n"), |
| 2660 |
Ok(( |
| 2661 |
"", |
| 2662 |
syntax::Preprocessor::Include(syntax::PreprocessorInclude { |
| 2663 |
path: syntax::Path::Relative("filename".to_owned()) |
| 2664 |
}) |
| 2665 |
)) |
| 2666 |
); |
| 2667 |
} |
| 2668 |
|
| 2669 |
#[test] |
| 2670 |
fn parse_pp_line() { |
| 2671 |
assert_eq!( |
| 2672 |
preprocessor("# line \\\n2\n"), |
| 2673 |
Ok(( |
| 2674 |
"", |
| 2675 |
syntax::Preprocessor::Line(syntax::PreprocessorLine { |
| 2676 |
line: 2, |
| 2677 |
source_string_number: None, |
| 2678 |
}) |
| 2679 |
)) |
| 2680 |
); |
| 2681 |
|
| 2682 |
assert_eq!( |
| 2683 |
preprocessor("#line 2 \\\n 4\n"), |
| 2684 |
Ok(( |
| 2685 |
"", |
| 2686 |
syntax::Preprocessor::Line(syntax::PreprocessorLine { |
| 2687 |
line: 2, |
| 2688 |
source_string_number: Some(4), |
| 2689 |
}) |
| 2690 |
)) |
| 2691 |
); |
| 2692 |
} |
| 2693 |
|
| 2694 |
#[test] |
| 2695 |
fn parse_pp_pragma() { |
| 2696 |
assert_eq!( |
| 2697 |
preprocessor("#\\\npragma some flag"), |
| 2698 |
Ok(( |
| 2699 |
"", |
| 2700 |
syntax::Preprocessor::Pragma(syntax::PreprocessorPragma { |
| 2701 |
command: "some flag".to_owned() |
| 2702 |
}) |
| 2703 |
)) |
| 2704 |
); |
| 2705 |
} |
| 2706 |
|
| 2707 |
#[test] |
| 2708 |
fn parse_pp_undef() { |
| 2709 |
assert_eq!( |
| 2710 |
preprocessor("# undef \\\n FOO"), |
| 2711 |
Ok(( |
| 2712 |
"", |
| 2713 |
syntax::Preprocessor::Undef(syntax::PreprocessorUndef { |
| 2714 |
name: syntax::Identifier("FOO".to_owned()) |
| 2715 |
}) |
| 2716 |
)) |
| 2717 |
); |
| 2718 |
} |
| 2719 |
|
| 2720 |
#[test] |
| 2721 |
fn parse_pp_extension_name() { |
| 2722 |
assert_eq!( |
| 2723 |
pp_extension_name("all"), |
| 2724 |
Ok(("", syntax::PreprocessorExtensionName::All)) |
| 2725 |
); |
| 2726 |
assert_eq!( |
| 2727 |
pp_extension_name("GL_foobar_extension "), |
| 2728 |
Ok(( |
| 2729 |
" ", |
| 2730 |
syntax::PreprocessorExtensionName::Specific("GL_foobar_extension".to_owned()) |
| 2731 |
)) |
| 2732 |
); |
| 2733 |
} |
| 2734 |
|
| 2735 |
#[test] |
| 2736 |
fn parse_pp_extension_behavior() { |
| 2737 |
assert_eq!( |
| 2738 |
pp_extension_behavior("require"), |
| 2739 |
Ok(("", syntax::PreprocessorExtensionBehavior::Require)) |
| 2740 |
); |
| 2741 |
assert_eq!( |
| 2742 |
pp_extension_behavior("enable"), |
| 2743 |
Ok(("", syntax::PreprocessorExtensionBehavior::Enable)) |
| 2744 |
); |
| 2745 |
assert_eq!( |
| 2746 |
pp_extension_behavior("warn"), |
| 2747 |
Ok(("", syntax::PreprocessorExtensionBehavior::Warn)) |
| 2748 |
); |
| 2749 |
assert_eq!( |
| 2750 |
pp_extension_behavior("disable"), |
| 2751 |
Ok(("", syntax::PreprocessorExtensionBehavior::Disable)) |
| 2752 |
); |
| 2753 |
} |
| 2754 |
|
| 2755 |
#[test] |
| 2756 |
fn parse_pp_extension() { |
| 2757 |
assert_eq!( |
| 2758 |
preprocessor("#extension all: require\n"), |
| 2759 |
Ok(( |
| 2760 |
"", |
| 2761 |
syntax::Preprocessor::Extension(syntax::PreprocessorExtension { |
| 2762 |
name: syntax::PreprocessorExtensionName::All, |
| 2763 |
behavior: Some(syntax::PreprocessorExtensionBehavior::Require) |
| 2764 |
}) |
| 2765 |
)) |
| 2766 |
); |
| 2767 |
} |
| 2768 |
|
| 2769 |
#[test] |
| 2770 |
fn parse_dot_field_expr_array() { |
| 2771 |
let src = "a[0].xyz;"; |
| 2772 |
let expected = syntax::Expr::Dot( |
| 2773 |
Box::new(syntax::Expr::Bracket( |
| 2774 |
Box::new(syntax::Expr::Variable("a".into())), |
| 2775 |
syntax::ArraySpecifier { |
| 2776 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::ExplicitlySized( |
| 2777 |
Box::new(syntax::Expr::IntConst(0)), |
| 2778 |
)]), |
| 2779 |
}, |
| 2780 |
)), |
| 2781 |
"xyz".into(), |
| 2782 |
); |
| 2783 |
|
| 2784 |
assert_eq!(expr(src), Ok((";", expected))); |
| 2785 |
} |
| 2786 |
|
| 2787 |
#[test] |
| 2788 |
fn parse_dot_field_expr_statement() { |
| 2789 |
let src = "vec3 v = smoothstep(vec3(border_width), vec3(0.0), v_barycenter).zyx;"; |
| 2790 |
let fun = syntax::FunIdentifier::Identifier("smoothstep".into()); |
| 2791 |
let args = vec![ |
| 2792 |
syntax::Expr::FunCall( |
| 2793 |
syntax::FunIdentifier::Identifier("vec3".into()), |
| 2794 |
vec![syntax::Expr::Variable("border_width".into())], |
| 2795 |
), |
| 2796 |
syntax::Expr::FunCall( |
| 2797 |
syntax::FunIdentifier::Identifier("vec3".into()), |
| 2798 |
vec![syntax::Expr::FloatConst(0.)], |
| 2799 |
), |
| 2800 |
syntax::Expr::Variable("v_barycenter".into()), |
| 2801 |
]; |
| 2802 |
let ini = syntax::Initializer::Simple(Box::new(syntax::Expr::Dot( |
| 2803 |
Box::new(syntax::Expr::FunCall(fun, args)), |
| 2804 |
"zyx".into(), |
| 2805 |
))); |
| 2806 |
let sd = syntax::SingleDeclaration { |
| 2807 |
ty: syntax::FullySpecifiedType { |
| 2808 |
qualifier: None, |
| 2809 |
ty: syntax::TypeSpecifier { |
| 2810 |
ty: syntax::TypeSpecifierNonArray::Vec3, |
| 2811 |
array_specifier: None, |
| 2812 |
}, |
| 2813 |
}, |
| 2814 |
name: Some("v".into()), |
| 2815 |
array_specifier: None, |
| 2816 |
initializer: Some(ini), |
| 2817 |
}; |
| 2818 |
let expected = syntax::Statement::Simple(Box::new(syntax::SimpleStatement::Declaration( |
| 2819 |
syntax::Declaration::InitDeclaratorList(syntax::InitDeclaratorList { |
| 2820 |
head: sd, |
| 2821 |
tail: Vec::new(), |
| 2822 |
}), |
| 2823 |
))); |
| 2824 |
|
| 2825 |
assert_eq!(statement(src), Ok(("", expected))); |
| 2826 |
} |
| 2827 |
|
| 2828 |
#[test] |
| 2829 |
fn parse_arrayed_identifier() { |
| 2830 |
let expected = syntax::ArrayedIdentifier::new( |
| 2831 |
"foo", |
| 2832 |
syntax::ArraySpecifier { |
| 2833 |
dimensions: syntax::NonEmpty(vec![syntax::ArraySpecifierDimension::Unsized]), |
| 2834 |
}, |
| 2835 |
); |
| 2836 |
|
| 2837 |
assert_eq!(arrayed_identifier("foo[]"), Ok(("", expected.clone()))); |
| 2838 |
assert_eq!(arrayed_identifier("foo \t\n [\n\t ]"), Ok(("", expected))); |
| 2839 |
} |
| 2840 |
|
| 2841 |
#[test] |
| 2842 |
fn parse_nested_parens() { |
| 2843 |
let start = std::time::Instant::now(); |
| 2844 |
parens_expr("((((((((1.0f))))))))").unwrap(); |
| 2845 |
let elapsed = start.elapsed(); |
| 2846 |
assert!(elapsed.as_millis() < 100, "{} ms", elapsed.as_millis()); |
| 2847 |
} |