()
| 330 | |
| 331 | #[test] |
| 332 | fn readonly_parameter() { |
| 333 | let code = indoc! {r#" |
| 334 | function foo(bar: readonly string) {} |
| 335 | "#}; |
| 336 | |
| 337 | let tree = init_parser().parse(code, None).unwrap(); |
| 338 | let mut cursor = tree.root_node().walk(); |
| 339 | walk_tree_to_function(&mut cursor); |
| 340 | |
| 341 | let symbol = parse( |
| 342 | &cursor.node(), |
| 343 | &mut ParserContext::new(Path::new("index.ts"), code), |
| 344 | ) |
| 345 | .unwrap(); |
| 346 | |
| 347 | let function = symbol.kind.as_function().unwrap(); |
| 348 | |
| 349 | let params = function.parameters().collect::<Vec<_>>(); |
| 350 | assert_eq!(params.len(), 1); |
| 351 | |
| 352 | let bar = params[0].kind.as_parameter().unwrap(); |
| 353 | assert_eq!(bar.identifier, "bar"); |
| 354 | assert!(bar.readonly); |
| 355 | assert!(!bar.optional); |
| 356 | assert_eq!( |
| 357 | bar.parameter_type().unwrap().kind.as_type().unwrap(), |
| 358 | &Type::Predefined("string".to_owned()) |
| 359 | ); |
| 360 | } |
| 361 | |
| 362 | #[test] |
| 363 | fn generics() { |
nothing calls this directly
no test coverage detected