Move 'nth' into 'select' (#4385)

This commit is contained in:
JT
2022-02-09 09:59:40 -05:00
committed by GitHub
parent 43850bf20e
commit 5a1d81221f
18 changed files with 190 additions and 259 deletions

View File

@ -108,7 +108,7 @@ fn fetches_more_than_one_column_path() {
arepas = 1
[[fortune_tellers]]
name = "Jonathan Turner"
name = "JT"
arepas = 1
[[fortune_tellers]]
@ -126,7 +126,7 @@ fn fetches_more_than_one_column_path() {
"#
));
assert_eq!(actual.out, "Jonathan Turner");
assert_eq!(actual.out, "JT");
})
}

View File

@ -34,7 +34,6 @@ mod math;
mod merge;
mod mkdir;
mod move_;
mod nth;
mod open;
mod parse;
mod path;

View File

@ -133,7 +133,7 @@ fn moves_columns_after() {
open sample.csv
| move letters and_more --after column1
| get
| nth 1 2
| select 1 2
| str collect
"#
));

View File

@ -1,41 +0,0 @@
use nu_test_support::fs::Stub::EmptyFile;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn selects_a_row() {
Playground::setup("nth_test_1", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("arepas.txt")]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
ls
| sort-by name
| nth 0
| get name.0
"#
));
assert_eq!(actual.out, "arepas.txt");
});
}
#[test]
fn selects_many_rows() {
Playground::setup("nth_test_2", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("arepas.txt")]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
ls
| get name
| nth 1 0
| length
"#
));
assert_eq!(actual.out, "2");
});
}

View File

@ -59,7 +59,7 @@ fn parses_csv() {
fn parses_bson() {
let actual = nu!(
cwd: "tests/fixtures/formats",
"open sample.bson | get root | nth 0 | get b"
"open sample.bson | get root | select 0 | get b"
);
assert_eq!(actual.out, "hello");
@ -73,7 +73,7 @@ fn parses_more_bson_complexity() {
r#"
open sample.bson
| get root
| nth 6
| select 6
| get b
| get '$binary_subtype'
"#
@ -120,7 +120,7 @@ fn parses_more_bson_complexity() {
// `ints` has just `z`, and `floats` has only the column `f`. This means, in general, when working
// with sqlite, one will want to select a single table, e.g.:
//
// open sample.db | nth 1 | get table_values
// open sample.db | select 1 | get table_values
// ━━━┯━━━━━━
// # │ z
// ───┼──────
@ -139,7 +139,7 @@ fn parses_sqlite() {
r#"
open sample.db
| get table_values
| nth 2
| select 2
| get x
"#
));

View File

@ -25,7 +25,7 @@ mod simple {
open key_value_separated_arepa_ingredients.txt
| lines
| each { echo $it | parse "{Name}={Value}" }
| nth 1
| select 1
| get Value
"#
));

View File

@ -1,4 +1,4 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
@ -126,3 +126,41 @@ fn ignores_duplicate_columns_selected() {
assert_eq!(actual.out, "first name last name");
}
#[test]
fn selects_a_row() {
Playground::setup("select_test_1", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("arepas.txt")]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
ls
| sort-by name
| select 0
| get name.0
"#
));
assert_eq!(actual.out, "arepas.txt");
});
}
#[test]
fn selects_many_rows() {
Playground::setup("select_test_2", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("notes.txt"), EmptyFile("arepas.txt")]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
ls
| get name
| select 1 0
| length
"#
));
assert_eq!(actual.out, "2");
});
}