integration_bash.rs
1 mod common; 2 use common::TestFixture; 3 use ecolog_lsp::server::handlers::{compute_diagnostics, handle_hover}; 4 use tower_lsp::lsp_types::{ 5 HoverParams, Position, TextDocumentIdentifier, TextDocumentPositionParams, 6 }; 7 8 #[tokio::test] 9 async fn test_bash_hover_simple_expansion() { 10 let fixture = TestFixture::new().await; 11 let uri = fixture.create_file("script.sh", r#"echo $DB_URL"#); 12 13 fixture 14 .state 15 .document_manager 16 .open( 17 uri.clone(), 18 "shellscript".to_string(), 19 r#"echo $DB_URL"#.to_string(), 20 0, 21 ) 22 .await; 23 24 let hover = handle_hover( 25 HoverParams { 26 text_document_position_params: TextDocumentPositionParams { 27 text_document: TextDocumentIdentifier { uri }, 28 position: Position::new(0, 8), 29 }, 30 work_done_progress_params: Default::default(), 31 }, 32 &fixture.state, 33 ) 34 .await; 35 36 assert!(hover.is_some(), "Expected hover for $DB_URL"); 37 assert!(format!("{:?}", hover.unwrap()).contains("postgres://")); 38 } 39 40 #[tokio::test] 41 async fn test_bash_hover_brace_expansion() { 42 let fixture = TestFixture::new().await; 43 let uri = fixture.create_file("script.sh", r#"echo ${API_KEY}"#); 44 45 fixture 46 .state 47 .document_manager 48 .open( 49 uri.clone(), 50 "shellscript".to_string(), 51 r#"echo ${API_KEY}"#.to_string(), 52 0, 53 ) 54 .await; 55 56 let hover = handle_hover( 57 HoverParams { 58 text_document_position_params: TextDocumentPositionParams { 59 text_document: TextDocumentIdentifier { uri }, 60 position: Position::new(0, 9), 61 }, 62 work_done_progress_params: Default::default(), 63 }, 64 &fixture.state, 65 ) 66 .await; 67 68 assert!(hover.is_some(), "Expected hover for ${{API_KEY}}"); 69 assert!(format!("{:?}", hover.unwrap()).contains("secret_key")); 70 } 71 72 #[tokio::test] 73 async fn test_bash_hover_default_value() { 74 let fixture = TestFixture::new().await; 75 let uri = fixture.create_file("script.sh", r#"echo ${DEBUG:-false}"#); 76 77 fixture 78 .state 79 .document_manager 80 .open( 81 uri.clone(), 82 "shellscript".to_string(), 83 r#"echo ${DEBUG:-false}"#.to_string(), 84 0, 85 ) 86 .await; 87 88 let hover = handle_hover( 89 HoverParams { 90 text_document_position_params: TextDocumentPositionParams { 91 text_document: TextDocumentIdentifier { uri }, 92 position: Position::new(0, 9), 93 }, 94 work_done_progress_params: Default::default(), 95 }, 96 &fixture.state, 97 ) 98 .await; 99 100 assert!(hover.is_some(), "Expected hover for ${{DEBUG:-false}}"); 101 assert!(format!("{:?}", hover.unwrap()).contains("true")); 102 } 103 104 #[tokio::test] 105 async fn test_bash_diagnostics_undefined() { 106 let fixture = TestFixture::new().await; 107 let uri = fixture.create_file("script.sh", r#"echo $UNDEFINED_VAR"#); 108 109 fixture 110 .state 111 .document_manager 112 .open( 113 uri.clone(), 114 "shellscript".to_string(), 115 r#"echo $UNDEFINED_VAR"#.to_string(), 116 0, 117 ) 118 .await; 119 120 let diags = compute_diagnostics(&uri, &fixture.state).await; 121 122 assert!(!diags.is_empty()); 123 assert!(diags.iter().any(|d| d.message.contains("not defined"))); 124 } 125 126 #[tokio::test] 127 async fn test_bash_multiple_expansions() { 128 let fixture = TestFixture::new().await; 129 let uri = fixture.create_file("script.sh", r#"echo $DB_URL ${API_KEY}"#); 130 131 fixture 132 .state 133 .document_manager 134 .open( 135 uri.clone(), 136 "shellscript".to_string(), 137 r#"echo $DB_URL ${API_KEY}"#.to_string(), 138 0, 139 ) 140 .await; 141 142 // Check first expansion 143 let hover1 = handle_hover( 144 HoverParams { 145 text_document_position_params: TextDocumentPositionParams { 146 text_document: TextDocumentIdentifier { uri: uri.clone() }, 147 position: Position::new(0, 8), 148 }, 149 work_done_progress_params: Default::default(), 150 }, 151 &fixture.state, 152 ) 153 .await; 154 155 assert!(hover1.is_some(), "Expected hover for $DB_URL"); 156 assert!(format!("{:?}", hover1.unwrap()).contains("postgres://")); 157 158 // Check second expansion 159 let hover2 = handle_hover( 160 HoverParams { 161 text_document_position_params: TextDocumentPositionParams { 162 text_document: TextDocumentIdentifier { uri }, 163 position: Position::new(0, 18), 164 }, 165 work_done_progress_params: Default::default(), 166 }, 167 &fixture.state, 168 ) 169 .await; 170 171 assert!(hover2.is_some(), "Expected hover for ${{API_KEY}}"); 172 assert!(format!("{:?}", hover2.unwrap()).contains("secret_key")); 173 }