use super::*;
use expect_test::expect;
#[tokio::test]
async fn did_change_pushes_on_parse_error_introduction() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\nfunction ok(): void {}\n").await;
let notif = s.change("a.php", 2, "<?php\nclass {\n").await;
expect![[r#"
1:6-1:7 [1] SyntaxError: expected class name, found '{'
2:0-2:1 [1] SyntaxError: expected '}', found end of file"#]]
.assert_eq(&render_diagnostics_notification(¬if));
}
#[tokio::test]
async fn did_change_pushes_empty_after_parse_error_fixed() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\nclass {\n").await;
let notif = s.change("a.php", 2, "<?php\nclass Foo {}\n").await;
expect!["<empty>"].assert_eq(&render_diagnostics_notification(¬if));
}
#[tokio::test]
async fn did_change_pushes_on_semantic_error_introduction() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\n").await;
let notif = s.change("a.php", 2, "<?php\nundefined_fn();\n").await;
expect!["1:0-1:14 [1] UndefinedFunction: Function undefined_fn() is not defined"]
.assert_eq(&render_diagnostics_notification(¬if));
}
#[tokio::test]
async fn did_change_pushes_empty_after_semantic_error_fixed() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\nundefined_fn();\n").await;
let notif = s
.change("a.php", 2, "<?php\nfunction defined_fn(): void {}\n")
.await;
expect!["<empty>"].assert_eq(&render_diagnostics_notification(¬if));
}
#[tokio::test]
async fn did_change_push_replaces_entire_prior_set() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\nclass {\n").await;
let notif = s.change("a.php", 2, "<?php\nmissing_fn();\n").await;
expect!["1:0-1:12 [1] UndefinedFunction: Function missing_fn() is not defined"]
.assert_eq(&render_diagnostics_notification(¬if));
}
#[tokio::test]
async fn did_change_push_replaces_semantic_with_parse_errors() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\ngone_fn();\n").await;
let notif = s.change("a.php", 2, "<?php\nclass {\n").await;
expect![[r#"
1:6-1:7 [1] SyntaxError: expected class name, found '{'
2:0-2:1 [1] SyntaxError: expected '}', found end of file"#]]
.assert_eq(&render_diagnostics_notification(¬if));
}
#[tokio::test]
async fn did_change_push_reflects_final_change_state() {
let mut s = TestServer::new().await;
s.open("a.php", "<?php\n").await;
s.change("a.php", 2, "<?php\nbad_fn();\n").await;
let notif = s
.change("a.php", 3, "<?php\nfunction good(): void {}\n")
.await;
expect!["<empty>"].assert_eq(&render_diagnostics_notification(¬if));
}