1+ import tests
2+ import resource_borrow_export
3+ import resource_aggregates
4+ import resource_alias1
5+ import resource_borrow_in_record
6+ from tests import exports , imports
7+ from tests .imports import resource_borrow_import
8+ from tests .imports import simple_import_and_export
9+ from tests .exports import resource_alias2
10+ from tests .types import Result , Ok
11+ from typing import Tuple , List , Optional
12+
13+ class SimpleExport (exports .SimpleExport ):
14+ def foo (self , v : int ) -> int :
15+ return v + 3
16+
17+ class SimpleImportAndExport (exports .SimpleImportAndExport ):
18+ def foo (self , v : int ) -> int :
19+ return simple_import_and_export .foo (v ) + 3
20+
21+ class ResourceImportAndExport (exports .ResourceImportAndExport ):
22+ pass
23+
24+ class ResourceBorrowExport (exports .ResourceBorrowExport ):
25+ def foo (self , v : resource_borrow_export .Thing ) -> int :
26+ return v .value + 2
27+
28+ class ResourceWithLists (exports .ResourceWithLists ):
29+ pass
30+
31+ class ResourceAggregates (exports .ResourceAggregates ):
32+ def foo (
33+ self ,
34+ r1 : exports .resource_aggregates .R1 ,
35+ r2 : exports .resource_aggregates .R2 ,
36+ r3 : exports .resource_aggregates .R3 ,
37+ t1 : Tuple [resource_aggregates .Thing , exports .resource_aggregates .R1 ],
38+ t2 : Tuple [resource_aggregates .Thing ],
39+ v1 : exports .resource_aggregates .V1 ,
40+ v2 : exports .resource_aggregates .V2 ,
41+ l1 : List [resource_aggregates .Thing ],
42+ l2 : List [resource_aggregates .Thing ],
43+ o1 : Optional [resource_aggregates .Thing ],
44+ o2 : Optional [resource_aggregates .Thing ],
45+ result1 : Result [resource_aggregates .Thing , None ],
46+ result2 : Result [resource_aggregates .Thing , None ]
47+ ) -> int :
48+ if o1 is None :
49+ host_o1 = None
50+ else :
51+ host_o1 = o1 .value
52+
53+ if o2 is None :
54+ host_o2 = None
55+ else :
56+ host_o2 = o2 .value
57+
58+ if isinstance (result1 , Ok ):
59+ host_result1 = Ok (result1 .value .value )
60+ else :
61+ host_result1 = result1
62+
63+ if isinstance (result2 , Ok ):
64+ host_result2 = Ok (result2 .value .value )
65+ else :
66+ host_result2 = result2
67+
68+ return imports .resource_aggregates .foo (
69+ imports .resource_aggregates .R1 (r1 .thing .value ),
70+ imports .resource_aggregates .R2 (r2 .thing .value ),
71+ imports .resource_aggregates .R3 (r3 .thing1 .value , r3 .thing2 .value ),
72+ (t1 [0 ].value , imports .resource_aggregates .R1 (t1 [1 ].thing .value )),
73+ (t2 [0 ].value ,),
74+ imports .resource_aggregates .V1Thing (v1 .value .value ),
75+ imports .resource_aggregates .V2Thing (v2 .value .value ),
76+ list (map (lambda x : x .value , l1 )),
77+ list (map (lambda x : x .value , l2 )),
78+ host_o1 ,
79+ host_o2 ,
80+ host_result1 ,
81+ host_result2
82+ ) + 4
83+
84+ class ResourceAlias1 (exports .ResourceAlias1 ):
85+ def a (self , f : exports .resource_alias1 .Foo ) -> List [resource_alias1 .Thing ]:
86+ return list (
87+ map (
88+ resource_alias1 .wrap_thing ,
89+ imports .resource_alias1 .a (imports .resource_alias1 .Foo (f .thing .value ))
90+ )
91+ )
92+
93+ class ResourceAlias2 (exports .ResourceAlias2 ):
94+ def b (self , f : exports .resource_alias2 .Foo , g : exports .resource_alias1 .Foo ) -> List [resource_alias1 .Thing ]:
95+ return list (
96+ map (
97+ resource_alias1 .wrap_thing ,
98+ imports .resource_alias2 .b (
99+ imports .resource_alias2 .Foo (f .thing .value ),
100+ exports .resource_alias1 .Foo (g .thing .value )
101+ )
102+ )
103+ )
104+
105+ class ResourceBorrowInRecord (exports .ResourceBorrowInRecord ):
106+ def test (self , a : List [exports .resource_borrow_in_record .Foo ]) -> List [resource_borrow_in_record .Thing ]:
107+ return list (
108+ map (
109+ resource_borrow_in_record .wrap_thing ,
110+ imports .resource_borrow_in_record .test (
111+ list (map (lambda x : imports .resource_borrow_in_record .Foo (x .thing .value ), a ))
112+ )
113+ )
114+ )
115+
116+ class Tests (tests .Tests ):
117+ def test_resource_borrow_import (self , v : int ) -> int :
118+ return resource_borrow_import .foo (resource_borrow_import .Thing (v + 1 )) + 4
119+
120+ def test_resource_alias (self , things : List [imports .resource_alias1 .Thing ]) -> List [imports .resource_alias1 .Thing ]:
121+ return things
122+
123+ def add (self , a : imports .resource_floats .Float , b : imports .resource_floats .Float ) -> imports .resource_floats .Float :
124+ return imports .resource_floats .Float (a .get () + b .get () + 5 )
0 commit comments