nushell/crates/nu-command/tests/commands
Andrés N. Robalino 7a77910720
Table content rolling. (#3097)
There are many use cases. Here we introduce the following:

- The rows can be rolled `... | roll` (up) or `... | roll down`
- Columns can be rolled too (the default is on the `left`, you can pass `... | roll column --opposite` to roll in the other direction)
- You can `roll` the cells of a table and keeping the header names in the same order (`... | roll column --cells-only`)
- Above examples can also be passed (Ex. `... | roll down 3`) a number to tell how many places to roll.

Basic working example with rolling columns:

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8

───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────
 # │ bit1 │ bit2 │ bit3 │ bit4 │ bit5 │ bit6 │ bit7 │ bit8
───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
 0 │    0 │    0 │    0 │    0 │    0 │    1 │    0 │    0
───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────
```

We want to "shift" three bits to the left of the bitstring (four in decimal), let's try it:

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8
| roll column 3

───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────
 # │ bit4 │ bit5 │ bit6 │ bit7 │ bit8 │ bit1 │ bit2 │ bit3
───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
 0 │    0 │    0 │    1 │    0 │    0 │    0 │    0 │    0
───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────
```

The tables was rolled correctly (32 in decimal, for above bitstring). However, the *last three header names* look confusing.
We can roll the cell contents only to fix it.

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8
| roll column 3 --cells-only

───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────
 # │ bit1 │ bit2 │ bit3 │ bit4 │ bit5 │ bit6 │ bit7 │ bit8
───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
 0 │    0 │    0 │    1 │    0 │    0 │    0 │    0 │    0
───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────
```

There we go. Let's compute it's decimal value now (should be 32)

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| roll column 3 --cells-only
| pivot bit --ignore-titles
| get bit
| reverse
| each --numbered { = $it.item * (2 ** $it.index) }
| math sum

32
```
2021-02-23 13:29:07 -05:00
..
hash_ nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
keep nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
math nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
move_ nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
path nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
random nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
skip nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
str_ allow str from to convert more things to string (#2977) 2021-01-29 07:43:35 -06:00
append.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
autoenv_trust.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
autoenv_untrust.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
autoenv.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
cal.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
cd.rs Replace dirs and directories with maintained (#2949) 2021-01-19 14:24:27 -06:00
compact.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
count.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
cp.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
def.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
default.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
drop.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
each.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
echo.rs RangeIterator can also go down (#2913) 2021-01-13 08:27:54 +13:00
empty.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
enter.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
every.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
first.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
flatten.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
format.rs standardize on how to get file size (#2992) 2021-02-03 07:19:38 -06:00
get.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
group_by.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
headers.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
histogram.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
insert.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
into_int.rs nu-parser + nu-protocol: switch to metric for KB, MB, GB, add KiB, MiB, GiB units (#3035) 2021-02-10 15:31:12 +13:00
last.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
lines.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
ls.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
merge.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
mkdir.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
mod.rs Table content rolling. (#3097) 2021-02-23 13:29:07 -05:00
nth.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
open.rs Soft rest arguments column path cohersions. (#3016) 2021-02-06 20:05:47 -05:00
parse.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
prepend.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
range.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
reduce.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
rename.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
reverse.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
rm.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
roll.rs Table content rolling. (#3097) 2021-02-23 13:29:07 -05:00
rotate.rs 90 degree table rotations (clockwise and counter-clockwise) (#3086) 2021-02-22 06:56:34 -05:00
save.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
select.rs Soft rest arguments column path cohersions. (#3016) 2021-02-06 20:05:47 -05:00
semicolon.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
sort_by.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
split_by.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
split_column.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
split_row.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
touch.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
uniq.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
update.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
where_.rs nu-parser + nu-protocol: switch to metric for KB, MB, GB, add KiB, MiB, GiB units (#3035) 2021-02-10 15:31:12 +13:00
which.rs Use equality assert macros (#2969) 2021-01-25 18:16:10 +13:00
with_env.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
wrap.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00