Skip to content

Commit

Permalink
tests: Add infrastructure for y4 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Oct 26, 2024
1 parent f7dcb9d commit b1d7f68
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/map.y4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!<tag:y4.managarm.org:preamble>
import:
- !std
---
result:
!std::map
list: [1, 2, 3, 4]
fn:
!std::fn
args: [!x ]
return: !std::add [!x , 100]
expected:
[101, 102, 103, 104]
14 changes: 14 additions & 0 deletions tests/reduce.y4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
!<tag:y4.managarm.org:preamble>
import:
- !std
---
result:
!std::reduce
list: [1, 2, 3]
init: 100
fn:
!std::fn
args: [!x , !y ]
return: !std::add [!x , !y ]
expected:
106
20 changes: 20 additions & 0 deletions tests/test_y4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import pytest
import subprocess
import sys
import yaml

cases = [
"map.y4.yml",
"reduce.y4.yml",
]


@pytest.mark.parametrize("path", cases)
def test_y4(path):
args = [sys.executable, "-m", "y4", os.path.join("tests", path)]
result = subprocess.run(args, stdout=subprocess.PIPE)
assert result.returncode == 0

yml = yaml.load(result.stdout, Loader=yaml.SafeLoader)
assert yml["result"] == yml["expected"]

0 comments on commit b1d7f68

Please sign in to comment.