tests: add simple gen test
This commit is contained in:
14
tests/cases/generator/01_simple_types.midas
Normal file
14
tests/cases/generator/01_simple_types.midas
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
type Meter = float
|
||||||
|
type Second = float
|
||||||
|
type MeterPerSecond = float
|
||||||
|
|
||||||
|
extend Meter {
|
||||||
|
def __add__: fn(Meter, /) -> Meter
|
||||||
|
def __sub__: fn(Meter, /) -> Meter
|
||||||
|
def __truediv__: fn(Second, /) -> MeterPerSecond
|
||||||
|
}
|
||||||
|
|
||||||
|
extend Second {
|
||||||
|
def __add__: fn(Second, /) -> Second
|
||||||
|
def __sub__: fn(Second, /) -> Second
|
||||||
|
}
|
||||||
5
tests/cases/generator/01_simple_types.py
Normal file
5
tests/cases/generator/01_simple_types.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from midas import cast, Meter, Second
|
||||||
|
|
||||||
|
distance: Meter = cast(Meter, 123.45)
|
||||||
|
time: Second = cast(Second, 6.7)
|
||||||
|
speed = distance / time
|
||||||
79
tests/cases/generator/01_simple_types.py.ref.txt
Normal file
79
tests/cases/generator/01_simple_types.py.ref.txt
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
Module(
|
||||||
|
body=[
|
||||||
|
ImportFrom(
|
||||||
|
module='midas',
|
||||||
|
names=[
|
||||||
|
alias(name='cast'),
|
||||||
|
alias(name='Meter'),
|
||||||
|
alias(name='Second')],
|
||||||
|
level=0),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_alias_0__')],
|
||||||
|
value=Constant(value=123.45)),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_alias_0__'),
|
||||||
|
Name(id='float')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='01_simple_types.py:L3:19: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_alias_0__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to float')])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='distance')],
|
||||||
|
value=Name(id='__midas_alias_0__')),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_alias_0__')]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_alias_1__')],
|
||||||
|
value=Constant(value=6.7)),
|
||||||
|
Assert(
|
||||||
|
test=Call(
|
||||||
|
func=Name(id='isinstance'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_alias_1__'),
|
||||||
|
Name(id='float')],
|
||||||
|
keywords=[]),
|
||||||
|
msg=JoinedStr(
|
||||||
|
values=[
|
||||||
|
Constant(value='01_simple_types.py:L4:16: CastError: Cannot cast '),
|
||||||
|
FormattedValue(
|
||||||
|
value=Attribute(
|
||||||
|
value=Call(
|
||||||
|
func=Name(id='type'),
|
||||||
|
args=[
|
||||||
|
Name(id='__midas_alias_1__')],
|
||||||
|
keywords=[]),
|
||||||
|
attr='__name__'),
|
||||||
|
conversion=-1),
|
||||||
|
Constant(value=' to float')])),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='time')],
|
||||||
|
value=Name(id='__midas_alias_1__')),
|
||||||
|
Delete(
|
||||||
|
targets=[
|
||||||
|
Name(id='__midas_alias_1__')]),
|
||||||
|
Assign(
|
||||||
|
targets=[
|
||||||
|
Name(id='speed')],
|
||||||
|
value=BinOp(
|
||||||
|
left=Name(id='distance'),
|
||||||
|
op=Div(),
|
||||||
|
right=Name(id='time')))],
|
||||||
|
type_ignores=[])
|
||||||
Reference in New Issue
Block a user