-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix the bug for "bytes remove --end" . #11428
Conversation
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.
Hi, thanks for your contribution! It'd be good to add a test for such behavior.
I think you can add it to examples
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.
Would you please add a test 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.
I am sorry, but for the moment, I don't really know how to add a test.
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.
@SebastianIonel
you should be able to copy-paste one of the Example
from
nushell/crates/nu-command/src/bytes/remove.rs
Lines 85 to 120 in 9522052
fn examples(&self) -> Vec<Example> { | |
vec![ | |
Example { | |
description: "Remove contents", | |
example: "0x[10 AA FF AA FF] | bytes remove 0x[10 AA]", | |
result: Some(Value::test_binary ( | |
vec![0xFF, 0xAA, 0xFF], | |
)), | |
}, | |
Example { | |
description: "Remove all occurrences of find binary in record field", | |
example: "{ data: 0x[10 AA 10 BB 10] } | bytes remove --all 0x[10] data", | |
result: Some(Value::test_record(record! { | |
"data" => Value::test_binary(vec![0xAA, 0xBB]) | |
})), | |
}, | |
Example { | |
description: "Remove occurrences of find binary from end", | |
example: "0x[10 AA 10 BB CC AA 10] | bytes remove --end 0x[10]", | |
result: Some(Value::test_binary ( | |
vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA], | |
)), | |
}, | |
Example { | |
description: "Remove all occurrences of find binary in table", | |
example: "[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes remove 0x[11] ColA ColC", | |
result: Some(Value::test_list ( | |
vec![Value::test_record(record! { | |
"ColA" => Value::test_binary ( vec![0x12, 0x13],), | |
"ColB" => Value::test_binary ( vec![0x14, 0x15, 0x16],), | |
"ColC" => Value::test_binary ( vec![0x17, 0x18, 0x19],), | |
})], | |
)), | |
}, | |
] | |
} |
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.
Yup, just need to add something like 0x[10 AA FF] | bytes remove --end 0x[BB]
You could also just add the test @WindSoilder added before closing his PR that does the same thing. https://github.com/nushell/nushell/pull/11427/files |
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.
Thanks! Looks good to me
This PR should close nushell#11426 . # Description > ### Describe the bug > When using the `--end` option of bytes remove, nushell panics if the provided bytes don't exist. This doesn't seem to affect `bytes remove` w/o flag or `bytes remove --all`. # User-Facing Changes Nushell doesn`t panic anymore. # Tests + Formatting Behavior before fixing the bug: ![nu-before changes](https://github.com/UPB-CS-OpenSourceUpstream/nushell/assets/119429832/f9c26d88-8962-4f38-a373-ba436a26ca7c) Behavior after fixing the bug: ![nu- after changes](https://github.com/UPB-CS-OpenSourceUpstream/nushell/assets/119429832/0dd2b487-1696-45a6-9ea2-928cbd3a33a8)
This PR should close #11426 .
Description
User-Facing Changes
Nushell doesn`t panic anymore.
Tests + Formatting
Behavior before fixing the bug:
![nu-before changes](https://private-user-images.githubusercontent.com/119429832/293013331-f9c26d88-8962-4f38-a373-ba436a26ca7c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MzY1ODksIm5iZiI6MTcyMTQzNjI4OSwicGF0aCI6Ii8xMTk0Mjk4MzIvMjkzMDEzMzMxLWY5YzI2ZDg4LTg5NjItNGYzOC1hMzczLWJhNDM2YTI2Y2E3Yy5w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