|
1 | 1 | use crate::declaration_files::models::CollectionKind; |
2 | | -use crate::declaration_files::tests::helpers::parsed_debug; |
3 | | -use crate::declaration_files::tests::test_types::DeclarationTextTestCase; |
| 2 | +use crate::declaration_files::tests::helpers::{nesting_failure_debug, parsed_debug}; |
| 3 | +use crate::declaration_files::tests::test_types::{ |
| 4 | + DeclarationTextTestCase, DeepDeclarationTestCase, |
| 5 | +}; |
4 | 6 |
|
5 | 7 | #[test] |
6 | 8 | fn given_declaration_files_when_parsing_then_values_and_failures_match_python() { |
@@ -213,3 +215,56 @@ fn given_declaration_files_when_parsing_then_values_and_failures_match_python() |
213 | 215 | ); |
214 | 216 | } |
215 | 217 | } |
| 218 | + |
| 219 | +#[test] |
| 220 | +fn given_deeply_nested_declaration_headers_when_parsing_then_each_reports_its_file_line() { |
| 221 | + let test_cases = [ |
| 222 | + DeepDeclarationTestCase { |
| 223 | + description: "a constant value", |
| 224 | + kind: CollectionKind::Constants, |
| 225 | + prefix: "CONSTANT (\n name limits,\n value ", |
| 226 | + suffix: ",\n);\n", |
| 227 | + expected_location: ("CONSTANT", 3), |
| 228 | + }, |
| 229 | + DeepDeclarationTestCase { |
| 230 | + description: "a hook description", |
| 231 | + kind: CollectionKind::SqlHooks, |
| 232 | + prefix: "HOOK (\n description ", |
| 233 | + suffix: ",\n);\n\nSELECT 1\n", |
| 234 | + expected_location: ("HOOK", 2), |
| 235 | + }, |
| 236 | + DeepDeclarationTestCase { |
| 237 | + description: "a function return type", |
| 238 | + kind: CollectionKind::SqlFunctions, |
| 239 | + prefix: "FUNCTION (\n description \"Whether placed\",\n returns ", |
| 240 | + suffix: ",\n);\n\norder_status = 'placed'\n", |
| 241 | + expected_location: ("FUNCTION", 3), |
| 242 | + }, |
| 243 | + DeepDeclarationTestCase { |
| 244 | + description: "an audit value on a later block", |
| 245 | + kind: CollectionKind::Audits, |
| 246 | + prefix: "AUDIT (name a);\nSELECT 1\nAUDIT (\n name b,\n value ", |
| 247 | + suffix: ",\n);\nSELECT 2\n", |
| 248 | + expected_location: ("AUDIT", 5), |
| 249 | + }, |
| 250 | + ]; |
| 251 | + |
| 252 | + for test_case in test_cases { |
| 253 | + let contents: String = format!( |
| 254 | + "{}{}1{}{}", |
| 255 | + test_case.prefix, |
| 256 | + "[".repeat(20_000), |
| 257 | + "]".repeat(20_000), |
| 258 | + test_case.suffix |
| 259 | + ); |
| 260 | + |
| 261 | + let debug: String = parsed_debug(test_case.kind, &contents); |
| 262 | + |
| 263 | + assert_eq!( |
| 264 | + debug, |
| 265 | + nesting_failure_debug(test_case.expected_location), |
| 266 | + "{}", |
| 267 | + test_case.description |
| 268 | + ); |
| 269 | + } |
| 270 | +} |
0 commit comments