tests: move midas parser tests in subfolder
This commit is contained in:
@@ -25,8 +25,8 @@ class Tester(ABC):
|
|||||||
def base_dir(self) -> Path:
|
def base_dir(self) -> Path:
|
||||||
return self.CASES_DIR / self.namespace
|
return self.CASES_DIR / self.namespace
|
||||||
|
|
||||||
def _list_tests(self) -> list[Path]:
|
@abstractmethod
|
||||||
return list(self.base_dir.rglob("*.midas"))
|
def _list_tests(self) -> list[Path]: ...
|
||||||
|
|
||||||
def run_all_tests(self) -> bool:
|
def run_all_tests(self) -> bool:
|
||||||
paths: list[Path] = self._list_tests()
|
paths: list[Path] = self._list_tests()
|
||||||
|
|||||||
@@ -2170,8 +2170,8 @@
|
|||||||
"stmts": [
|
"stmts": [
|
||||||
{
|
{
|
||||||
"_type": "SimpleTypeStmt",
|
"_type": "SimpleTypeStmt",
|
||||||
"template": null,
|
|
||||||
"name": "Custom",
|
"name": "Custom",
|
||||||
|
"template": null,
|
||||||
"base": {
|
"base": {
|
||||||
"_type": "TypeExpr",
|
"_type": "TypeExpr",
|
||||||
"name": "float",
|
"name": "float",
|
||||||
@@ -2182,8 +2182,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_type": "SimpleTypeStmt",
|
"_type": "SimpleTypeStmt",
|
||||||
"template": null,
|
|
||||||
"name": "Latitude",
|
"name": "Latitude",
|
||||||
|
"template": null,
|
||||||
"base": {
|
"base": {
|
||||||
"_type": "TypeExpr",
|
"_type": "TypeExpr",
|
||||||
"name": "float",
|
"name": "float",
|
||||||
@@ -2219,8 +2219,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_type": "SimpleTypeStmt",
|
"_type": "SimpleTypeStmt",
|
||||||
"template": null,
|
|
||||||
"name": "Longitude",
|
"name": "Longitude",
|
||||||
|
"template": null,
|
||||||
"base": {
|
"base": {
|
||||||
"_type": "TypeExpr",
|
"_type": "TypeExpr",
|
||||||
"name": "float",
|
"name": "float",
|
||||||
@@ -2256,6 +2256,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_type": "SimpleTypeStmt",
|
"_type": "SimpleTypeStmt",
|
||||||
|
"name": "Difference",
|
||||||
"template": {
|
"template": {
|
||||||
"_type": "TemplateExpr",
|
"_type": "TemplateExpr",
|
||||||
"type": {
|
"type": {
|
||||||
@@ -2265,7 +2266,6 @@
|
|||||||
"optional": false
|
"optional": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "Difference",
|
|
||||||
"base": {
|
"base": {
|
||||||
"_type": "TypeExpr",
|
"_type": "TypeExpr",
|
||||||
"name": "T",
|
"name": "T",
|
||||||
@@ -3,13 +3,13 @@ from dataclasses import asdict, dataclass, field
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from midas.ast.json_serializer import AstJsonSerializer
|
|
||||||
from midas.ast.midas import Stmt
|
from midas.ast.midas import Stmt
|
||||||
from midas.lexer.base import MidasSyntaxError
|
from midas.lexer.base import MidasSyntaxError
|
||||||
from midas.lexer.midas import MidasLexer
|
from midas.lexer.midas import MidasLexer
|
||||||
from midas.lexer.token import Token
|
from midas.lexer.token import Token
|
||||||
from midas.parser.midas import MidasParser
|
from midas.parser.midas import MidasParser
|
||||||
from tests.base import Tester
|
from tests.base import Tester
|
||||||
|
from tests.serializer.midas import MidasAstJsonSerializer
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -25,7 +25,10 @@ class CaseResult:
|
|||||||
class MidasTester(Tester):
|
class MidasTester(Tester):
|
||||||
@property
|
@property
|
||||||
def namespace(self) -> str:
|
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:
|
def _exec_case(self, path: Path) -> CaseResult:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
@@ -61,7 +64,7 @@ class MidasTester(Tester):
|
|||||||
|
|
||||||
parser: MidasParser = MidasParser(tokens)
|
parser: MidasParser = MidasParser(tokens)
|
||||||
stmts: list[Stmt] = parser.parse()
|
stmts: list[Stmt] = parser.parse()
|
||||||
result.stmts = AstJsonSerializer().serialize(stmts)
|
result.stmts = MidasAstJsonSerializer().serialize(stmts)
|
||||||
result.errors.extend(
|
result.errors.extend(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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"""
|
"""An AST serializer which produces a JSON-compatible structure"""
|
||||||
|
|
||||||
def serialize(self, stmts: list[Stmt]) -> list[dict]:
|
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:
|
def visit_simple_type_stmt(self, stmt: SimpleTypeStmt) -> dict:
|
||||||
return {
|
return {
|
||||||
"_type": "SimpleTypeStmt",
|
"_type": "SimpleTypeStmt",
|
||||||
"template": self._serialize_optional(stmt.template),
|
|
||||||
"name": stmt.name.lexeme,
|
"name": stmt.name.lexeme,
|
||||||
|
"template": self._serialize_optional(stmt.template),
|
||||||
"base": stmt.base.accept(self),
|
"base": stmt.base.accept(self),
|
||||||
"constraint": self._serialize_optional(stmt.constraint),
|
"constraint": self._serialize_optional(stmt.constraint),
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user