diff --git a/src/domain/models/editor.rs b/src/domain/models/editor.rs index 8fbf5ef..c31e64b 100644 --- a/src/domain/models/editor.rs +++ b/src/domain/models/editor.rs @@ -56,7 +56,7 @@ impl EditorContext { let language = &self.language; let code = &self.code; - if code.is_empty() { + if code.is_empty() || self.end_line.is_none() { return format!("File: {file_path}"); } diff --git a/src/domain/models/editor_test.rs b/src/domain/models/editor_test.rs index 3417237..f995800 100644 --- a/src/domain/models/editor_test.rs +++ b/src/domain/models/editor_test.rs @@ -14,7 +14,7 @@ fn it_renders_with_no_code() { } #[test] -fn it_renders_with_code() { +fn it_renders_with_file_path() { let context = EditorContext { file_path: "file.rs".to_string(), language: "rust".to_string(), @@ -23,6 +23,19 @@ fn it_renders_with_code() { end_line: None, }; + insta::assert_snapshot!(context.format(), @"File: file.rs"); +} + +#[test] +fn it_renders_with_code() { + let context = EditorContext { + file_path: "file.rs".to_string(), + language: "rust".to_string(), + code: "let x = 5;".to_string(), + start_line: 0, + end_line: Some(1), + }; + insta::assert_snapshot!(context.format(), @r###" File: file.rs