2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
|
|
use nu_test_support::playground::Playground;
|
2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-10-31 10:42:18 +01:00
|
|
|
|
2019-10-31 10:36:08 +01:00
|
|
|
#[test]
|
2019-12-15 17:15:06 +01:00
|
|
|
fn fetches_a_row() {
|
2019-10-31 10:36:08 +01:00
|
|
|
Playground::setup("get_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
nu_party_venue = "zion"
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 10:36:08 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
|
|
|
| get nu_party_venue
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "zion");
|
2019-10-31 10:36:08 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-01 22:19:46 +01:00
|
|
|
fn fetches_by_index() {
|
2019-10-31 10:36:08 +01:00
|
|
|
Playground::setup("get_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "nu"
|
|
|
|
version = "0.4.1"
|
|
|
|
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
|
|
|
description = "When arepas shells are tasty and fun."
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 10:36:08 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
|
|
|
| get package.authors.2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "Andrés N. Robalino <andres@androbtech.com>");
|
2019-10-31 10:36:08 +01:00
|
|
|
})
|
|
|
|
}
|
2019-10-31 20:20:22 +01:00
|
|
|
#[test]
|
2019-11-01 22:19:46 +01:00
|
|
|
fn fetches_by_column_path() {
|
2019-10-31 20:20:22 +01:00
|
|
|
Playground::setup("get_test_3", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
2019-11-01 22:19:46 +01:00
|
|
|
name = "nu"
|
2019-10-31 20:20:22 +01:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 20:20:22 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
2019-11-01 22:19:46 +01:00
|
|
|
| get package.name
|
2019-10-31 20:20:22 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "nu");
|
2019-10-31 20:20:22 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-01 22:19:46 +01:00
|
|
|
fn column_paths_are_either_double_quoted_or_regular_unquoted_words_separated_by_dot() {
|
2019-10-31 20:20:22 +01:00
|
|
|
Playground::setup("get_test_4", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
2019-11-01 22:19:46 +01:00
|
|
|
9999 = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
2019-10-31 20:20:22 +01:00
|
|
|
description = "When arepas shells are tasty and fun."
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 20:20:22 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
2019-11-01 22:19:46 +01:00
|
|
|
| get package."9999"
|
2021-03-13 22:46:40 +01:00
|
|
|
| length
|
2019-10-31 20:20:22 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "3");
|
2019-10-31 20:20:22 +01:00
|
|
|
})
|
|
|
|
}
|
2019-10-31 10:36:08 +01:00
|
|
|
|
|
|
|
#[test]
|
2019-11-01 22:19:46 +01:00
|
|
|
fn fetches_more_than_one_column_path() {
|
2019-10-31 20:20:22 +01:00
|
|
|
Playground::setup("get_test_5", |dirs, sandbox| {
|
2019-10-31 10:36:08 +01:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[[fortune_tellers]]
|
|
|
|
name = "Andrés N. Robalino"
|
|
|
|
arepas = 1
|
|
|
|
|
|
|
|
[[fortune_tellers]]
|
|
|
|
name = "Jonathan Turner"
|
|
|
|
arepas = 1
|
|
|
|
|
|
|
|
[[fortune_tellers]]
|
|
|
|
name = "Yehuda Katz"
|
|
|
|
arepas = 1
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 10:36:08 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
|
|
|
| get fortune_tellers.2.name fortune_tellers.0.name fortune_tellers.1.name
|
|
|
|
| nth 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "Jonathan Turner");
|
2019-10-31 10:36:08 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-31 20:20:22 +01:00
|
|
|
#[test]
|
|
|
|
fn errors_fetching_by_column_not_present() {
|
|
|
|
Playground::setup("get_test_6", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[taconushell]
|
|
|
|
sentence_words = ["Yo", "quiero", "taconushell"]
|
2020-09-22 04:14:11 +02:00
|
|
|
[pizzanushell]
|
|
|
|
sentence-words = ["I", "want", "pizza"]
|
2019-10-31 20:20:22 +01:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 20:20:22 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
|
|
|
| get taco
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2021-03-26 09:26:57 +01:00
|
|
|
assert!(actual.err.contains("Unknown column"),);
|
|
|
|
assert!(actual.err.contains("There isn't a column named 'taco'"),);
|
|
|
|
assert!(actual.err.contains("Perhaps you meant 'taconushell'?"),);
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("Columns available: pizzanushell, taconushell"),);
|
2019-10-31 20:20:22 +01:00
|
|
|
})
|
|
|
|
}
|
2019-11-01 22:19:46 +01:00
|
|
|
|
2019-10-31 10:36:08 +01:00
|
|
|
#[test]
|
2019-11-01 22:19:46 +01:00
|
|
|
fn errors_fetching_by_column_using_a_number() {
|
2019-10-31 20:20:22 +01:00
|
|
|
Playground::setup("get_test_7", |dirs, sandbox| {
|
2019-11-01 22:19:46 +01:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[spanish_lesson]
|
|
|
|
0 = "can only be fetched with 0 double quoted."
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-11-01 22:19:46 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
2020-01-10 16:44:24 +01:00
|
|
|
| get spanish_lesson.0
|
2019-11-01 22:19:46 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2021-03-26 09:26:57 +01:00
|
|
|
assert!(actual.err.contains("No rows available"),);
|
|
|
|
assert!(actual.err.contains("A row at '0' can't be indexed."),);
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("Appears to contain columns. Columns available: 0"),)
|
2019-11-01 22:19:46 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn errors_fetching_by_index_out_of_bounds() {
|
|
|
|
Playground::setup("get_test_8", |dirs, sandbox| {
|
2019-10-31 10:36:08 +01:00
|
|
|
sandbox.with_files(vec![FileWithContent(
|
|
|
|
"sample.toml",
|
|
|
|
r#"
|
|
|
|
[spanish_lesson]
|
|
|
|
sentence_words = ["Yo", "quiero", "taconushell"]
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-10-31 10:36:08 +01:00
|
|
|
r#"
|
|
|
|
open sample.toml
|
|
|
|
| get spanish_lesson.sentence_words.3
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2021-03-26 09:26:57 +01:00
|
|
|
assert!(actual.err.contains("Row not found"),);
|
|
|
|
assert!(actual.err.contains("There isn't a row indexed at 3"),);
|
|
|
|
assert!(actual.err.contains("The table only has 3 rows (0 to 2)"),)
|
2019-10-31 10:36:08 +01:00
|
|
|
})
|
|
|
|
}
|
2020-04-26 08:01:55 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn quoted_column_access() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats",
|
2020-10-26 07:55:52 +01:00
|
|
|
r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz "#
|
2020-04-26 08:01:55 +02:00
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "4");
|
2020-04-26 08:01:55 +02:00
|
|
|
}
|