-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added functionality for moving code block and deleting code block. #13
Open
RajWorking
wants to merge
7
commits into
main
Choose a base branch
from
rj/move_code_blk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+184
−32
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c38d5a
Added functionality for moving code block and deleting code block.
RajWorking a75945e
Minor bug fixes and added tests.
RajWorking 57fba09
.
RajWorking 182079c
lint
RajWorking 6cd591b
Made some fixes
RajWorking 8aa3577
lint errors
RajWorking 68da3cd
lint errors
RajWorking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,73 @@ def test_insert_with_linting(editor): | |
) | ||
|
||
|
||
def test_delete_block(editor): | ||
editor, test_file = editor | ||
test_file.write_text( | ||
'This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz' | ||
) | ||
result = editor( | ||
command='delete', | ||
path=str(test_file), | ||
lines_range=[2, 3], | ||
) | ||
assert isinstance(result, CLIResult) | ||
assert 'foo' not in test_file.read_text() | ||
assert 'bar' not in test_file.read_text() | ||
print(result.output) | ||
assert ( | ||
result.output | ||
== f"""The file {test_file} has been edited. Here's the result of running `cat -n` on a snippet of the edited file: | ||
1\tThis is a test file. | ||
2\tThis file is for testing purposes. | ||
3\tbaz | ||
Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" | ||
) | ||
|
||
|
||
def test_move_code_block(editor): | ||
editor, test_file = editor | ||
test_file.write_text( | ||
'This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz' | ||
) | ||
|
||
second_test_file = test_file.parent / 'second_test.txt' | ||
second_test_file.write_text( | ||
'This is also a test file.\nSome text should be added above this.' | ||
) | ||
|
||
result = editor( | ||
command='move_code_block', | ||
path=str(test_file), | ||
dst_path=str(second_test_file), | ||
lines_range=[2, 3], | ||
insert_line=1, | ||
) | ||
assert isinstance(result, CLIResult) | ||
assert 'foo' not in test_file.read_text() | ||
assert 'bar' not in test_file.read_text() | ||
assert 'foo' in second_test_file.read_text() | ||
assert 'bar' in second_test_file.read_text() | ||
print(result.output) | ||
assert ( | ||
result.output | ||
== f"""Code block moved from {test_file} to {second_test_file}. | ||
The file {test_file} has been edited. Here's the result of running `cat -n` on a snippet of the edited file: | ||
1\tThis is a test file. | ||
2\tThis file is for testing purposes. | ||
3\tbaz | ||
Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary. | ||
The file {second_test_file} has been edited. Here's the result of running `cat -n` on a snippet of the edited file: | ||
1\tThis is also a test file. | ||
2\tfoo | ||
3\tbar | ||
4\tSome text should be added above this. | ||
|
||
No linting issues found in the changes. | ||
Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test case for delete as well? |
||
|
||
def test_insert_invalid_line(editor): | ||
editor, test_file = editor | ||
with pytest.raises(EditorToolParameterInvalidError) as exc_info: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do validation for the command to make sure path is not a directory? (And maybe a test case for it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we are doing that above.