mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 03:34:58 +02:00
xpath command for nushell (#2656)
* xpath prototype * new xpath engine is finally working * nearly there * closer * working with list, started to add test, code cleanup * broken again * working again - time for some cleanup * cleaned up code, added error handling and test * update example, fix clippy * removed commented char
This commit is contained in:
41
crates/nu-cli/tests/commands/xpath.rs
Normal file
41
crates/nu-cli/tests/commands/xpath.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn position_function_in_predicate() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "<?xml version="1.0" encoding="UTF-8"?><a><b/><b/></a>" | from xml | to xml | xpath "count(//a/*[position() = 2])"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1.0000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn functions_implicitly_coerce_argument_types() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "<?xml version="1.0" encoding="UTF-8"?><a>true</a>" | from xml | to xml | xpath "count(//*[contains(., true)])"
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "1.0000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_guid_permilink_is_true() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open jonathan.xml
|
||||
| to xml
|
||||
| xpath '//guid/@isPermaLink'
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
Reference in New Issue
Block a user