Skip to content
Open
14 changes: 8 additions & 6 deletions e2e/array_inport_holes/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { fmt }

def Main(start any) (stop any) {
fmt.Printf
---
:start -> '$1 $2 $3' -> printf:tpl
1 -> printf:args[0]
3 -> printf:args[2]
[printf:sig, printf:err] -> :stop
fmt.Printf
---
:start -> [
'$1 $2 $3' -> printf:tpl,
1 -> printf:args[0],
3 -> printf:args[2]
]
[printf:sig, printf:err] -> :stop
}
17 changes: 17 additions & 0 deletions e2e/compiler_error_autonomous_const/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package test

import (
"testing"

"github.com/nevalang/neva/pkg/e2e"
"github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
out, err := e2e.RunExpectingError(t, "run", "main")
require.Contains(
t,
out+err,
"Constants must be triggered by a signal (e.g. :start -> 42 -> ...)",
)
}
11 changes: 11 additions & 0 deletions e2e/compiler_error_autonomous_const/main/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { fmt }

const myConst string = 'Hello, World!'

def Main(start any) (stop any) {
p1 fmt.Println
p2 fmt.Println
---
:start -> p1
$myConst -> p2
}
1 change: 1 addition & 0 deletions e2e/compiler_error_autonomous_const/neva.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neva: 0.32.0
2 changes: 1 addition & 1 deletion e2e/compiler_error_unused_outport/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def Main(start any) (stop any) {
---
:start -> 'Hi, Neva!' -> sub1:data
sub1:stop-> :stop
'1' -> sub2
:start -> '1' -> sub2
}

