tests: move midas parser tests in subfolder

This commit is contained in:
2026-05-29 18:39:25 +02:00
parent 86e4763a12
commit e2d5943517
5 changed files with 14 additions and 11 deletions

View File

@@ -25,8 +25,8 @@ class Tester(ABC):
def base_dir(self) -> Path:
return self.CASES_DIR / self.namespace
def _list_tests(self) -> list[Path]:
return list(self.base_dir.rglob("*.midas"))
@abstractmethod
def _list_tests(self) -> list[Path]: ...
def run_all_tests(self) -> bool:
paths: list[Path] = self._list_tests()

View File

@@ -2170,8 +2170,8 @@
"stmts": [
{
"_type": "SimpleTypeStmt",
"template": null,
"name": "Custom",
"template": null,
"base": {
"_type": "TypeExpr",
"name": "float",
@@ -2182,8 +2182,8 @@
},
{
"_type": "SimpleTypeStmt",
"template": null,
"name": "Latitude",
"template": null,
"base": {
"_type": "TypeExpr",
"name": "float",
@@ -2219,8 +2219,8 @@
},
{
"_type": "SimpleTypeStmt",
"template": null,
"name": "Longitude",
"template": null,
"base": {
"_type": "TypeExpr",
"name": "float",
@@ -2256,6 +2256,7 @@
},
{
"_type": "SimpleTypeStmt",
"name": "Difference",
"template": {
"_type": "TemplateExpr",
"type": {
@@ -2265,7 +2266,6 @@
"optional": false
}
},
"name": "Difference",
"base": {
"_type": "TypeExpr",
"name": "T",

View File

@@ -3,13 +3,13 @@ from dataclasses import asdict, dataclass, field
from pathlib import Path
from typing import Optional
from midas.ast.json_serializer import AstJsonSerializer
from midas.ast.midas import Stmt
from midas.lexer.base import MidasSyntaxError
from midas.lexer.midas import MidasLexer
from midas.lexer.token import Token
from midas.parser.midas import MidasParser
from tests.base import Tester
from tests.serializer.midas import MidasAstJsonSerializer
@dataclass
@@ -25,7 +25,10 @@ class CaseResult:
class MidasTester(Tester):
@property
def namespace(self) -> str:
return "parser"
return "midas-parser"
def _list_tests(self) -> list[Path]:
return list(self.base_dir.rglob("*.midas"))
def _exec_case(self, path: Path) -> CaseResult:
if not path.exists():
@@ -61,7 +64,7 @@ class MidasTester(Tester):
parser: MidasParser = MidasParser(tokens)
stmts: list[Stmt] = parser.parse()
result.stmts = AstJsonSerializer().serialize(stmts)
result.stmts = MidasAstJsonSerializer().serialize(stmts)
result.errors.extend(
[
{

View File

@@ -23,7 +23,7 @@ from midas.ast.midas import (
)
class AstJsonSerializer(Stmt.Visitor[dict], Expr.Visitor[dict]):
class MidasAstJsonSerializer(Stmt.Visitor[dict], Expr.Visitor[dict]):
"""An AST serializer which produces a JSON-compatible structure"""
def serialize(self, stmts: list[Stmt]) -> list[dict]:
@@ -40,8 +40,8 @@ class AstJsonSerializer(Stmt.Visitor[dict], Expr.Visitor[dict]):
def visit_simple_type_stmt(self, stmt: SimpleTypeStmt) -> dict:
return {
"_type": "SimpleTypeStmt",
"template": self._serialize_optional(stmt.template),
"name": stmt.name.lexeme,
"template": self._serialize_optional(stmt.template),
"base": stmt.base.accept(self),
"constraint": self._serialize_optional(stmt.constraint),
}