From 732fc5020fa072d670c10c994288208adff17b97 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Sun, 6 Oct 2024 19:36:06 +0500 Subject: [PATCH] fix(std:scanln): don't use buffers because it didn't work well in test env (and maybe problem was biffer than just tests); fix(e2e): upd tests after movign from interpreter --- e2e/add_nums_from_stdin_naive/e2e_test.go | 30 ++++++++++++++ e2e/add_nums_from_stdin_naive/main/main.neva | 12 +++--- .../e2e_test.go | 30 ++++++++++++++ .../main/main.neva | 10 ++--- .../e2e_test.go | 30 ++++++++++++++ .../main/main.neva | 16 ++++---- .../e2e_test.go | 30 ++++++++++++++ .../main/main.neva | 10 ++--- .../e2e_test.go | 30 ++++++++++++++ .../main/main.neva | 13 +++--- e2e/add_nums_verbose/main/main.neva | 8 +--- e2e/add_nums_with_bridge/e2e_test.go | 22 ---------- e2e/add_nums_with_bridge/main/main.neva | 13 ------ e2e/add_nums_with_bridge/neva.yml | 1 - e2e/comments/e2e_test.go | 2 +- e2e/echo_verbose/main/main.neva | 6 +-- e2e/enums_verbose/e2e_test.go | 2 +- e2e/for_with_range_and_if/e2e_test.go | 22 +++++----- e2e/incompat_comp_type_arg/e2e_test.go | 2 +- .../.DS_Store | Bin 0 -> 6148 bytes .../e2e_test.go | 23 +++-------- .../main/main.neva | 16 +++----- e2e/interface_anonymous/e2e_test.go | 2 +- e2e/interface_verbose/e2e_test.go | 2 +- e2e/interface_with_imports/e2e_test.go | 2 +- e2e/simple_fan_out/e2e_test.go | 2 +- examples/add_numbers_from_stdin/e2e_test.go | 38 ++++++++++++++++++ examples/add_numbers_from_stdin/main.neva | 6 +-- examples/echo/e2e_test.go | 30 ++++++++------ examples/fizzbuzz/e2e_test.go | 4 +- examples/fizzbuzz/main.neva | 5 --- examples/for_loop_over_list/e2e_test.go | 34 ++++++++-------- examples/get_args/main.neva | 2 +- internal/runtime/funcs/scanln.go | 18 ++++----- std/builtin/routers.neva | 5 ++- std/builtin/streams.neva | 11 ----- 36 files changed, 304 insertions(+), 185 deletions(-) create mode 100644 e2e/add_nums_from_stdin_naive/e2e_test.go create mode 100644 e2e/add_nums_from_stdin_with_default_any/e2e_test.go create mode 100644 e2e/add_nums_from_stdin_with_err_handling/e2e_test.go create mode 100644 e2e/add_nums_from_stdin_with_multuple_senders/e2e_test.go create mode 100644 e2e/add_nums_from_stdin_with_sub_components/e2e_test.go delete mode 100644 e2e/add_nums_with_bridge/e2e_test.go delete mode 100644 e2e/add_nums_with_bridge/main/main.neva delete mode 100644 e2e/add_nums_with_bridge/neva.yml create mode 100644 e2e/incompat_types_with_untyped_port/.DS_Store create mode 100644 examples/add_numbers_from_stdin/e2e_test.go diff --git a/e2e/add_nums_from_stdin_naive/e2e_test.go b/e2e/add_nums_from_stdin_naive/e2e_test.go new file mode 100644 index 00000000..1ad9b829 --- /dev/null +++ b/e2e/add_nums_from_stdin_naive/e2e_test.go @@ -0,0 +1,30 @@ +package test + +import ( + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + for i := 0; i < 1; i++ { + t.Run("Add numbers from stdin", func(t *testing.T) { + cmd := exec.Command("neva", "run", "main") + + cmd.Stdin = strings.NewReader("3\n4\n\n") + + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "7\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } +} diff --git a/e2e/add_nums_from_stdin_naive/main/main.neva b/e2e/add_nums_from_stdin_naive/main/main.neva index a0815150..caf18d30 100644 --- a/e2e/add_nums_from_stdin_naive/main/main.neva +++ b/e2e/add_nums_from_stdin_naive/main/main.neva @@ -8,14 +8,14 @@ flow Main(start any) (stop any) { scanner2 io.Scanln parser1 strconv.ParseNum parser2 strconv.ParseNum - adder ReducePort { Add } + add Add println Println --- :start -> scanner1:sig - scanner1:data-> parser1:data - parser1:res -> [adder:port[0], scanner2:sig] - scanner2:data -> parser2:data - parser2:res -> adder:port[1] - adder:res -> println:data + scanner1:res -> parser1:data + parser1:res -> [add:acc, scanner2:sig] + scanner2:res -> parser2:data + parser2:res -> add:el + add:res -> println:data println:sig -> :stop } \ No newline at end of file diff --git a/e2e/add_nums_from_stdin_with_default_any/e2e_test.go b/e2e/add_nums_from_stdin_with_default_any/e2e_test.go new file mode 100644 index 00000000..1ad9b829 --- /dev/null +++ b/e2e/add_nums_from_stdin_with_default_any/e2e_test.go @@ -0,0 +1,30 @@ +package test + +import ( + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + for i := 0; i < 1; i++ { + t.Run("Add numbers from stdin", func(t *testing.T) { + cmd := exec.Command("neva", "run", "main") + + cmd.Stdin = strings.NewReader("3\n4\n\n") + + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "7\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } +} diff --git a/e2e/add_nums_from_stdin_with_default_any/main/main.neva b/e2e/add_nums_from_stdin_with_default_any/main/main.neva index 00303126..472ec144 100644 --- a/e2e/add_nums_from_stdin_with_default_any/main/main.neva +++ b/e2e/add_nums_from_stdin_with_default_any/main/main.neva @@ -14,20 +14,20 @@ flow Main(start) (stop) { flow Aux(sig) (res int, err error) { reader1 IntReader reader2 IntReader - adder ReducePort { Add } + add Add --- :sig -> reader1:sig - reader1:num -> [adder:port[0], reader2:sig] + reader1:num -> [add:acc, reader2:sig] [reader1:err, reader2:err] -> :err - reader2:num -> adder:port[1] - adder:res -> :res + reader2:num -> add:el + add:res -> :res } flow IntReader(sig any) (num int, err error) { io.Scanln, strconv.ParseNum --- :sig -> scanln:sig - scanln:data -> parseNum:data + scanln:res -> parseNum:data parseNum:res -> :num parseNum:err -> :err } diff --git a/e2e/add_nums_from_stdin_with_err_handling/e2e_test.go b/e2e/add_nums_from_stdin_with_err_handling/e2e_test.go new file mode 100644 index 00000000..1ad9b829 --- /dev/null +++ b/e2e/add_nums_from_stdin_with_err_handling/e2e_test.go @@ -0,0 +1,30 @@ +package test + +import ( + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + for i := 0; i < 1; i++ { + t.Run("Add numbers from stdin", func(t *testing.T) { + cmd := exec.Command("neva", "run", "main") + + cmd.Stdin = strings.NewReader("3\n4\n\n") + + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "7\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } +} diff --git a/e2e/add_nums_from_stdin_with_err_handling/main/main.neva b/e2e/add_nums_from_stdin_with_err_handling/main/main.neva index 5cf13724..dcb46212 100644 --- a/e2e/add_nums_from_stdin_with_err_handling/main/main.neva +++ b/e2e/add_nums_from_stdin_with_err_handling/main/main.neva @@ -8,16 +8,14 @@ flow Main(start any) (stop any) { scanner2 io.Scanln parser1 strconv.ParseNum parser2 strconv.ParseNum - adder ReducePort { Add } + add Add println Println --- :start -> scanner1:sig - scanner1:data -> parser1:data - parser1:err -> println:data - parser1:res -> [adder:port[0], scanner2:sig] - scanner2:data -> parser2:data - parser2:err -> println:data - parser2:res -> adder:port[1] - adder:res -> println:data + scanner1:res -> parser1:data + parser1:res -> [add:acc, scanner2:sig] + scanner2:res -> parser2:data + parser2:res -> add:el println:sig -> :stop -} \ No newline at end of file + [parser1:err, parser2:err, add:res] -> println:data +} diff --git a/e2e/add_nums_from_stdin_with_multuple_senders/e2e_test.go b/e2e/add_nums_from_stdin_with_multuple_senders/e2e_test.go new file mode 100644 index 00000000..1ad9b829 --- /dev/null +++ b/e2e/add_nums_from_stdin_with_multuple_senders/e2e_test.go @@ -0,0 +1,30 @@ +package test + +import ( + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + for i := 0; i < 1; i++ { + t.Run("Add numbers from stdin", func(t *testing.T) { + cmd := exec.Command("neva", "run", "main") + + cmd.Stdin = strings.NewReader("3\n4\n\n") + + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "7\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } +} diff --git a/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva b/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva index a5048b01..e6908382 100644 --- a/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva +++ b/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva @@ -14,20 +14,20 @@ flow Main(start) (stop) { flow Aux(sig) (res int, err error) { reader1 IntReader reader2 IntReader - adder ReducePort { Add } + add Add --- :sig -> reader1:sig - reader1:num -> [adder:port[0], reader2:sig] + reader1:num -> [add:acc, reader2:sig] [reader1:err, reader2:err] -> :err - reader2:num -> adder:port[1] - adder:res -> :res + reader2:num -> add:el + add:res -> :res } flow IntReader(sig any) (num int, err error) { io.Scanln, strconv.ParseNum --- :sig -> scanln:sig - scanln:data -> parseNum:data + scanln:res -> parseNum:data parseNum:res -> :num parseNum:err -> :err } diff --git a/e2e/add_nums_from_stdin_with_sub_components/e2e_test.go b/e2e/add_nums_from_stdin_with_sub_components/e2e_test.go new file mode 100644 index 00000000..1ad9b829 --- /dev/null +++ b/e2e/add_nums_from_stdin_with_sub_components/e2e_test.go @@ -0,0 +1,30 @@ +package test + +import ( + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + for i := 0; i < 1; i++ { + t.Run("Add numbers from stdin", func(t *testing.T) { + cmd := exec.Command("neva", "run", "main") + + cmd.Stdin = strings.NewReader("3\n4\n\n") + + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "7\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } +} diff --git a/e2e/add_nums_from_stdin_with_sub_components/main/main.neva b/e2e/add_nums_from_stdin_with_sub_components/main/main.neva index 9582ee01..322db1b9 100644 --- a/e2e/add_nums_from_stdin_with_sub_components/main/main.neva +++ b/e2e/add_nums_from_stdin_with_sub_components/main/main.neva @@ -7,29 +7,28 @@ flow Main(start any) (stop any) { Aux, Println --- :start -> aux:sig - aux:res -> println:data - aux:err -> println:data + [aux:res, aux:err] -> println:data println:sig -> :stop } flow Aux(sig any) (res int, err error) { reader1 IntReader reader2 IntReader - adder ReducePort { Add } + add Add --- :sig -> reader1:sig - reader1:num -> [adder:port[0], reader2:sig] + reader1:num -> [add:acc, reader2:sig] reader1:err -> :err reader2:err -> :err - reader2:num -> adder:port[1] - adder:res -> :res + reader2:num -> add:el + add:res -> :res } flow IntReader(sig any) (num int, err error) { io.Scanln, strconv.ParseNum --- :sig -> scanln:sig - scanln:data -> parseNum:data + scanln:res -> parseNum:data parseNum:res -> :num parseNum:err -> :err } diff --git a/e2e/add_nums_verbose/main/main.neva b/e2e/add_nums_verbose/main/main.neva index ebd688de..9adca48f 100644 --- a/e2e/add_nums_verbose/main/main.neva +++ b/e2e/add_nums_verbose/main/main.neva @@ -1,15 +1,11 @@ flow Main(start any) (stop any) { adder Add - sequencer ArrPortToStream println Println - --- - :start -> [ - (1 -> sequencer:port[0]), - (2 -> sequencer:port[1]) + (1 -> adder:acc), + (2 -> adder:el) ] - sequencer:data -> adder:data adder:res -> println:data println:sig -> :stop } \ No newline at end of file diff --git a/e2e/add_nums_with_bridge/e2e_test.go b/e2e/add_nums_with_bridge/e2e_test.go deleted file mode 100644 index 4b1d4909..00000000 --- a/e2e/add_nums_with_bridge/e2e_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package test - -import ( - "os/exec" - "testing" - - "github.com/stretchr/testify/require" -) - -func Test(t *testing.T) { - cmd := exec.Command("neva", "run", "main") - - out, err := cmd.CombinedOutput() - require.NoError(t, err) - require.Equal( - t, - "3\n", - string(out), - ) - - require.Equal(t, 0, cmd.ProcessState.ExitCode()) -} diff --git a/e2e/add_nums_with_bridge/main/main.neva b/e2e/add_nums_with_bridge/main/main.neva deleted file mode 100644 index e08dd0be..00000000 --- a/e2e/add_nums_with_bridge/main/main.neva +++ /dev/null @@ -1,13 +0,0 @@ -flow Main(start any) (stop any) { - adder ReducePort { Add } - println Println - - --- - - :start -> [ - (1 -> adder:port[0]), - (2 -> adder:port[1]) - ] - adder:res -> println:data - println:sig -> :stop -} diff --git a/e2e/add_nums_with_bridge/neva.yml b/e2e/add_nums_with_bridge/neva.yml deleted file mode 100644 index 8a5439ab..00000000 --- a/e2e/add_nums_with_bridge/neva.yml +++ /dev/null @@ -1 +0,0 @@ -neva: 0.26.0 \ No newline at end of file diff --git a/e2e/comments/e2e_test.go b/e2e/comments/e2e_test.go index 985518fd..16d404f0 100644 --- a/e2e/comments/e2e_test.go +++ b/e2e/comments/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "\n", + "{}\n", string(out), ) diff --git a/e2e/echo_verbose/main/main.neva b/e2e/echo_verbose/main/main.neva index d55748e6..adc8c761 100644 --- a/e2e/echo_verbose/main/main.neva +++ b/e2e/echo_verbose/main/main.neva @@ -1,10 +1,10 @@ import { io } flow Main(start any) (stop any) { - scanner io.Scanln + io.Scanln println Println --- - :start -> scanner:sig - scanner:data -> println:data + :start -> scanln:sig + scanln:res -> println:data println:sig -> :stop } \ No newline at end of file diff --git a/e2e/enums_verbose/e2e_test.go b/e2e/enums_verbose/e2e_test.go index 4eaf2263..aa8337f2 100644 --- a/e2e/enums_verbose/e2e_test.go +++ b/e2e/enums_verbose/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "4\n", + "Friday\n", string(out), ) diff --git a/e2e/for_with_range_and_if/e2e_test.go b/e2e/for_with_range_and_if/e2e_test.go index 51a8963e..0c6a693f 100644 --- a/e2e/for_with_range_and_if/e2e_test.go +++ b/e2e/for_with_range_and_if/e2e_test.go @@ -9,18 +9,20 @@ import ( func Test(t *testing.T) { for i := 0; i < 10; i++ { - cmd := exec.Command("neva", "run", "main") + t.Run("", func(t *testing.T) { + cmd := exec.Command("neva", "run", "main") - out, err := cmd.CombinedOutput() - require.NoError(t, err, "out: ", out) + out, err := cmd.CombinedOutput() + require.NoError(t, err, "out: ", out) - require.Equal( - t, - "1\n0\n", - string(out), - "iteration: %d", i, - ) + require.Equal( + t, + "1\n0\n", + string(out), + "iteration: %d", i, + ) - require.Equal(t, 0, cmd.ProcessState.ExitCode()) + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) } } diff --git a/e2e/incompat_comp_type_arg/e2e_test.go b/e2e/incompat_comp_type_arg/e2e_test.go index c8538630..e4f5fd85 100644 --- a/e2e/incompat_comp_type_arg/e2e_test.go +++ b/e2e/incompat_comp_type_arg/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "main/main.neva:2:1 Subtype must be either union or literal: want int | float, got any\n", + "build failed: main/main.neva:2:1 Subtype must be either union or literal: want int | float, got any\n", string(out), ) diff --git a/e2e/incompat_types_with_untyped_port/.DS_Store b/e2e/incompat_types_with_untyped_port/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 println: Subtype inst must have same ref as supertype: got any, want int", + ), + "Error message should end with expected suffix", ) - require.True( - t, - strings.HasSuffix(actualOutput, expectedErrorSuffix), - "Error message should end with expected suffix") - - // Check if all expected fields are present in the error message - for _, field := range expectedFields { - require.Contains(t, actualOutput, field, "Error message should contain field: "+field) - } require.Equal(t, 0, cmd.ProcessState.ExitCode()) } diff --git a/e2e/incompat_types_with_untyped_port/main/main.neva b/e2e/incompat_types_with_untyped_port/main/main.neva index 47472388..c688bf37 100644 --- a/e2e/incompat_types_with_untyped_port/main/main.neva +++ b/e2e/incompat_types_with_untyped_port/main/main.neva @@ -1,17 +1,11 @@ flow Main(start) (stop) { - Sworktest - ArrPortToStream - Println + PrintAny --- - :start -> [ - (1 -> arrPortToStream[0]), - (2 -> arrPortToStream[1]) - ] - arrPortToStream -> sworktest -> println -> :stop + :start -> (42 -> printAny -> :stop) } -flow Sworktest(in) (out) { - Add +flow PrintAny(data) (sig) { + Println --- - :in -> add -> :out + :data -> println -> :sig } diff --git a/e2e/interface_anonymous/e2e_test.go b/e2e/interface_anonymous/e2e_test.go index 985518fd..16d404f0 100644 --- a/e2e/interface_anonymous/e2e_test.go +++ b/e2e/interface_anonymous/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "\n", + "{}\n", string(out), ) diff --git a/e2e/interface_verbose/e2e_test.go b/e2e/interface_verbose/e2e_test.go index 985518fd..16d404f0 100644 --- a/e2e/interface_verbose/e2e_test.go +++ b/e2e/interface_verbose/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "\n", + "{}\n", string(out), ) diff --git a/e2e/interface_with_imports/e2e_test.go b/e2e/interface_with_imports/e2e_test.go index 985518fd..16d404f0 100644 --- a/e2e/interface_with_imports/e2e_test.go +++ b/e2e/interface_with_imports/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "\n", + "{}\n", string(out), ) diff --git a/e2e/simple_fan_out/e2e_test.go b/e2e/simple_fan_out/e2e_test.go index 05a27637..08d39aa9 100644 --- a/e2e/simple_fan_out/e2e_test.go +++ b/e2e/simple_fan_out/e2e_test.go @@ -14,7 +14,7 @@ func Test(t *testing.T) { require.NoError(t, err) require.Equal( t, - "\n\n", + "{}\n{}\n", string(out), ) diff --git a/examples/add_numbers_from_stdin/e2e_test.go b/examples/add_numbers_from_stdin/e2e_test.go new file mode 100644 index 00000000..7f2a306a --- /dev/null +++ b/examples/add_numbers_from_stdin/e2e_test.go @@ -0,0 +1,38 @@ +package test + +import ( + "os" + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + err := os.Chdir("..") + require.NoError(t, err) + + wd, err := os.Getwd() + require.NoError(t, err) + defer os.Chdir(wd) + + for i := 0; i < 1; i++ { + t.Run("Add numbers from stdin", func(t *testing.T) { + cmd := exec.Command("neva", "run", "add_numbers_from_stdin") + + cmd.Stdin = strings.NewReader("3\n4\n\n") + + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "7\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } +} diff --git a/examples/add_numbers_from_stdin/main.neva b/examples/add_numbers_from_stdin/main.neva index 34c453de..d2e7448b 100644 --- a/examples/add_numbers_from_stdin/main.neva +++ b/examples/add_numbers_from_stdin/main.neva @@ -10,11 +10,11 @@ flow Main(start) (stop) { flow App(sig) (res int, err error) { readFirstInt ReadIntFromStdin readSecondInt ReadIntFromStdin - add ReducePort { Add } + add Add --- :sig -> readFirstInt - readFirstInt:num -> [add[0], readSecondInt] - readSecondInt:num -> add[1] + readFirstInt:num -> [add:acc, readSecondInt] + readSecondInt:num -> add:el [readFirstInt:err, readSecondInt:err] -> :err add -> :res } diff --git a/examples/echo/e2e_test.go b/examples/echo/e2e_test.go index d152d0d1..365b799e 100644 --- a/examples/echo/e2e_test.go +++ b/examples/echo/e2e_test.go @@ -17,17 +17,21 @@ func Test(t *testing.T) { require.NoError(t, err) defer os.Chdir(wd) - cmd := exec.Command("neva", "run", "echo") - - cmd.Stdin = strings.NewReader("yo\n") - out, err := cmd.CombinedOutput() - require.NoError(t, err) - - require.Equal( - t, - "yo\n", - string(out), - ) - - require.Equal(t, 0, cmd.ProcessState.ExitCode()) + for i := 0; i < 1; i++ { + t.Run("Echo Test", func(t *testing.T) { + cmd := exec.Command("neva", "run", "echo") + + cmd.Stdin = strings.NewReader("yo\n") + out, err := cmd.CombinedOutput() + require.NoError(t, err) + + require.Equal( + t, + "yo\n", + string(out), + ) + + require.Equal(t, 0, cmd.ProcessState.ExitCode()) + }) + } } diff --git a/examples/fizzbuzz/e2e_test.go b/examples/fizzbuzz/e2e_test.go index ae3398c2..ee999d10 100644 --- a/examples/fizzbuzz/e2e_test.go +++ b/examples/fizzbuzz/e2e_test.go @@ -18,7 +18,7 @@ func Test(t *testing.T) { require.NoError(t, err) defer os.Chdir(wd) - for i := 0; i < 1; i++ { + t.Run("FizzBuzz Test", func(t *testing.T) { cmd := exec.Command("neva", "run", "fizzbuzz") // Set a timeout for the command @@ -41,7 +41,7 @@ func Test(t *testing.T) { ) require.Equal(t, 0, cmd.ProcessState.ExitCode()) - } + }) } var expected = `1 diff --git a/examples/fizzbuzz/main.neva b/examples/fizzbuzz/main.neva index 566512e7..d775f88c 100644 --- a/examples/fizzbuzz/main.neva +++ b/examples/fizzbuzz/main.neva @@ -10,9 +10,7 @@ flow Main(start) (stop) { flow FizzBuzz(data int) (res string|int) { Select, Mod15, Mod3, Mod5 - --- - :data -> [mod15, select:then[3]] mod15:then -> select:if[0] @@ -57,12 +55,9 @@ flow Mod5(num int) (then int, else int) { h:else -> :else } -// ModHelper checks if num can be devided by den flow ModHelper(num int, den int) (then int, else int) { Mod, Eq, Cond - --- - :num -> [mod:num, cond:data] :den -> mod:den diff --git a/examples/for_loop_over_list/e2e_test.go b/examples/for_loop_over_list/e2e_test.go index 40e182bc..3e24e082 100644 --- a/examples/for_loop_over_list/e2e_test.go +++ b/examples/for_loop_over_list/e2e_test.go @@ -20,22 +20,24 @@ func Test(t *testing.T) { // We do 100 attempts to prove that implementation is correct // and order of elements is always the same. for i := 0; i < 100; i++ { - cmd := exec.Command("neva", "run", "for_loop_over_list") - out, err := cmd.CombinedOutput() - if err != nil { - exitError, ok := err.(*exec.ExitError) - if ok { - t.Fatalf("Command failed with exit code %d. Error output:\n%s", exitError.ExitCode(), string(out)) - } else { - t.Fatalf("Command failed with error: %v. Output:\n%s", err, string(out)) + t.Run(fmt.Sprintf("Iteration %d", i), func(t *testing.T) { + cmd := exec.Command("neva", "run", "for_loop_over_list") + out, err := cmd.CombinedOutput() + if err != nil { + exitError, ok := err.(*exec.ExitError) + if ok { + t.Fatalf("Command failed with exit code %d. Error output:\n%s", exitError.ExitCode(), string(out)) + } else { + t.Fatalf("Command failed with error: %v. Output:\n%s", err, string(out)) + } } - } - require.Equal( - t, - "1\n2\n3\n", - string(out), - fmt.Sprintf("Unexpected output on iteration %d", i), - ) - require.Equal(t, 0, cmd.ProcessState.ExitCode(), fmt.Sprintf("Unexpected exit code on iteration %d", i)) + require.Equal( + t, + "1\n2\n3\n", + string(out), + "Unexpected output", + ) + require.Equal(t, 0, cmd.ProcessState.ExitCode(), "Unexpected exit code") + }) } } diff --git a/examples/get_args/main.neva b/examples/get_args/main.neva index d0eee5c6..b7016a64 100644 --- a/examples/get_args/main.neva +++ b/examples/get_args/main.neva @@ -1,4 +1,4 @@ -import { os, lists } +import { os } flow Main(start) (stop) { os.Args, ListToStream, ForEach{Println}, Wait diff --git a/internal/runtime/funcs/scanln.go b/internal/runtime/funcs/scanln.go index 6da5dec2..d98c8afc 100644 --- a/internal/runtime/funcs/scanln.go +++ b/internal/runtime/funcs/scanln.go @@ -1,40 +1,38 @@ package funcs import ( - "bufio" "context" - "os" + "fmt" "github.com/nevalang/neva/internal/runtime" ) type scanln struct{} -func (r scanln) Create(io runtime.IO, _ runtime.Msg) (func(ctx context.Context), error) { - sigIn, err := io.In.Single("sig") +// TODO add `:err` outport +func (r scanln) Create(rio runtime.IO, _ runtime.Msg) (func(ctx context.Context), error) { + sigIn, err := rio.In.Single("sig") if err != nil { return nil, err } - resOut, err := io.Out.Single("res") + resOut, err := rio.Out.Single("res") if err != nil { return nil, err } return func(ctx context.Context) { for { - reader := bufio.NewReader(os.Stdin) - if _, ok := sigIn.Receive(ctx); !ok { return } - bb, _, err := reader.ReadLine() - if err != nil { + var input string + if _, err := fmt.Scanln(&input); err != nil { panic(err) } - if !resOut.Send(ctx, runtime.NewStringMsg(string(bb))) { + if !resOut.Send(ctx, runtime.NewStringMsg(input)) { return } } diff --git a/std/builtin/routers.neva b/std/builtin/routers.neva index 0f7158df..42327e7d 100644 --- a/std/builtin/routers.neva +++ b/std/builtin/routers.neva @@ -34,4 +34,7 @@ pub flow FanIn([data] T) (res T) // (data T, [if] any) ([then] T, else T) // it's like a mix between Switch and Select // - it's like a switch, but it cares where data came from, not what data is -// - it's like a select, but it cares where to send data, not what to send \ No newline at end of file +// - it's like a select, but it cares where to send data, not what to send + +// MatchSwitch maps and routes the data. +// pub flow MatchSwitch(data T, [if] T, [then] T, else T) ([then] T, else T) diff --git a/std/builtin/streams.neva b/std/builtin/streams.neva index b369b52b..b6f0bcb1 100644 --- a/std/builtin/streams.neva +++ b/std/builtin/streams.neva @@ -22,17 +22,6 @@ pub flow ArrPortToStream([port] T) (data stream) // It's expected to send a result message after every processed stream. pub interface IPortReducer(data stream) (res T) -// ReducePort reduces messages from multiple connections to a single message. -// It iterates over all array-inport's slots in order and streams every message -// to reducer. When all messages are processed the result is emited to outport. -pub flow ReducePort([port] T) (res T) { - reducer IPortReducer - streamer ArrPortToStream - --- - :port => streamer:port - streamer -> reducer -> :res -} - // === Iterators === // These constants are used for binding by Field flow.