// Here we are panicking inside the sub-component instead of propagating the error.
Expand Down
6 changes: 4 additions & 2 deletions e2e/errors_must/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def Main(start any) (stop any) {
def Handler(data string) (res any, err error) {
write_all io.WriteAll?
---
:data -> write_all:filename
'Hello, io.WriteAll!' -> write_all:data
:data -> [
write_all:filename,
'Hello, io.WriteAll!' -> write_all:data
]
write_all:res -> :res
}
20 changes: 11 additions & 9 deletions e2e/hello_world_with_const_sender/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
const greeting string = 'Hello, World!'

def Main(start any) (stop any) {
println fmt.Println<string>
lock Lock<string>
panic runtime.Panic
---
:start -> lock:sig
$greeting -> lock:data
lock:data -> println:data
println:res -> :stop
println:err -> panic
println fmt.Println<string>
lock Lock<string>
panic runtime.Panic
---
:start -> [
lock:sig,
$greeting -> lock:data
]
lock:data -> println:data
println:res -> :stop
println:err -> panic
}
22 changes: 12 additions & 10 deletions e2e/multiply_numbers/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {
const l list<int> = [1, 2, 3]

def Main(start any) (stop any) {
fmt.Println<int>
Reduce<int, int>{Mul}
ListToStream<int>
panic runtime.Panic
---
:start -> $l -> listToStream -> reduce:data
1 -> reduce:init
reduce -> println:data
println:res -> :stop
println:err -> panic
fmt.Println<int>
Reduce<int, int>{Mul}
ListToStream<int>
panic runtime.Panic
---
:start -> [
$l -> listToStream -> reduce:data,
1 -> reduce:init
]
reduce -> println:data
println:res -> :stop
println:err -> panic
}
20 changes: 11 additions & 9 deletions e2e/order_dependend_with_arr_inport/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const l list<int> = [1, 2, 3]

def Main(start any) (stop any) {
fmt.Println<int>
Reduce<int, int>{Sub}
ListToStream<int>
panic runtime.Panic
---
:start -> $l -> listToStream -> reduce:data
0 -> reduce:init
reduce -> println:data
println:res -> :stop
println:err -> panic
Reduce<int, int>{Sub}
ListToStream<int>
panic runtime.Panic
---
:start -> [
$l -> listToStream -> reduce:data,
0 -> reduce:init
]
reduce -> println:data
println:res -> :stop
println:err -> panic
}
6 changes: 4 additions & 2 deletions e2e/slow_iteration_with_for/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def Slow(data int) (res any, err error) {
time.Delay<int>
fmt.Println<int>?
---
:data -> delay:data
$time.second -> delay:dur
:data -> [
delay:data,
$time.second -> delay:dur
]
delay -> println:data
println:res -> :res
}
6 changes: 4 additions & 2 deletions e2e/slow_iteration_with_map/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def Slow(data int) (res int) {
delay time.Delay<int>
dec Dec
---
:data -> delay:data
$time.second -> delay:dur
:data -> [
delay:data,
$time.second -> delay:dur
]
delay -> dec -> :res
}
8 changes: 5 additions & 3 deletions examples/compare_values/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def Main(start any) (stop any) {
2 -> eq:left,
2 -> eq:right
]
eq -> ternary:if
'They match' -> ternary:then
'They do not match' -> ternary:else
eq -> [
ternary:if,
'They match' -> ternary:then,
'They do not match' -> ternary:else
]
ternary -> println
println:res -> :stop
println:err -> panic
Expand Down
34 changes: 18 additions & 16 deletions examples/delayed_echo/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@ def Main(start any) (stop any) {
wg sync.WaitGroup
panic runtime.Panic
---
:start -> [
'Hello' -> println,
1 -> w1,
:start -> [
'Hello' -> println,
1 -> w1,
2 -> w2,
3 -> w3,
4 -> w4,
5 -> w5,
'World' -> w6
]
6 -> wg:count
[w1:sig, w2:sig, w3:sig, w4:sig, w5:sig, w6:sig, println:res] -> wg:sig
wg -> :stop
4 -> w4,
5 -> w5,
'World' -> w6,
6 -> wg:count
]
[w1:sig, w2:sig, w3:sig, w4:sig, w5:sig, w6:sig, println:res] -> wg:sig
wg -> :stop
[w1:err, w2:err, w3:err, w4:err, w5:err, w6:err, println:err] -> panic
}

def Worker(data any) (sig any, err error) {
delay time.Delay
println fmt.Println?
---
:data -> delay:data
$time.second -> delay:dur
delay -> println -> :sig
delay time.Delay
println fmt.Println?
---
:data -> [
delay:data,
$time.second -> delay:dur
]
delay -> println -> :sig
}

// TODO add unit test
6 changes: 4 additions & 2 deletions examples/dict/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const d dict<string> = {
def Main(start any) (stop any) {
Get, fmt.Println, runtime.Panic
---
:start -> 'name' -> get:key
$d -> get:dict
:start -> [
'name' -> get:key,
$d -> get:dict
]
[get:res, get:err] -> println:data
println:res -> :stop
println:err -> panic
Expand Down
6 changes: 2 additions & 4 deletions examples/filter_list/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def IsEven(data int) (res bool) {
mod Mod
eq Eq<int>
---
:data -> mod:left
2 -> mod:right
mod -> eq:left
0 -> eq:right
:data -> [mod:left, 2 -> mod:right]
mod -> [eq:left, 0 -> eq:right]
eq -> :res
}
21 changes: 7 additions & 14 deletions examples/fizzbuzz/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ def FizzBuzz(data int) (res any) {

:data -> [mod15, select:then[3]]

mod15:then -> select:if[0]
'FizzBuzz' -> select:then[0]
mod15:then -> [select:if[0], 'FizzBuzz' -> select:then[0]]
mod15:else -> mod3

mod3:then -> select:if[1]
'Fizz' -> select:then[1]
mod3:then -> [select:if[1], 'Fizz' -> select:then[1]]
mod3:else -> mod5

mod5:then -> select:if[2]
'Buzz' -> select:then[2]
mod5:then -> [select:if[2], 'Buzz' -> select:then[2]]
mod5:else -> select:if[3]

select -> :res
Expand All @@ -43,26 +40,23 @@ def FizzBuzz(data int) (res any) {
def Mod15(num int) (then int, else int) {
h ModHelper
---
:num -> h:num
15 -> h:den
:num -> [h:num, 15 -> h:den]
h:then -> :then
h:else -> :else
}

def Mod3(num int) (then int, else int) {
h ModHelper
---
:num -> h:num
3 -> h:den
:num -> [h:num, 3 -> h:den]
h:then -> :then
h:else -> :else
}

def Mod5(num int) (then int, else int) {
h ModHelper
---
:num -> h:num
5 -> h:den
:num -> [h:num, 5 -> h:den]
h:then -> :then
h:else -> :else
}
Expand All @@ -73,8 +67,7 @@ def ModHelper(num int, den int) (then int, else int) {
:num -> [mod:left, cond:data]
:den -> mod:right

mod -> eq:left
0 -> eq:right
mod -> [eq:left, 0 -> eq:right]
eq -> cond:if

cond:then -> :then
Expand Down
9 changes: 6 additions & 3 deletions examples/image_png/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def NewPixel(x int, y int, c image.RGBA) (pixel image.Pixel) {
:x -> pb:x
:y -> pb:y
:c -> pb:color

pb -> :pixel
}

Expand All @@ -22,9 +23,11 @@ def NewColor(r int, g int, b int, a int) (color image.RGBA) {
def NewStream(p image.Pixel) (s stream<image.Pixel>) {
sb Struct<stream<image.Pixel>>
---
0 -> sb:idx
:p -> sb:data
true -> sb:last
:p -> [
sb:data,
0 -> sb:idx,
true -> sb:last
]
sb -> :s
}

Expand Down
22 changes: 10 additions & 12 deletions examples/match/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ def Handler(data int) (res any, err error) {

---

:data -> match:data

1 -> match:if[0]
'one' -> match:then[0]

2 -> match:if[1]
'two' -> match:then[1]

3 -> match:if[2]
'three' -> match:then[2]

'four' -> match:else
:data -> [
match:data,
1 -> match:if[0],
'one' -> match:then[0],
2 -> match:if[1],
'two' -> match:then[1],
3 -> match:if[2],
'three' -> match:then[2],
'four' -> match:else
]

match -> println -> :res
}
6 changes: 4 additions & 2 deletions examples/reduce_list/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ def Main(start any) (stop any) {
println fmt.Println
panic runtime.Panic
---
:start -> $lst -> l2s -> reduce:data
0 -> reduce:init
:start -> [
$lst -> l2s -> reduce:data,
0 -> reduce:init
]
reduce -> println:data
println:res -> :stop
println:err -> panic
Expand Down
Loading
Loading