nushell/tests
Yehuda Katz 34292b282a Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.

The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.

As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.

For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.

This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).

The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.

This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.

By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.

In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:03:24 -07:00
..
fixtures Finish last few types and add tests 2019-08-25 09:50:25 -04:00
helpers [from|to]csv additions/refactoring. 2019-08-25 12:32:08 -05:00
command_cd_tests.rs Add support for external escape valve (^dir) 2019-08-15 15:18:18 -07:00
command_cp_tests.rs copies_expected -> expected. Use expected as test dirname expectation outcomes from now on. 2019-08-14 16:05:35 -05:00
command_enter_test.rs sidestep 'enter' integration test failure for files. 2019-08-20 08:01:02 -05:00
command_ls_tests.rs Add support for ~ expansion 2019-08-26 21:03:24 -07:00
command_mkdir_tests.rs mkdir can take multiple directories or multiple directory hierachies and wil create them as required. 2019-08-21 07:07:37 -05:00
command_mv_tests.rs mv introduced. \¡Viva\! 2019-08-14 15:29:05 -05:00
command_open_tests.rs [from|to]csv additions/refactoring. 2019-08-25 12:32:08 -05:00
command_rm_tests.rs rm fully operational and error surveyd. 2019-08-20 06:22:11 -05:00
commands_test.rs mark #[test] back. (deleted and reverting it from.. 12e38063) 2019-08-25 21:50:55 -05:00
external_tests.rs Add support for external escape valve (^dir) 2019-08-15 15:18:18 -07:00
filter_inc_tests.rs Reverted test removal from (dfcbaed) 2019-08-14 15:55:26 -05:00
filter_str_tests.rs Test sample changed to check behavior with strings on different operating systems. 2019-08-11 13:18:42 -05:00
filters_test.rs Merge pull request #415 from androbtech/fromto-refact 2019-08-25 12:56:28 -05:00
tests.rs Covered the remaining semver flags for inc plugin. 2019-08-10 06:04:13 -05:00