@@ -40,6 +40,7 @@ def test_view_file(editor):
40
40
assert f"Here's the result of running `cat -n` on { test_file } :" in result .output
41
41
assert '1\t This is a test file.' in result .output
42
42
assert '2\t This file is for testing purposes.' in result .output
43
+ assert '3\t ' not in result .output # No extra line
43
44
44
45
45
46
def test_view_directory (editor ):
@@ -54,6 +55,30 @@ def test_view_directory(editor):
54
55
)
55
56
56
57
58
+ def test_view_with_a_specific_range (editor ):
59
+ editor , test_file = editor
60
+
61
+ # Replace the current content with content: Line {line_number}
62
+ _ = editor (
63
+ command = 'str_replace' ,
64
+ path = str (test_file ),
65
+ old_str = 'This is a test file.\n This file is for testing purposes.' ,
66
+ new_str = '' ,
67
+ )
68
+ for i in range (0 , 200 ):
69
+ _ = editor (
70
+ command = 'insert' , path = str (test_file ), insert_line = i , new_str = f'Line { i + 1 } '
71
+ )
72
+
73
+ # View file in range 50-100
74
+ result = editor (command = 'view' , path = str (test_file ), view_range = [50 , 100 ])
75
+ assert f"Here's the result of running `cat -n` on { test_file } :" in result .output
76
+ assert ' 49\t Line 49' not in result .output
77
+ assert ' 50\t Line 50' in result .output
78
+ assert ' 100\t Line 100' in result .output
79
+ assert '101' not in result .output
80
+
81
+
57
82
def test_create_file (editor ):
58
83
editor , test_file = editor
59
84
new_file = test_file .parent / 'new_file.txt'
@@ -73,6 +98,11 @@ def test_create_with_empty_string(editor):
73
98
assert new_file .read_text () == ''
74
99
assert 'File created successfully' in result .output
75
100
101
+ # Test the view command showing an empty line
102
+ result = editor (command = 'view' , path = str (new_file ))
103
+ assert f"Here's the result of running `cat -n` on { new_file } :" in result .output
104
+ assert '1\t ' in result .output # Check for empty line
105
+
76
106
77
107
def test_create_with_none_file_text (editor ):
78
108
editor , test_file = editor
@@ -100,7 +130,6 @@ def test_str_replace_no_linting(editor):
100
130
2\t This file is for testing purposes.
101
131
Review the changes and make sure they are as expected. Edit the file again if necessary."""
102
132
)
103
- print (result .output )
104
133
105
134
# Test that the file content has been updated
106
135
assert 'This is a sample file.' in test_file .read_text ()
@@ -265,7 +294,6 @@ def test_insert_no_linting(editor):
265
294
)
266
295
assert isinstance (result , CLIResult )
267
296
assert 'Inserted line' in test_file .read_text ()
268
- print (result .output )
269
297
assert (
270
298
result .output
271
299
== f"""The file { test_file } has been edited. Here's the result of running `cat -n` on a snippet of the edited file:
@@ -287,7 +315,6 @@ def test_insert_with_linting(editor):
287
315
)
288
316
assert isinstance (result , CLIResult )
289
317
assert 'Inserted line' in test_file .read_text ()
290
- print (result .output )
291
318
assert (
292
319
result .output
293
320
== f"""The file { test_file } has been edited. Here's the result of running `cat -n` on a snippet of the edited file:
0 commit comments