2020-01-10 16:44:24 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
2020-01-11 07:45:09 +01:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2020-01-10 16:44:24 +01:00
|
|
|
|
|
|
|
#[test]
|
2020-01-11 07:45:09 +01:00
|
|
|
fn regular_columns() {
|
2020-05-07 13:03:43 +02:00
|
|
|
Playground::setup("select_test_1", |dirs, sandbox| {
|
2020-01-10 16:44:24 +01:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.csv",
|
|
|
|
r#"
|
|
|
|
first_name,last_name,rusty_at,type
|
|
|
|
Andrés,Robalino,10/11/2013,A
|
|
|
|
Jonathan,Turner,10/12/2013,B
|
|
|
|
Yehuda,Katz,10/11/2013,A
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.csv
|
2020-05-07 13:03:43 +02:00
|
|
|
| select rusty_at last_name
|
2020-01-10 16:44:24 +01:00
|
|
|
| nth 0
|
|
|
|
| get last_name
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "Robalino");
|
2020-01-10 16:44:24 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-01-11 07:45:09 +01:00
|
|
|
fn complex_nested_columns() {
|
2020-05-07 13:03:43 +02:00
|
|
|
Playground::setup("select_test_2", |dirs, sandbox| {
|
2020-01-10 16:44:24 +01:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
2020-01-11 07:45:09 +01:00
|
|
|
"los_tres_caballeros.json",
|
2020-01-10 16:44:24 +01:00
|
|
|
r#"
|
2020-01-11 07:45:09 +01:00
|
|
|
{
|
|
|
|
"nu": {
|
|
|
|
"committers": [
|
|
|
|
{"name": "Andrés N. Robalino"},
|
|
|
|
{"name": "Jonathan Turner"},
|
|
|
|
{"name": "Yehuda Katz"}
|
|
|
|
],
|
|
|
|
"releases": [
|
|
|
|
{"version": "0.2"}
|
|
|
|
{"version": "0.8"},
|
|
|
|
{"version": "0.9999999"}
|
|
|
|
],
|
|
|
|
"0xATYKARNU": [
|
|
|
|
["Th", "e", " "],
|
|
|
|
["BIG", " ", "UnO"],
|
|
|
|
["punto", "cero"]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2020-01-10 16:44:24 +01:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
2020-01-11 07:45:09 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.json
|
2020-05-07 13:03:43 +02:00
|
|
|
| select nu."0xATYKARNU" nu.committers.name nu.releases.version
|
Restructure and streamline token expansion (#1123)
Restructure and streamline token expansion
The purpose of this commit is to streamline the token expansion code, by
removing aspects of the code that are no longer relevant, removing
pointless duplication, and eliminating the need to pass the same
arguments to `expand_syntax`.
The first big-picture change in this commit is that instead of a handful
of `expand_` functions, which take a TokensIterator and ExpandContext, a
smaller number of methods on the `TokensIterator` do the same job.
The second big-picture change in this commit is fully eliminating the
coloring traits, making coloring a responsibility of the base expansion
implementations. This also means that the coloring tracer is merged into
the expansion tracer, so you can follow a single expansion and see how
the expansion process produced colored tokens.
One side effect of this change is that the expander itself is marginally
more error-correcting. The error correction works by switching from
structured expansion to `BackoffColoringMode` when an unexpected token
is found, which guarantees that all spans of the source are colored, but
may not be the most optimal error recovery strategy.
That said, because `BackoffColoringMode` only extends as far as a
closing delimiter (`)`, `]`, `}`) or pipe (`|`), it does result in
fairly granular correction strategy.
The current code still produces an `Err` (plus a complete list of
colored shapes) from the parsing process if any errors are encountered,
but this could easily be addressed now that the underlying expansion is
error-correcting.
This commit also colors any spans that are syntax errors in red, and
causes the parser to include some additional information about what
tokens were expected at any given point where an error was encountered,
so that completions and hinting could be more robust in the future.
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Andrés N. Robalino <andres@androbtech.com>
2020-01-21 23:45:03 +01:00
|
|
|
| where "nu.releases.version" > "0.8"
|
2020-01-11 07:45:09 +01:00
|
|
|
| get "nu.releases.version"
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "0.9999999");
|
2020-01-11 07:45:09 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn allows_if_given_unknown_column_name_is_missing() {
|
2020-05-07 13:03:43 +02:00
|
|
|
Playground::setup("select_test_3", |dirs, sandbox| {
|
2020-01-11 07:45:09 +01:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.csv",
|
|
|
|
r#"
|
|
|
|
first_name,last_name,rusty_at,type
|
|
|
|
Andrés,Robalino,10/11/2013,A
|
|
|
|
Jonathan,Turner,10/12/2013,B
|
|
|
|
Yehuda,Katz,10/11/2013,A
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2020-01-10 16:44:24 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.csv
|
2020-05-07 13:03:43 +02:00
|
|
|
| select rrusty_at first_name
|
2020-01-11 07:45:09 +01:00
|
|
|
| count
|
|
|
|
| echo $it
|
2020-01-10 16:44:24 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "3");
|
2020-01-10 16:44:24 +01:00
|
|
|
})
|
|
|
|
}
|