Commit 2bc8826a authored by matu3ba's avatar matu3ba
Browse files

fix(manual, testing): unit tests for correctly working sections+examples in...

fix(manual, testing): unit tests for correctly working sections+examples in manual chapter expansion
parent 7878d8ac
......@@ -13,18 +13,12 @@ expansion. If the character that follows is an accepted Unicode character, all c
follow will be collected until either a non-accepted Unicode character is found, or all characters
have been read. Then the characters that were collected will be used as the name of the string
variable to substitute with.
```sh
let string = "example string"
echo $string
echo $string:$string
{{#include ../../../tests/variable_exp.ion:string_variables}}
```
```txt
example string
example string:example string
{{#include ../../../tests/variable_exp.out:string_variables}}
```
**NOTE:**
- Accepted characters are **unicode** alphanumeric characters and **_**.
......@@ -34,15 +28,12 @@ Unlike POSIX, Ion also offers support for first class arrays, which are denoted
sigil. The rules for these are identical, but instead of returning a single string, it will
return an array of strings. This means that it's possible to use an array variable as arguments
in a command, as each element in the array will be treated as a separate shell word.
```sh
let array = [one two three]
echo @array
{{#include ../../../tests/variable_exp.ion:array_variables}}
```
```txt
one two three
{{#include ../../../tests/variable_exp.out:array_variables}}
```
However, do note that double-quoted arrays are coerced into strings, with spaces separating each
element. It is equivalent to using the `$join(array)` method. Containing multiple arrays within
double quotes is therefore equivalent to folding the elements into a single string.
......@@ -51,17 +42,19 @@ double quotes is therefore equivalent to folding the elements into a single stri
Braces can also be used when you need to integrate a variable expansion along accepted Unicode
characters.
```sh
echo ${hello}world
echo @{hello}world
{{#include ../../../tests/variable_exp.ion:braced_variables}}
```
```txt
{{#include ../../../tests/variable_exp.out:braced_variables}}
```
## Aliases
Ion also supports aliasing commands, which can be defined using the `alias` builtin. Aliases
are often used as shortcuts to repetitive command invocations.
```sh
alias ls = "ls --color"
{{#include ../../../tests/variable_exp.ion:aliases}}
```
```txt
{{#include ../../../tests/variable_exp.out:aliases}}
```
......@@ -13,20 +13,9 @@ let array = [ @(cmd args...) ]
**NOTES:**
- To split outputs by line, see [@lines($(cmd))](https://doc.redox-os.org/ion-manual/html/expansions/05-method.html#lines).
- `@(cmd)` is equivalent to [@split($(cmd))](https://doc.redox-os.org/ion-manual/html/expansions/05-method.html#split).
```sh
mkdir -p _tmp _tmp/t1 _tmp/t2
cd _tmp
let res = $(ls)
let res2 = [ @(ls) ]
echo $res # output the string
echo @res2 # output the array
cd ..
rm -fr _tmp
{{#include ../../../tests/process_exp.ion:process_expansion}}
```
```txt
t1
t2
t1 t2
{{#include ../../../tests/process_exp.out:process_expansion}}
```
......@@ -7,65 +7,41 @@ non-whitespace characters connected to brace expansions will also be included wi
permutations.
**NOTE:** Brace expansions will not work within double quotes.
```sh
echo filename.{ext1,ext2}
{{#include ../../../tests/brace_exp.ion:single_brace_expansion}}
```
```txt
filename.ext1 filename.ext2
{{#include ../../../tests/brace_exp.out:single_brace_expansion}}
```
Multiple brace tokens may occur within a braced collection, where each token expands the
possible permutation variants.
```sh
echo job_{01,02}.{ext1,ext2}
{{#include ../../../tests/brace_exp.ion:multi_brace_expansion}}
```
```txt
job_01.ext1 job_01.ext2 job_02.ext1 job_02.ext2
{{#include ../../../tests/brace_exp.out:multi_brace_expansion}}
```
Brace tokens may even contain brace tokens of their own, as each brace element will also be
expanded.
```sh
echo job_{01_{out,err},02_{out,err}}.txt
{{#include ../../../tests/brace_exp.ion:nested_brace_expansion}}
```
```txt
job_01_out.txt job_01_err.txt job_02_out.txt job_02_err.txt
{{#include ../../../tests/brace_exp.out:nested_brace_expansion}}
```
Braces elements may also be designated as ranges, which may be either inclusive or exclusive,
descending or ascending, numbers or latin alphabet characters.
```sh
echo {1..10}
echo {10..1}
echo {1...10}
echo {10...1}
echo {a..d}
echo {d..a}
echo {a...d}
echo {d...a}
{{#include ../../../tests/brace_exp.ion:range_brace_expansion}}
```
```txt
1 2 3 4 5 6 7 8 9
10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
a b c
d c b
a b c d
d c b a
{{#include ../../../tests/brace_exp.out:range_brace_expansion}}
```
It's also important to note that, as brace expansions return arrays, they may be used in for loops.
It's also important to note that, as range brace expansions return arrays, they may be used in for loops.
```sh
for num in {1..10}
echo $num
end
{{#include ../../../tests/brace_exp.ion:range_brace_expansion_as_array}}
```
```txt
1 2 3 4 5 6 7 8 9
{{#include ../../../tests/brace_exp.out:range_brace_expansion_as_array}}
```
echo '# ANCHOR: single_brace_expansion'
echo filename.{ext1,ext2}
echo '# ANCHOR_END: single_brace_expansion'
echo '# ANCHOR: multi_brace_expansion'
echo job_{01,02}.{ext1,ext2}
echo '# ANCHOR_END: multi_brace_expansion'
echo '# ANCHOR: nested_brace_expansion'
echo job_{01_{out,err},02_{out,err}}.txt
echo '# ANCHOR_END: nested_brace_expansion'
echo '# ANCHOR: range_brace_expansion'
echo {1..10}
echo {10..1}
echo {1...10}
echo {10...1}
echo {a..d}
echo {d..a}
echo {a...d}
echo {d...a}
echo '# ANCHOR_END: range_brace_expansion'
echo '# ANCHOR: range_brace_expansion_as_array'
for num in {1..10}
echo $num
end
echo '# ANCHOR_END: range_brace_expansion_as_array'
# ANCHOR: single_brace_expansion
filename.ext1 filename.ext2
# ANCHOR_END: single_brace_expansion
# ANCHOR: multi_brace_expansion
job_01.ext1 job_01.ext2 job_02.ext1 job_02.ext2
# ANCHOR_END: multi_brace_expansion
# ANCHOR: nested_brace_expansion
job_01_out.txt job_01_err.txt job_02_out.txt job_02_err.txt
# ANCHOR_END: nested_brace_expansion
# ANCHOR: range_brace_expansion
1 2 3 4 5 6 7 8 9
10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
a b c
d c b
a b c d
d c b a
# ANCHOR_END: range_brace_expansion
# ANCHOR: range_brace_expansion_as_array
1
2
3
4
5
6
7
8
9
# ANCHOR_END: range_brace_expansion_as_array
Cargo.toml
tests/braces.ion tests/braces.out tests/break.ion tests/break.out
tests/brace_exp.ion tests/brace_exp.out tests/braces.ion tests/braces.out tests/break.ion tests/break.out
Cargo.toml
Cargo.toml
Cargo.lock Cargo.toml
......
echo '# ANCHOR: process_expansion'
mkdir -p _tmp _tmp/t1 _tmp/t2
cd _tmp
let res = $(ls)
let res2 = [ @(ls) ]
echo $res # output the string
echo @res2 # output the array
cd ..
rm -fr _tmp
echo '# ANCHOR_END: process_expansion'
# ANCHOR: process_expansion
t1
t2
t1 t2
# ANCHOR_END: process_expansion
echo '# ANCHOR: string_variables'
let string = "example string"
echo $string
echo $string:$string
echo '# ANCHOR_END: string_variables'
echo '# ANCHOR: array_variables'
let array = [one two three]
echo @array
echo '# ANCHOR_END: array_variables'
echo '# ANCHOR: braced_variables'
let hello = "hello123"
echo ${hello}world
let hello = [hello 123 ' ']
echo @{hello}world
echo '# ANCHOR_END: braced_variables'
echo '# ANCHOR: aliases'
alias ls = "ls --color"
#echo $ls #ion: expansion error: Variable does not exist
#aliase are stored separately
echo '# ANCHOR_END: aliases'
# ANCHOR: string_variables
example string
example string:example string
# ANCHOR_END: string_variables
# ANCHOR: array_variables
one two three
# ANCHOR_END: array_variables
# ANCHOR: braced_variables
hello123world
hello 123 world
# ANCHOR_END: braced_variables
# ANCHOR: aliases
# ANCHOR_END: aliases
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment