diff --git a/tests/cases/checker/01_simple_types.py b/tests/cases/checker/01_simple_types.py new file mode 100644 index 0000000..3566f9a --- /dev/null +++ b/tests/cases/checker/01_simple_types.py @@ -0,0 +1,14 @@ +# type: ignore +# ruff: disable[F821] +from __future__ import annotations + +df: Frame[ + verified: bool, + birth_year: int, + height: float + ( _ > 0 ) + ( _ < 250 ), + name: str, + date: datetime, + float, + unknown: _, + _ +] diff --git a/tests/cases/checker/01_simple_types.py.ref.json b/tests/cases/checker/01_simple_types.py.ref.json new file mode 100644 index 0000000..c37fb01 --- /dev/null +++ b/tests/cases/checker/01_simple_types.py.ref.json @@ -0,0 +1,3 @@ +{ + "diagnostics": [] +} \ No newline at end of file diff --git a/tests/cases/checker/02_simple_operations.py b/tests/cases/checker/02_simple_operations.py new file mode 100644 index 0000000..9e936c1 --- /dev/null +++ b/tests/cases/checker/02_simple_operations.py @@ -0,0 +1,11 @@ +a: int = 3 +b: int = 4 + +c = a + b + +c = "invalid" + +d = True +e = d + d + +f: float = a diff --git a/tests/cases/checker/02_simple_operations.py.ref.json b/tests/cases/checker/02_simple_operations.py.ref.json new file mode 100644 index 0000000..c390e27 --- /dev/null +++ b/tests/cases/checker/02_simple_operations.py.ref.json @@ -0,0 +1,46 @@ +{ + "diagnostics": [ + { + "type": "Error", + "location": { + "start": [ + 6, + 0 + ], + "end": [ + 6, + 13 + ] + }, + "message": "Cannot assign BaseType(name='str') to c of type BaseType(name='int')" + }, + { + "type": "Error", + "location": { + "start": [ + 9, + 4 + ], + "end": [ + 9, + 9 + ] + }, + "message": "Undefined operation __add__ between BaseType(name='bool') and BaseType(name='bool')" + }, + { + "type": "Error", + "location": { + "start": [ + 11, + 0 + ], + "end": [ + 11, + 12 + ] + }, + "message": "Cannot assign BaseType(name='int') to f of type BaseType(name='float')" + } + ] +} \ No newline at end of file diff --git a/tests/cases/checker/03_functions.py b/tests/cases/checker/03_functions.py new file mode 100644 index 0000000..ddc0a56 --- /dev/null +++ b/tests/cases/checker/03_functions.py @@ -0,0 +1,18 @@ +def foo(a: int, /, b: float, *, c: str): + return True + + +r1 = foo() +r2 = foo(1) +r3 = foo(1, 2.0) +r4 = foo(1, b=2.0) +r5 = foo(1, 2.0, "test") +r6 = foo(1, 2.0, b=3.0) +r7 = foo(a=1) +r8 = foo(g="test") + +r9a = foo(1, 2.0, c="test") +r9b = foo(1, b=2.0, c="test") +r9c = foo(1, c="test", b=2.0) + +r10 = foo("a", 3, c=False) diff --git a/tests/cases/checker/03_functions.py.ref.json b/tests/cases/checker/03_functions.py.ref.json new file mode 100644 index 0000000..40b33b5 --- /dev/null +++ b/tests/cases/checker/03_functions.py.ref.json @@ -0,0 +1,270 @@ +{ + "diagnostics": [ + { + "type": "Error", + "location": { + "start": [ + 5, + 5 + ], + "end": [ + 5, + 10 + ] + }, + "message": "Missing required positional arguments: 'a' and 'b'" + }, + { + "type": "Error", + "location": { + "start": [ + 5, + 5 + ], + "end": [ + 5, + 10 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 6, + 5 + ], + "end": [ + 6, + 11 + ] + }, + "message": "Missing required positional argument: 'b'" + }, + { + "type": "Error", + "location": { + "start": [ + 6, + 5 + ], + "end": [ + 6, + 11 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 7, + 5 + ], + "end": [ + 7, + 16 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 8, + 5 + ], + "end": [ + 8, + 18 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 9, + 17 + ], + "end": [ + 9, + 23 + ] + }, + "message": "Too many positional arguments" + }, + { + "type": "Error", + "location": { + "start": [ + 9, + 5 + ], + "end": [ + 9, + 24 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 10, + 19 + ], + "end": [ + 10, + 22 + ] + }, + "message": "Multiple values for argument 'b'" + }, + { + "type": "Error", + "location": { + "start": [ + 10, + 5 + ], + "end": [ + 10, + 23 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 11, + 11 + ], + "end": [ + 11, + 12 + ] + }, + "message": "Unknown keyword argument 'a'" + }, + { + "type": "Error", + "location": { + "start": [ + 11, + 5 + ], + "end": [ + 11, + 13 + ] + }, + "message": "Missing required positional arguments: 'a' and 'b'" + }, + { + "type": "Error", + "location": { + "start": [ + 11, + 5 + ], + "end": [ + 11, + 13 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 12, + 11 + ], + "end": [ + 12, + 17 + ] + }, + "message": "Unknown keyword argument 'g'" + }, + { + "type": "Error", + "location": { + "start": [ + 12, + 5 + ], + "end": [ + 12, + 18 + ] + }, + "message": "Missing required positional arguments: 'a' and 'b'" + }, + { + "type": "Error", + "location": { + "start": [ + 12, + 5 + ], + "end": [ + 12, + 18 + ] + }, + "message": "Missing required keyword argument: 'c'" + }, + { + "type": "Error", + "location": { + "start": [ + 18, + 10 + ], + "end": [ + 18, + 13 + ] + }, + "message": "Wrong type for argument 'a', expected BaseType(name='int'), got BaseType(name='str')" + }, + { + "type": "Error", + "location": { + "start": [ + 18, + 15 + ], + "end": [ + 18, + 16 + ] + }, + "message": "Wrong type for argument 'b', expected BaseType(name='float'), got BaseType(name='int')" + }, + { + "type": "Error", + "location": { + "start": [ + 18, + 20 + ], + "end": [ + 18, + 25 + ] + }, + "message": "Wrong type for argument 'c', expected BaseType(name='str'), got BaseType(name='bool')" + } + ] +} \ No newline at end of file diff --git a/tests/cases/checker/04_custom_types.midas b/tests/cases/checker/04_custom_types.midas new file mode 100644 index 0000000..eee3eb9 --- /dev/null +++ b/tests/cases/checker/04_custom_types.midas @@ -0,0 +1,14 @@ +type Meter(float) +type Second(float) +type MeterPerSecond(float) + +extend Meter { + op __add__(Meter) -> Meter + op __sub__(Meter) -> Meter + op __truediv__(Second) -> MeterPerSecond +} + +extend Second { + op __add__(Second) -> Second + op __sub__(Second) -> Second +} diff --git a/tests/cases/checker/04_custom_types.py b/tests/cases/checker/04_custom_types.py new file mode 100644 index 0000000..d176181 --- /dev/null +++ b/tests/cases/checker/04_custom_types.py @@ -0,0 +1,8 @@ +# type: ignore +# ruff: disable [F821] + +midas.using("04_custom_types.midas") + +distance: Meter = 123.45 +time: Second = 6.7 +speed = distance / time diff --git a/tests/cases/checker/04_custom_types.py.ref.json b/tests/cases/checker/04_custom_types.py.ref.json new file mode 100644 index 0000000..de13745 --- /dev/null +++ b/tests/cases/checker/04_custom_types.py.ref.json @@ -0,0 +1,32 @@ +{ + "diagnostics": [ + { + "type": "Error", + "location": { + "start": [ + 6, + 0 + ], + "end": [ + 6, + 24 + ] + }, + "message": "Cannot assign BaseType(name='float') to distance of type SimpleType(name='Meter', base=BaseType(name='float'))" + }, + { + "type": "Error", + "location": { + "start": [ + 7, + 0 + ], + "end": [ + 7, + 18 + ] + }, + "message": "Cannot assign BaseType(name='float') to time of type SimpleType(name='Second', base=BaseType(name='float'))" + } + ] +} \ No newline at end of file