From ddca230ef5f9a94ddcd17d03cdb6e2c9db128cc4 Mon Sep 17 00:00:00 2001 From: aimof <aimof.aimof@gmail.com> Date: Sun, 14 Jan 2018 17:29:55 +0900 Subject: [PATCH] Change: remove tests dependency script_exec test is depends on examples/a* and examples/b*. If we try to change tests in a* or b*, we must change script_exec.out So, I remove dependency. --- examples/script_exec.ion | 4 +- examples/script_exec/array_methods.ion | 10 ++++ examples/script_exec/array_methods.out | 9 ++++ examples/script_exec/arrays.ion | 69 ++++++++++++++++++++++++ examples/script_exec/arrays.out | 54 +++++++++++++++++++ examples/script_exec/basic_condition.ion | 5 ++ examples/script_exec/basic_condition.out | 1 + examples/script_exec/braces.ion | 37 +++++++++++++ examples/script_exec/braces.out | 26 +++++++++ examples/script_exec/break.ion | 15 ++++++ examples/script_exec/break.out | 10 ++++ examples/script_exec/builtin_piping.ion | 5 ++ examples/script_exec/builtin_piping.out | 4 ++ 13 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 examples/script_exec/array_methods.ion create mode 100644 examples/script_exec/array_methods.out create mode 100644 examples/script_exec/arrays.ion create mode 100644 examples/script_exec/arrays.out create mode 100755 examples/script_exec/basic_condition.ion create mode 100644 examples/script_exec/basic_condition.out create mode 100644 examples/script_exec/braces.ion create mode 100644 examples/script_exec/braces.out create mode 100644 examples/script_exec/break.ion create mode 100644 examples/script_exec/break.out create mode 100644 examples/script_exec/builtin_piping.ion create mode 100644 examples/script_exec/builtin_piping.out diff --git a/examples/script_exec.ion b/examples/script_exec.ion index 92cf7d03..66a495b7 100644 --- a/examples/script_exec.ion +++ b/examples/script_exec.ion @@ -1,3 +1,3 @@ -for script in examples/a* examples/b* +for script in examples/script_exec/a* examples/script_exec/b* target/debug/ion $script -end \ No newline at end of file +end diff --git a/examples/script_exec/array_methods.ion b/examples/script_exec/array_methods.ion new file mode 100644 index 00000000..c15408ef --- /dev/null +++ b/examples/script_exec/array_methods.ion @@ -0,0 +1,10 @@ +echo @split("onetwoone", "two") +echo @split_at("onetwoone", "3") +echo @graphemes("onetwo", "3") +echo @bytes("onetwo") +echo @chars("onetwo") +echo @lines($unescape("firstline\nsecondline")) +echo @reverse([1 2 3]) +echo @reverse(["a"]) +let foo = [1 2 3] +echo @reverse(@foo) diff --git a/examples/script_exec/array_methods.out b/examples/script_exec/array_methods.out new file mode 100644 index 00000000..af8487b8 --- /dev/null +++ b/examples/script_exec/array_methods.out @@ -0,0 +1,9 @@ +one one +one twoone +o n e t w o +111 110 101 116 119 111 +o n e t w o +firstline secondline +3 2 1 +a +3 2 1 diff --git a/examples/script_exec/arrays.ion b/examples/script_exec/arrays.ion new file mode 100644 index 00000000..e8658556 --- /dev/null +++ b/examples/script_exec/arrays.ion @@ -0,0 +1,69 @@ +# Standard Arrays + +let array = [1 [2 3] 4 [5 6]] +for i in @array + echo $i +end + +for i in [1 [2 3] 4 [5 6]] + echo $i +end + +# Array Command Substitution + +let array_process = [ @(echo a b c d e) ] +for i in @array_process + echo $i +end + +for i in @(echo a b c d e) + echo $i +end + +# Array Concatenation + +let new_array = [@array @array_process] +for i in @new_array + echo $i +end + +# As Command Arguments + +echo @array +echo @array_process +echo @new_array + +# Slice by ID + +let array = [ 1 2 3 ] +echo @array[0] +echo @array[1] +echo @array[2] + +echo [ 1 2 3 ][0] +echo [ 1 2 3 ][1] +echo [ 1 2 3 ][2] + +echo @(echo 1 2 3)[0] +echo @(echo 1 2 3)[1] +echo @(echo 1 2 3)[2] + +# Slice by Range + +let array = [ 1 2 3 4 5 ] +echo @array[0..1] +echo @array[0...1] +echo @array[..3] +echo @array[3..] +echo @array[..] + +# Slice Syntax w/ variables +for index in 0..3 + echo $(echo 😉😉😉)[$index] +end + +# Convert Array to String + +let array = [ 1 2 3 4 5 ] +let as_string = @array +echo $as_string diff --git a/examples/script_exec/arrays.out b/examples/script_exec/arrays.out new file mode 100644 index 00000000..e46fc022 --- /dev/null +++ b/examples/script_exec/arrays.out @@ -0,0 +1,54 @@ +1 +2 +3 +4 +5 +6 +1 +2 +3 +4 +5 +6 +a +b +c +d +e +a +b +c +d +e +1 +2 +3 +4 +5 +6 +a +b +c +d +e +1 2 3 4 5 6 +a b c d e +1 2 3 4 5 6 a b c d e +1 +2 +3 +1 +2 +3 +1 +2 +3 +1 +1 2 +1 2 3 +4 5 +1 2 3 4 5 +😉 +😉 +😉 +1 2 3 4 5 diff --git a/examples/script_exec/basic_condition.ion b/examples/script_exec/basic_condition.ion new file mode 100755 index 00000000..10bd1f45 --- /dev/null +++ b/examples/script_exec/basic_condition.ion @@ -0,0 +1,5 @@ +if test 3 -eq 3 + echo pass +else + echo fail +end diff --git a/examples/script_exec/basic_condition.out b/examples/script_exec/basic_condition.out new file mode 100644 index 00000000..2ae28399 --- /dev/null +++ b/examples/script_exec/basic_condition.out @@ -0,0 +1 @@ +pass diff --git a/examples/script_exec/braces.ion b/examples/script_exec/braces.ion new file mode 100644 index 00000000..8bc78fec --- /dev/null +++ b/examples/script_exec/braces.ion @@ -0,0 +1,37 @@ +# nested braces +echo 1{A{1,2},B{1,2}} + +# permutating braces +echo {0,1}abc{2,3,4}def{5,6,7}{g,h,i} + +# inclusive ranges +echo {-1...1} +echo {2...0} +echo {a...c} +echo {d...b} +echo {A...C} +echo {D...B} + +# exclusive ranges +echo {-1..2} +echo {2..-1} +echo {a..d} +echo {d..a} +echo {A..D} +echo {D..A} + +# inclusive stepped ranges +echo {0..2...4} +echo {a..2...e} +echo {A..2...E} +echo {0..-2...-4} +echo {e..-2...a} +echo {E..-2...A} + +# exclusive stepped ranges +echo {0..2..5} +echo {a..2..f} +echo {A..2..F} +echo {0..-2..-5} +echo {e..-2..a} +echo {E..-2..A} \ No newline at end of file diff --git a/examples/script_exec/braces.out b/examples/script_exec/braces.out new file mode 100644 index 00000000..e27ebdbf --- /dev/null +++ b/examples/script_exec/braces.out @@ -0,0 +1,26 @@ +1A1 1A2 1B1 1B2 +0abc2def5g 0abc2def5h 0abc2def5i 0abc2def6g 0abc2def6h 0abc2def6i 0abc2def7g 0abc2def7h 0abc2def7i 0abc3def5g 0abc3def5h 0abc3def5i 0abc3def6g 0abc3def6h 0abc3def6i 0abc3def7g 0abc3def7h 0abc3def7i 0abc4def5g 0abc4def5h 0abc4def5i 0abc4def6g 0abc4def6h 0abc4def6i 0abc4def7g 0abc4def7h 0abc4def7i 1abc2def5g 1abc2def5h 1abc2def5i 1abc2def6g 1abc2def6h 1abc2def6i 1abc2def7g 1abc2def7h 1abc2def7i 1abc3def5g 1abc3def5h 1abc3def5i 1abc3def6g 1abc3def6h 1abc3def6i 1abc3def7g 1abc3def7h 1abc3def7i 1abc4def5g 1abc4def5h 1abc4def5i 1abc4def6g 1abc4def6h 1abc4def6i 1abc4def7g 1abc4def7h 1abc4def7i +-1 0 1 +2 1 0 +a b c +d c b +A B C +D C B +-1 0 1 +2 1 0 +a b c +d c b +A B C +D C B +0 2 4 +a c e +A C E +0 -2 -4 +e c a +E C A +0 2 4 +a c e +A C E +0 -2 -4 +e c +E C diff --git a/examples/script_exec/break.ion b/examples/script_exec/break.ion new file mode 100644 index 00000000..eabd0945 --- /dev/null +++ b/examples/script_exec/break.ion @@ -0,0 +1,15 @@ +for i in 1..10 + echo $i + if test $i -eq 5 + break + end +end + +let a = 1 +while test $a -lt 10 + echo $a + if test $a -eq 5 + break + end + let a += 1 +end diff --git a/examples/script_exec/break.out b/examples/script_exec/break.out new file mode 100644 index 00000000..68c24932 --- /dev/null +++ b/examples/script_exec/break.out @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +1 +2 +3 +4 +5 diff --git a/examples/script_exec/builtin_piping.ion b/examples/script_exec/builtin_piping.ion new file mode 100644 index 00000000..8962861b --- /dev/null +++ b/examples/script_exec/builtin_piping.ion @@ -0,0 +1,5 @@ +matches Foo '([A-Z])\w+' && echo true +matches foo '([A-Z])\w+' || echo false +echo foo | cat +read foo <<< $(echo bar) +echo $foo diff --git a/examples/script_exec/builtin_piping.out b/examples/script_exec/builtin_piping.out new file mode 100644 index 00000000..abd1f965 --- /dev/null +++ b/examples/script_exec/builtin_piping.out @@ -0,0 +1,4 @@ +true +false +foo +bar -- GitLab