()
| 474 | |
| 475 | #[test] |
| 476 | fn parse_file_messages() { |
| 477 | let json = r#"{ |
| 478 | "totals": {"errors": 1, "warnings": 1, "fixable": 2}, |
| 479 | "files": { |
| 480 | "/project/src/Foo.php": { |
| 481 | "errors": 1, |
| 482 | "warnings": 1, |
| 483 | "messages": [ |
| 484 | { |
| 485 | "message": "Line indented incorrectly; expected 4 spaces, found 2", |
| 486 | "source": "PSR2.Methods.FunctionCallSignature.Indent", |
| 487 | "severity": 5, |
| 488 | "fixable": true, |
| 489 | "type": "ERROR", |
| 490 | "line": 42, |
| 491 | "column": 1 |
| 492 | }, |
| 493 | { |
| 494 | "message": "Missing file doc comment", |
| 495 | "source": "PEAR.Commenting.FileComment.Missing", |
| 496 | "severity": 5, |
| 497 | "fixable": false, |
| 498 | "type": "WARNING", |
| 499 | "line": 1, |
| 500 | "column": 1 |
| 501 | } |
| 502 | ] |
| 503 | } |
| 504 | } |
| 505 | }"#; |
| 506 | let path = Path::new("/project/src/Foo.php"); |
| 507 | let diags = parse_phpcs_json(json, path).unwrap(); |
| 508 | assert_eq!(diags.len(), 2); |
| 509 | |
| 510 | // First diagnostic — ERROR, full-line range |
| 511 | assert_eq!(diags[0].range.start.line, 41); // 42 - 1 |
| 512 | assert_eq!(diags[0].range.start.character, 0); |
| 513 | assert_eq!(diags[0].range.end.line, 41); |
| 514 | assert_eq!(diags[0].range.end.character, u32::MAX); |
| 515 | assert_eq!(diags[0].severity, Some(DiagnosticSeverity::ERROR)); |
| 516 | assert_eq!(diags[0].source.as_deref(), Some("phpcs")); |
| 517 | assert_eq!( |
| 518 | diags[0].code, |
| 519 | Some(NumberOrString::String( |
| 520 | "PSR2.Methods.FunctionCallSignature.Indent".to_string() |
| 521 | )) |
| 522 | ); |
| 523 | assert!(diags[0].message.contains("Line indented incorrectly")); |
| 524 | assert_eq!(diags[0].data, Some(serde_json::json!({ "fixable": true }))); |
| 525 | |
| 526 | // Second diagnostic — WARNING |
| 527 | assert_eq!(diags[1].range.start.line, 0); // 1 - 1 |
| 528 | assert_eq!(diags[1].range.end.character, u32::MAX); |
| 529 | assert_eq!(diags[1].severity, Some(DiagnosticSeverity::WARNING)); |
| 530 | assert_eq!( |
| 531 | diags[1].code, |
| 532 | Some(NumberOrString::String( |
| 533 | "PEAR.Commenting.FileComment.Missing".to_string() |
nothing calls this directly
no test coverage detected