@alloy-js/python 0.4.0-dev.2 → 0.4.0-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/dist/dev/src/builtins/python.js +30 -0
  2. package/dist/dev/src/builtins/python.js.map +1 -0
  3. package/dist/dev/src/components/Atom.js +122 -0
  4. package/dist/dev/src/components/Atom.js.map +1 -0
  5. package/dist/dev/src/components/CallSignature.js +195 -0
  6. package/dist/dev/src/components/CallSignature.js.map +1 -0
  7. package/dist/dev/src/components/ClassDeclaration.js +112 -0
  8. package/dist/dev/src/components/ClassDeclaration.js.map +1 -0
  9. package/dist/dev/src/components/ClassInstantiation.js +40 -0
  10. package/dist/dev/src/components/ClassInstantiation.js.map +1 -0
  11. package/dist/dev/src/components/ClassMethodDeclaration.js +40 -0
  12. package/dist/dev/src/components/ClassMethodDeclaration.js.map +1 -0
  13. package/dist/dev/src/components/ConstructorDeclaration.js +39 -0
  14. package/dist/dev/src/components/ConstructorDeclaration.js.map +1 -0
  15. package/dist/dev/src/components/DataclassDeclaration.js +177 -0
  16. package/dist/dev/src/components/DataclassDeclaration.js.map +1 -0
  17. package/dist/dev/src/components/Declaration.js +31 -0
  18. package/dist/dev/src/components/Declaration.js.map +1 -0
  19. package/dist/dev/src/components/DunderMethodDeclaration.js +33 -0
  20. package/dist/dev/src/components/DunderMethodDeclaration.js.map +1 -0
  21. package/dist/dev/src/components/EnumDeclaration.js +259 -0
  22. package/dist/dev/src/components/EnumDeclaration.js.map +1 -0
  23. package/dist/dev/src/components/EnumMember.js +95 -0
  24. package/dist/dev/src/components/EnumMember.js.map +1 -0
  25. package/dist/dev/src/components/FunctionBase.js +130 -0
  26. package/dist/dev/src/components/FunctionBase.js.map +1 -0
  27. package/dist/dev/src/components/FunctionCallExpression.js +53 -0
  28. package/dist/dev/src/components/FunctionCallExpression.js.map +1 -0
  29. package/dist/dev/src/components/FunctionDeclaration.js +45 -0
  30. package/dist/dev/src/components/FunctionDeclaration.js.map +1 -0
  31. package/dist/dev/src/components/FutureStatement.js +31 -0
  32. package/dist/dev/src/components/FutureStatement.js.map +1 -0
  33. package/dist/dev/src/components/ImportStatement.js +167 -0
  34. package/dist/dev/src/components/ImportStatement.js.map +1 -0
  35. package/dist/dev/src/components/LexicalScope.js +26 -0
  36. package/dist/dev/src/components/LexicalScope.js.map +1 -0
  37. package/dist/dev/src/components/MemberExpression.js +290 -0
  38. package/dist/dev/src/components/MemberExpression.js.map +1 -0
  39. package/dist/dev/src/components/MemberScope.js +23 -0
  40. package/dist/dev/src/components/MemberScope.js.map +1 -0
  41. package/dist/dev/src/components/MethodBase.js +40 -0
  42. package/dist/dev/src/components/MethodBase.js.map +1 -0
  43. package/dist/dev/src/components/MethodDeclaration.js +38 -0
  44. package/dist/dev/src/components/MethodDeclaration.js.map +1 -0
  45. package/dist/dev/src/components/PropertyDeclaration.js +287 -0
  46. package/dist/dev/src/components/PropertyDeclaration.js.map +1 -0
  47. package/dist/dev/src/components/PyDoc.js +1478 -0
  48. package/dist/dev/src/components/PyDoc.js.map +1 -0
  49. package/dist/dev/src/components/PythonBlock.js +35 -0
  50. package/dist/dev/src/components/PythonBlock.js.map +1 -0
  51. package/dist/dev/src/components/Reference.js +23 -0
  52. package/dist/dev/src/components/Reference.js.map +1 -0
  53. package/dist/dev/src/components/SourceFile.js +385 -0
  54. package/dist/dev/src/components/SourceFile.js.map +1 -0
  55. package/dist/dev/src/components/StatementList.js +34 -0
  56. package/dist/dev/src/components/StatementList.js.map +1 -0
  57. package/dist/dev/src/components/StaticMethodDeclaration.js +40 -0
  58. package/dist/dev/src/components/StaticMethodDeclaration.js.map +1 -0
  59. package/dist/dev/src/components/TypeArguments.js +22 -0
  60. package/dist/dev/src/components/TypeArguments.js.map +1 -0
  61. package/dist/dev/src/components/TypeRefContext.js +33 -0
  62. package/dist/dev/src/components/TypeRefContext.js.map +1 -0
  63. package/dist/dev/src/components/TypeReference.js +67 -0
  64. package/dist/dev/src/components/TypeReference.js.map +1 -0
  65. package/dist/dev/src/components/UnionTypeExpression.js +57 -0
  66. package/dist/dev/src/components/UnionTypeExpression.js.map +1 -0
  67. package/dist/dev/src/components/VariableDeclaration.js +150 -0
  68. package/dist/dev/src/components/VariableDeclaration.js.map +1 -0
  69. package/dist/dev/src/components/index.js +32 -0
  70. package/dist/dev/src/components/index.js.map +1 -0
  71. package/dist/dev/src/context/index.js +2 -0
  72. package/dist/dev/src/context/index.js.map +1 -0
  73. package/dist/dev/src/context/type-ref-context.js +17 -0
  74. package/dist/dev/src/context/type-ref-context.js.map +1 -0
  75. package/dist/dev/src/create-module.js +64 -0
  76. package/dist/dev/src/create-module.js.map +1 -0
  77. package/dist/dev/src/index.js +8 -0
  78. package/dist/dev/src/index.js.map +1 -0
  79. package/dist/dev/src/name-conflict-resolver.js +8 -0
  80. package/dist/dev/src/name-conflict-resolver.js.map +1 -0
  81. package/dist/dev/src/name-policy.js +48 -0
  82. package/dist/dev/src/name-policy.js.map +1 -0
  83. package/dist/dev/src/parameter-descriptor.js +8 -0
  84. package/dist/dev/src/parameter-descriptor.js.map +1 -0
  85. package/dist/dev/src/symbol-creation.js +58 -0
  86. package/dist/dev/src/symbol-creation.js.map +1 -0
  87. package/dist/dev/src/symbols/factories.js +28 -0
  88. package/dist/dev/src/symbols/factories.js.map +1 -0
  89. package/dist/dev/src/symbols/index.js +8 -0
  90. package/dist/dev/src/symbols/index.js.map +1 -0
  91. package/dist/dev/src/symbols/python-lexical-scope.js +15 -0
  92. package/dist/dev/src/symbols/python-lexical-scope.js.map +1 -0
  93. package/dist/dev/src/symbols/python-member-scope.js +7 -0
  94. package/dist/dev/src/symbols/python-member-scope.js.map +1 -0
  95. package/dist/dev/src/symbols/python-module-scope.js +86 -0
  96. package/dist/dev/src/symbols/python-module-scope.js.map +1 -0
  97. package/dist/dev/src/symbols/python-output-symbol.js +73 -0
  98. package/dist/dev/src/symbols/python-output-symbol.js.map +1 -0
  99. package/dist/dev/src/symbols/reference.js +87 -0
  100. package/dist/dev/src/symbols/reference.js.map +1 -0
  101. package/dist/dev/src/symbols/scopes.js +13 -0
  102. package/dist/dev/src/symbols/scopes.js.map +1 -0
  103. package/dist/dev/src/utils.js +13 -0
  104. package/dist/dev/src/utils.js.map +1 -0
  105. package/dist/dev/test/callsignatures.test.js +482 -0
  106. package/dist/dev/test/callsignatures.test.js.map +1 -0
  107. package/dist/dev/test/class-method-declaration.test.js +85 -0
  108. package/dist/dev/test/class-method-declaration.test.js.map +1 -0
  109. package/dist/dev/test/classdeclarations.test.js +654 -0
  110. package/dist/dev/test/classdeclarations.test.js.map +1 -0
  111. package/dist/dev/test/classinstantiations.test.js +281 -0
  112. package/dist/dev/test/classinstantiations.test.js.map +1 -0
  113. package/dist/dev/test/constructordeclaration.test.js +86 -0
  114. package/dist/dev/test/constructordeclaration.test.js.map +1 -0
  115. package/dist/dev/test/dataclassdeclarations.test.js +1068 -0
  116. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -0
  117. package/dist/dev/test/dundermethoddeclaration.test.js +93 -0
  118. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -0
  119. package/dist/dev/test/enums.test.js +263 -0
  120. package/dist/dev/test/enums.test.js.map +1 -0
  121. package/dist/dev/test/externals.test.js +307 -0
  122. package/dist/dev/test/externals.test.js.map +1 -0
  123. package/dist/dev/test/factories.test.js +122 -0
  124. package/dist/dev/test/factories.test.js.map +1 -0
  125. package/dist/dev/test/functioncallexpressions.test.js +257 -0
  126. package/dist/dev/test/functioncallexpressions.test.js.map +1 -0
  127. package/dist/dev/test/functiondeclaration.test.js +817 -0
  128. package/dist/dev/test/functiondeclaration.test.js.map +1 -0
  129. package/dist/dev/test/imports.test.js +372 -0
  130. package/dist/dev/test/imports.test.js.map +1 -0
  131. package/dist/dev/test/memberexpressions.test.js +1668 -0
  132. package/dist/dev/test/memberexpressions.test.js.map +1 -0
  133. package/dist/dev/test/methoddeclaration.test.js +344 -0
  134. package/dist/dev/test/methoddeclaration.test.js.map +1 -0
  135. package/dist/dev/test/namepolicies.test.js +154 -0
  136. package/dist/dev/test/namepolicies.test.js.map +1 -0
  137. package/dist/dev/test/propertydeclaration.test.js +354 -0
  138. package/dist/dev/test/propertydeclaration.test.js.map +1 -0
  139. package/dist/dev/test/pydocs.test.js +1675 -0
  140. package/dist/dev/test/pydocs.test.js.map +1 -0
  141. package/dist/dev/test/references.test.js +66 -0
  142. package/dist/dev/test/references.test.js.map +1 -0
  143. package/dist/dev/test/sourcefiles.test.js +1802 -0
  144. package/dist/dev/test/sourcefiles.test.js.map +1 -0
  145. package/dist/dev/test/staticmethoddeclaration.test.js +85 -0
  146. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -0
  147. package/dist/dev/test/type-checking-imports.test.js +617 -0
  148. package/dist/dev/test/type-checking-imports.test.js.map +1 -0
  149. package/dist/dev/test/typereference.test.js +79 -0
  150. package/dist/dev/test/typereference.test.js.map +1 -0
  151. package/dist/dev/test/uniontypeexpression.test.js +307 -0
  152. package/dist/dev/test/uniontypeexpression.test.js.map +1 -0
  153. package/dist/dev/test/utils.js +100 -0
  154. package/dist/dev/test/utils.js.map +1 -0
  155. package/dist/dev/test/values.test.js +182 -0
  156. package/dist/dev/test/values.test.js.map +1 -0
  157. package/dist/dev/test/variables.test.js +363 -0
  158. package/dist/dev/test/variables.test.js.map +1 -0
  159. package/dist/src/components/CallSignature.d.ts.map +1 -1
  160. package/dist/src/components/CallSignature.js +12 -3
  161. package/dist/src/components/CallSignature.js.map +1 -1
  162. package/dist/src/components/ImportStatement.d.ts +12 -0
  163. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  164. package/dist/src/components/ImportStatement.js +47 -5
  165. package/dist/src/components/ImportStatement.js.map +1 -1
  166. package/dist/src/components/MemberExpression.d.ts +1 -1
  167. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  168. package/dist/src/components/MemberExpression.js +98 -180
  169. package/dist/src/components/MemberExpression.js.map +1 -1
  170. package/dist/src/components/Reference.d.ts.map +1 -1
  171. package/dist/src/components/Reference.js +5 -1
  172. package/dist/src/components/Reference.js.map +1 -1
  173. package/dist/src/components/SourceFile.d.ts +1 -1
  174. package/dist/src/components/SourceFile.d.ts.map +1 -1
  175. package/dist/src/components/SourceFile.js +46 -7
  176. package/dist/src/components/SourceFile.js.map +1 -1
  177. package/dist/src/components/TypeRefContext.d.ts +26 -0
  178. package/dist/src/components/TypeRefContext.d.ts.map +1 -0
  179. package/dist/src/components/TypeRefContext.js +29 -0
  180. package/dist/src/components/TypeRefContext.js.map +1 -0
  181. package/dist/src/components/TypeReference.d.ts +5 -0
  182. package/dist/src/components/TypeReference.d.ts.map +1 -1
  183. package/dist/src/components/TypeReference.js +19 -9
  184. package/dist/src/components/TypeReference.js.map +1 -1
  185. package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
  186. package/dist/src/components/VariableDeclaration.js +7 -2
  187. package/dist/src/components/VariableDeclaration.js.map +1 -1
  188. package/dist/src/components/index.d.ts +1 -1
  189. package/dist/src/components/index.d.ts.map +1 -1
  190. package/dist/src/components/index.js +1 -1
  191. package/dist/src/components/index.js.map +1 -1
  192. package/dist/src/context/index.d.ts +2 -0
  193. package/dist/src/context/index.d.ts.map +1 -0
  194. package/dist/src/context/index.js +2 -0
  195. package/dist/src/context/index.js.map +1 -0
  196. package/dist/src/context/type-ref-context.d.ts +13 -0
  197. package/dist/src/context/type-ref-context.d.ts.map +1 -0
  198. package/dist/src/context/type-ref-context.js +17 -0
  199. package/dist/src/context/type-ref-context.js.map +1 -0
  200. package/dist/src/symbols/python-module-scope.d.ts +13 -1
  201. package/dist/src/symbols/python-module-scope.d.ts.map +1 -1
  202. package/dist/src/symbols/python-module-scope.js +36 -2
  203. package/dist/src/symbols/python-module-scope.js.map +1 -1
  204. package/dist/src/symbols/python-output-symbol.d.ts +11 -0
  205. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
  206. package/dist/src/symbols/python-output-symbol.js +26 -2
  207. package/dist/src/symbols/python-output-symbol.js.map +1 -1
  208. package/dist/src/symbols/reference.d.ts +8 -1
  209. package/dist/src/symbols/reference.d.ts.map +1 -1
  210. package/dist/src/symbols/reference.js +4 -2
  211. package/dist/src/symbols/reference.js.map +1 -1
  212. package/dist/test/dataclassdeclarations.test.js +5 -2
  213. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  214. package/dist/test/externals.test.js +8 -2
  215. package/dist/test/externals.test.js.map +1 -1
  216. package/dist/test/functiondeclaration.test.js +6 -3
  217. package/dist/test/functiondeclaration.test.js.map +1 -1
  218. package/dist/test/imports.test.js +3 -3
  219. package/dist/test/imports.test.js.map +1 -1
  220. package/dist/test/references.test.js +1 -1
  221. package/dist/test/references.test.js.map +1 -1
  222. package/dist/test/sourcefiles.test.js +26 -26
  223. package/dist/test/sourcefiles.test.js.map +1 -1
  224. package/dist/test/type-checking-imports.test.d.ts +2 -0
  225. package/dist/test/type-checking-imports.test.d.ts.map +1 -0
  226. package/dist/test/type-checking-imports.test.js +437 -0
  227. package/dist/test/type-checking-imports.test.js.map +1 -0
  228. package/dist/test/uniontypeexpression.test.js +4 -1
  229. package/dist/test/uniontypeexpression.test.js.map +1 -1
  230. package/dist/test/variables.test.js +4 -1
  231. package/dist/test/variables.test.js.map +1 -1
  232. package/dist/tsconfig.tsbuildinfo +1 -1
  233. package/package.json +6 -4
  234. package/src/components/CallSignature.tsx +6 -2
  235. package/src/components/ImportStatement.tsx +52 -5
  236. package/src/components/MemberExpression.tsx +174 -298
  237. package/src/components/Reference.tsx +3 -1
  238. package/src/components/SourceFile.tsx +44 -8
  239. package/src/components/TypeRefContext.tsx +36 -0
  240. package/src/components/TypeReference.tsx +15 -7
  241. package/src/components/VariableDeclaration.tsx +5 -1
  242. package/src/components/index.ts +1 -1
  243. package/src/context/index.ts +1 -0
  244. package/src/context/type-ref-context.tsx +16 -0
  245. package/src/symbols/python-module-scope.ts +55 -2
  246. package/src/symbols/python-output-symbol.ts +32 -1
  247. package/src/symbols/reference.tsx +10 -0
  248. package/temp/api.json +443 -338
  249. package/test/dataclassdeclarations.test.tsx +8 -2
  250. package/test/externals.test.tsx +8 -2
  251. package/test/functiondeclaration.test.tsx +6 -3
  252. package/test/imports.test.tsx +6 -6
  253. package/test/references.test.tsx +1 -1
  254. package/test/sourcefiles.test.tsx +13 -13
  255. package/test/type-checking-imports.test.tsx +363 -0
  256. package/test/uniontypeexpression.test.tsx +4 -1
  257. package/test/variables.test.tsx +4 -1
  258. package/vitest.config.ts +8 -0
@@ -0,0 +1,79 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { code, refkey } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { describe, expect, it } from "vitest";
5
+ import * as py from "../src/index.js";
6
+ import { toSourceText } from "./utils.js";
7
+ describe("TypeReference", () => {
8
+ it("renders a Python TypeReference with a refkey and type arguments", () => {
9
+ const classRefkey = refkey();
10
+ expect(toSourceText([_$createComponent(py.StatementList, {
11
+ get children() {
12
+ return [_$createComponent(py.ClassDeclaration, {
13
+ name: "Bar",
14
+ refkey: classRefkey
15
+ }, {
16
+ fileName: import.meta.url,
17
+ lineNumber: 14,
18
+ columnNumber: 11
19
+ }), _$createComponent(py.TypeReference, {
20
+ refkey: classRefkey,
21
+ typeArgs: ["T", "P"]
22
+ }, {
23
+ fileName: import.meta.url,
24
+ lineNumber: 18,
25
+ columnNumber: 11
26
+ }), _$createComponent(py.TypeReference, {
27
+ name: "dict",
28
+ typeArgs: ["str", "int"]
29
+ }, {
30
+ fileName: import.meta.url,
31
+ lineNumber: 19,
32
+ columnNumber: 11
33
+ })];
34
+ }
35
+ }, {
36
+ fileName: import.meta.url,
37
+ lineNumber: 13,
38
+ columnNumber: 9
39
+ })])).toRenderTo(d`
40
+ class Bar:
41
+ pass
42
+
43
+ Bar[T, P]
44
+ dict[str, int]
45
+ `);
46
+ });
47
+ it("renders a Python list expression with a reference", () => {
48
+ const classRefkey = refkey();
49
+ const type = code`list[${classRefkey}]`;
50
+ expect(toSourceText([_$createComponent(py.StatementList, {
51
+ get children() {
52
+ return [_$createComponent(py.ClassDeclaration, {
53
+ name: "Foo",
54
+ refkey: classRefkey
55
+ }, {
56
+ fileName: import.meta.url,
57
+ lineNumber: 38,
58
+ columnNumber: 11
59
+ }), _$createComponent(py.TypeReference, {
60
+ name: type
61
+ }, {
62
+ fileName: import.meta.url,
63
+ lineNumber: 42,
64
+ columnNumber: 11
65
+ })];
66
+ }
67
+ }, {
68
+ fileName: import.meta.url,
69
+ lineNumber: 37,
70
+ columnNumber: 9
71
+ })])).toRenderTo(d`
72
+ class Foo:
73
+ pass
74
+
75
+ list[Foo]
76
+ `);
77
+ });
78
+ });
79
+ //# sourceMappingURL=typereference.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["code","refkey","d","describe","expect","it","py","toSourceText","classRefkey","_$createComponent","StatementList","children","ClassDeclaration","name","fileName","import","meta","url","lineNumber","columnNumber","TypeReference","typeArgs","toRenderTo","type"],"sources":["../../../test/typereference.test.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,IAAI,EAAEC,MAAM,QAAQ,gBAAgB;AAC7C,SAASC,CAAC,QAAQ,wBAAwB;AAC1C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,OAAO,KAAKC,EAAE,MAAM,iBAAiB;AACrC,SAASC,YAAY;AAErBJ,QAAQ,CAAC,eAAe,EAAE,MAAM;EAC9BE,EAAE,CAAC,iEAAiE,EAAE,MAAM;IAC1E,MAAMG,WAAW,GAAGP,MAAM,CAAC,CAAC;IAE5BG,MAAM,CACJG,YAAY,CAAC,CAAAE,iBAAA,CACVH,EAAE,CAACI,aAAa;MAAA,IAAAC,SAAA;QAAA,QAAAF,iBAAA,CACdH,EAAE,CAACM,gBAAgB;UAClBC,IAAI;UACJZ,MAAM,EAAEO;QAAW;UAAAM,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,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AC,IAAA,CAAAC,GAAA;MAAAC,UAAA;MAAAC,YAAA;IAAA,GAE/B,CACH,CAAC,CAACG,UAAU,CAACpB,CAAC;AAClB;AACA;AACA;AACA;AACA,KAAK,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,307 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { refkey } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { describe, expect, it } from "vitest";
5
+ import * as py from "../src/index.js";
6
+ import { assertFileContents, toSourceText, toSourceTextMultiple } from "./utils.js";
7
+ describe("UnionTypeExpression", () => {
8
+ it("renders a Python union expression - 1 item", () => {
9
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
10
+ children: ["int"]
11
+ }, {
12
+ fileName: import.meta.url,
13
+ lineNumber: 14,
14
+ columnNumber: 21
15
+ })])).toRenderTo("int");
16
+ });
17
+ it("renders a Python union expression - 2 items", () => {
18
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
19
+ children: ["int", "str"]
20
+ }, {
21
+ fileName: import.meta.url,
22
+ lineNumber: 19,
23
+ columnNumber: 21
24
+ })])).toRenderTo("int | str");
25
+ });
26
+ it("renders a Python union expression - N items", () => {
27
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
28
+ children: ["int", "str", "float", "bool", "list", "dict", "set", "tuple", "frozenset", "bytes", "bytearray", "memoryview", "complex"]
29
+ }, {
30
+ fileName: import.meta.url,
31
+ lineNumber: 25,
32
+ columnNumber: 9
33
+ })])).toRenderTo(d`
34
+ (
35
+ int
36
+ | str
37
+ | float
38
+ | bool
39
+ | list
40
+ | dict
41
+ | set
42
+ | tuple
43
+ | frozenset
44
+ | bytes
45
+ | bytearray
46
+ | memoryview
47
+ | complex
48
+ )`);
49
+ });
50
+ it("renders a Python union expression - 2 items again", () => {
51
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
52
+ children: ["int", "str"]
53
+ }, {
54
+ fileName: import.meta.url,
55
+ lineNumber: 62,
56
+ columnNumber: 21
57
+ })])).toRenderTo("int | str");
58
+ });
59
+ it("renders a Python union expression - 2 items with None", () => {
60
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
61
+ children: ["int", "str", "None"]
62
+ }, {
63
+ fileName: import.meta.url,
64
+ lineNumber: 68,
65
+ columnNumber: 9
66
+ })])).toRenderTo("int | str | None");
67
+ });
68
+ it("renders a Python union with generic types", () => {
69
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
70
+ get children() {
71
+ return [_$createComponent(py.TypeReference, {
72
+ name: "list",
73
+ typeArgs: ["int"]
74
+ }, {
75
+ fileName: import.meta.url,
76
+ lineNumber: 78,
77
+ columnNumber: 13
78
+ }), _$createComponent(py.TypeReference, {
79
+ name: "dict",
80
+ typeArgs: ["str", "int"]
81
+ }, {
82
+ fileName: import.meta.url,
83
+ lineNumber: 79,
84
+ columnNumber: 13
85
+ })];
86
+ }
87
+ }, {
88
+ fileName: import.meta.url,
89
+ lineNumber: 76,
90
+ columnNumber: 9
91
+ })])).toRenderTo("list[int] | dict[str, int]");
92
+ });
93
+ it("renders a Python type expression with references", () => {
94
+ const classRefkey = refkey();
95
+ const otherClassRefkey = refkey();
96
+ expect(toSourceText([_$createComponent(py.StatementList, {
97
+ get children() {
98
+ return [_$createComponent(py.ClassDeclaration, {
99
+ name: "Bar",
100
+ refkey: classRefkey
101
+ }, {
102
+ fileName: import.meta.url,
103
+ lineNumber: 93,
104
+ columnNumber: 11
105
+ }), _$createComponent(py.ClassDeclaration, {
106
+ name: "Foo",
107
+ refkey: otherClassRefkey
108
+ }, {
109
+ fileName: import.meta.url,
110
+ lineNumber: 97,
111
+ columnNumber: 11
112
+ }), _$createComponent(py.UnionTypeExpression, {
113
+ get children() {
114
+ return [_$createComponent(py.Reference, {
115
+ refkey: classRefkey
116
+ }, {
117
+ fileName: import.meta.url,
118
+ lineNumber: 103,
119
+ columnNumber: 15
120
+ }), _$createComponent(py.Reference, {
121
+ refkey: otherClassRefkey
122
+ }, {
123
+ fileName: import.meta.url,
124
+ lineNumber: 104,
125
+ columnNumber: 15
126
+ })];
127
+ }
128
+ }, {
129
+ fileName: import.meta.url,
130
+ lineNumber: 101,
131
+ columnNumber: 11
132
+ })];
133
+ }
134
+ }, {
135
+ fileName: import.meta.url,
136
+ lineNumber: 92,
137
+ columnNumber: 9
138
+ })])).toRenderTo(d`
139
+ class Bar:
140
+ pass
141
+
142
+ class Foo:
143
+ pass
144
+
145
+ Bar | Foo
146
+ `);
147
+ });
148
+ it("emits import for TypeReference with refkey and typeArgs across files", () => {
149
+ const classRefkey = refkey();
150
+ const res = toSourceTextMultiple([_$createComponent(py.SourceFile, {
151
+ path: "defs.py",
152
+ get children() {
153
+ return _$createComponent(py.ClassDeclaration, {
154
+ name: "Bar",
155
+ refkey: classRefkey
156
+ }, {
157
+ fileName: import.meta.url,
158
+ lineNumber: 124,
159
+ columnNumber: 9
160
+ });
161
+ }
162
+ }, {
163
+ fileName: import.meta.url,
164
+ lineNumber: 123,
165
+ columnNumber: 7
166
+ }), _$createComponent(py.SourceFile, {
167
+ path: "use.py",
168
+ get children() {
169
+ return _$createComponent(py.StatementList, {
170
+ get children() {
171
+ return _$createComponent(py.VariableDeclaration, {
172
+ name: "v",
173
+ get type() {
174
+ return _$createComponent(py.TypeReference, {
175
+ refkey: classRefkey,
176
+ typeArgs: ["T"]
177
+ }, {
178
+ fileName: import.meta.url,
179
+ lineNumber: 130,
180
+ columnNumber: 19
181
+ });
182
+ }
183
+ }, {
184
+ fileName: import.meta.url,
185
+ lineNumber: 128,
186
+ columnNumber: 11
187
+ });
188
+ }
189
+ }, {
190
+ fileName: import.meta.url,
191
+ lineNumber: 127,
192
+ columnNumber: 9
193
+ });
194
+ }
195
+ }, {
196
+ fileName: import.meta.url,
197
+ lineNumber: 126,
198
+ columnNumber: 7
199
+ })]);
200
+ assertFileContents(res, {
201
+ "defs.py": `
202
+ class Bar:
203
+ pass
204
+
205
+ `,
206
+ "use.py": `
207
+ from typing import TYPE_CHECKING
208
+
209
+ if TYPE_CHECKING:
210
+ from defs import Bar
211
+
212
+ v: Bar[T] = None
213
+ `
214
+ });
215
+ });
216
+ });
217
+ describe("TypeExpression in different scenarios", () => {
218
+ it("renders an UnionTypeExpression as a function type parameter and return type", () => {
219
+ const classRefkey = refkey();
220
+ const type = _$createComponent(py.UnionTypeExpression, {
221
+ get children() {
222
+ return ["int", "str", _$createComponent(py.Reference, {
223
+ refkey: classRefkey
224
+ }, {
225
+ fileName: import.meta.url,
226
+ lineNumber: 158,
227
+ columnNumber: 34
228
+ })];
229
+ }
230
+ }, {
231
+ fileName: import.meta.url,
232
+ lineNumber: 157,
233
+ columnNumber: 7
234
+ });
235
+ expect(toSourceText([_$createComponent(py.ClassDeclaration, {
236
+ name: "Foo",
237
+ refkey: classRefkey
238
+ }, {
239
+ fileName: import.meta.url,
240
+ lineNumber: 163,
241
+ columnNumber: 9
242
+ }), _$createComponent(py.FunctionDeclaration, {
243
+ name: "fooFunction",
244
+ parameters: [{
245
+ name: "x",
246
+ type: type
247
+ }],
248
+ args: true,
249
+ kwargs: true,
250
+ returnType: type
251
+ }, {
252
+ fileName: import.meta.url,
253
+ lineNumber: 167,
254
+ columnNumber: 9
255
+ })])).toRenderTo(d`
256
+ class Foo:
257
+ pass
258
+
259
+
260
+ def foo_function(x: int | str | Foo, *args, **kwargs) -> int | str | Foo:
261
+ pass
262
+
263
+
264
+ `);
265
+ });
266
+ it("renders an UnionTypeExpression as a variable type", () => {
267
+ const classRefkey = refkey();
268
+ const type = _$createComponent(py.UnionTypeExpression, {
269
+ get children() {
270
+ return ["int", "str", _$createComponent(py.Reference, {
271
+ refkey: classRefkey
272
+ }, {
273
+ fileName: import.meta.url,
274
+ lineNumber: 195,
275
+ columnNumber: 34
276
+ })];
277
+ }
278
+ }, {
279
+ fileName: import.meta.url,
280
+ lineNumber: 194,
281
+ columnNumber: 7
282
+ });
283
+ expect(toSourceText([_$createComponent(py.ClassDeclaration, {
284
+ name: "Foo",
285
+ refkey: classRefkey
286
+ }, {
287
+ fileName: import.meta.url,
288
+ lineNumber: 200,
289
+ columnNumber: 9
290
+ }), _$createComponent(py.VariableDeclaration, {
291
+ name: "fooVariable",
292
+ type: type
293
+ }, {
294
+ fileName: import.meta.url,
295
+ lineNumber: 204,
296
+ columnNumber: 9
297
+ })])).toRenderTo(d`
298
+ class Foo:
299
+ pass
300
+
301
+
302
+ foo_variable: int | str | Foo = None
303
+
304
+ `);
305
+ });
306
+ });
307
+ //# sourceMappingURL=uniontypeexpression.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["refkey","d","describe","expect","it","py","assertFileContents","toSourceText","toSourceTextMultiple","_$createComponent","UnionTypeExpression","children","fileName","import","meta","url","lineNumber","columnNumber","toRenderTo","TypeReference","name","typeArgs","classRefkey","otherClassRefkey","StatementList","ClassDeclaration","Reference","res","SourceFile","path","VariableDeclaration","type","FunctionDeclaration","parameters","args","kwargs","returnType"],"sources":["../../../test/uniontypeexpression.test.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAQ,gBAAgB;AACvC,SAASC,CAAC,QAAQ,wBAAwB;AAC1C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,OAAO,KAAKC,EAAE,MAAM,iBAAiB;AACrC,SACEC,kBAAkB,EAClBC,YAAY,EACZC,oBAAoB;AAGtBN,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpCE,EAAE,CAAC,4CAA4C,EAAE,MAAM;IACrDD,MAAM,CACJI,YAAY,CAAC,CAAAE,iBAAA,CAAEJ,EAAE,CAACK,mBAAmB;MAACC,QAAQ,EAAE,CAAC,KAAK;IAAC;MAAAC,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,GAAA;MAAAC,UAAA;MAAAC,YAAA;IAAA,GAAK,CAC9D,CAAC,CAACC,UAAU,CAA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,EAAE,CAACK,mBAAmB;MAAA,IACrBC,QAAQA,CAAA;QAAA,OAAE,CAAC,KAAK,EAAE,KAAK,EAAAF,iBAAA,CAAGJ,EAAE,CAACqB,SAAS;UAAC1B,MAAM,EAAEsB;QAAW;UAAAV,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,GAAA;UAAAC,UAAA;UAAAC,YAAA;QAAA,GAAK;MAAA;IAAA;MAAAL,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,GAAA;MAAAC,UAAA;MAAAC,YAAA;IAAA,EAElE;IACDd,MAAM,CACJI,YAAY,CAAC,CAAAE,iBAAA,CACVJ,EAAE,CAACoB,gBAAgB;MAClBL,IAAI;MACJpB,MAAM,EAAEsB;IAAW;MAAAV,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,GAAA;MAAAC,UAAA;MAAAC,YAAA;IAAA,IAAAR,iBAAA,CAEpBJ,EAAE,CAACyB,mBAAmB;MAACV,IAAI;MAAeW,IAAI,EAAEA;IAAI;MAAAnB,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,GAAA;MAAAC,UAAA;MAAAC,YAAA;IAAA,GACtD,CACH,CAAC,CAACC,UAAU,CAACjB,CAAC;AAClB;AACA;AACA;AACA;AACA;AACA;AACA,KAAK,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,100 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Output, render } from "@alloy-js/core";
3
+ import { dedent } from "@alloy-js/core/testing";
4
+ import { expect } from "vitest";
5
+ import * as py from "../src/components/index.js";
6
+ import { pythonNameConflictResolver } from "../src/name-conflict-resolver.js";
7
+ import { createPythonNamePolicy } from "../src/name-policy.js";
8
+ import { PythonModuleScope } from "../src/symbols/index.js";
9
+ export function findFile(res, path) {
10
+ const result = findFileWorker(res, path);
11
+ if (!result) {
12
+ throw new Error("Expected to find file " + path);
13
+ }
14
+ return result;
15
+ function findFileWorker(res, path) {
16
+ for (const item of res.contents) {
17
+ if (item.kind === "file") {
18
+ if (item.path === path) {
19
+ return item;
20
+ }
21
+ continue;
22
+ } else {
23
+ const found = findFileWorker(item, path);
24
+ if (found) {
25
+ return found;
26
+ }
27
+ }
28
+ }
29
+ return null;
30
+ }
31
+ }
32
+ export function assertFileContents(res, expectedFiles) {
33
+ for (const [path, contents] of Object.entries(expectedFiles)) {
34
+ const file = findFile(res, path);
35
+ expect(file.contents).toBe(dedent(contents));
36
+ }
37
+ }
38
+ export function toSourceTextMultiple(sourceFiles, {
39
+ policy,
40
+ externals,
41
+ options,
42
+ printOptions
43
+ } = {}) {
44
+ if (!policy) {
45
+ policy = createPythonNamePolicy();
46
+ }
47
+ const mergedExternals = options?.externals ?? externals;
48
+ if (printOptions === undefined) {
49
+ printOptions = {
50
+ printWidth: 80,
51
+ tabWidth: 4,
52
+ insertFinalNewLine: false
53
+ };
54
+ } else {
55
+ printOptions.insertFinalNewLine = false;
56
+ printOptions.tabWidth = 4;
57
+ }
58
+ const content = _$createComponent(Output, {
59
+ externals: mergedExternals,
60
+ namePolicy: policy,
61
+ nameConflictResolver: pythonNameConflictResolver,
62
+ children: sourceFiles
63
+ }, {
64
+ fileName: import.meta.url,
65
+ lineNumber: 92,
66
+ columnNumber: 5
67
+ });
68
+ return render(content, printOptions);
69
+ }
70
+ export function toSourceText(content, {
71
+ policy,
72
+ externals,
73
+ options,
74
+ printOptions
75
+ } = {}, path = "test.py") {
76
+ // If content is an array, wrap it in a default SourceFile
77
+ const sourceFile = Array.isArray(content) ? _$createComponent(py.SourceFile, {
78
+ path: path,
79
+ children: content
80
+ }, {
81
+ fileName: import.meta.url,
82
+ lineNumber: 121,
83
+ columnNumber: 7
84
+ }) : content;
85
+ const res = toSourceTextMultiple([sourceFile], {
86
+ policy,
87
+ externals,
88
+ options,
89
+ printOptions
90
+ });
91
+ return findFile(res, path).contents;
92
+ }
93
+
94
+ // Helper function to create a PythonModuleScope to be used in tests
95
+ export function createPythonModuleScope(name, parent, binder = undefined) {
96
+ return new PythonModuleScope(name, parent, {
97
+ binder: binder
98
+ });
99
+ }
100
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Output","render","dedent","expect","py","pythonNameConflictResolver","createPythonNamePolicy","PythonModuleScope","findFile","res","path","result","findFileWorker","Error","item","contents","kind","found","assertFileContents","expectedFiles","Object","entries","file","toBe","toSourceTextMultiple","sourceFiles","policy","externals","options","printOptions","mergedExternals","undefined","printWidth","tabWidth","insertFinalNewLine","content","_$createComponent","namePolicy","nameConflictResolver","children","fileName","import","meta","url","lineNumber","columnNumber","toSourceText","sourceFile","Array","isArray","SourceFile","createPythonModuleScope","name","parent","binder"],"sources":["../../../test/utils.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAKEA,MAAM,EAMNC,MAAM,QACD,gBAAgB;AACvB,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,MAAM,QAAQ,QAAQ;AAC/B,OAAO,KAAKC,EAAE,MAAM,4BAA4B;AAChD,SAASC,0BAA0B,QAAQ,kCAAkC;AAC7E,SAASC,sBAAsB,QAAQ,uBAAuB;AAC9D,SAASC,iBAAiB,QAAQ,yBAAyB;AAE3D,OAAO,SAASC,QAAQA,CACtBC,GAAoB,EACpBC,IAAY,EACO;EACnB,MAAMC,MAAM,GAAGC,cAAc,CAACH,GAAG,EAAEC,IAAI,CAAC;EAExC,IAAI,CAACC,MAAM,EAAE;IACX,MAAM,IAAIE,KAAK,CAAC,wBAAwB,GAAGH,IAAI,CAAC;EAClD;EACA,OAAOC,MAAM;EAEb,SAASC,cAAcA,CACrBH,GAAoB,EACpBC,IAAY,EACO;IACnB,KAAK,MAAMI,IAAI,IAAIL,GAAG,CAACM,QAAQ,EAAE;MAC/B,IAAID,IAAI,CAACE,IAAI,KAAK,MAAM,EAAE;QACxB,IAAIF,IAAI,CAACJ,IAAI,KAAKA,IAAI,EAAE;UACtB,OAAOI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A;IAAAC,UAAA;IAAAC,YAAA;EAAA,EAEf;EACD,OAAO5C,MAAM,CAACkC,OAAO,EAAEN,YAAY,CAAC;AACtC;AAEA,OAAO,SAASiB,YAAYA,CAC1BX,OAA8B,EAC9B;EACET,MAAM;EACNC,SAAS;EACTC,OAAO;EACPC;AAMF,CAAC,GAAG,CAAC,CAAC,EACNnB,IAAY,GAAG,SAAS,EAChB;EACR;EACA,MAAMqC,UAAU,GACdC,KAAK,CAACC,OAAO,CAACd,OAAO,CAAC,GAAAC,iBAAA,CACnBhC,EAAE,CAAC8C,UAAU;IAACxC,IAAI,EAAEA,IAAI;IAAA6B,QAAA,EAAGJ;EAAO;IAAAK,QAAA,EAAAC,MAAA,CAAAC,IAAA,CAAAC,GAAA;IAAAC,UAAA;IAAAC,YAAA;EAAA,KACnCV,OAAO;EAEX,MAAM1B,GAAG,GAAGe,oBAAoB,CAAC,CAACuB,UAAU,CAAC,EAAE;IAC7CrB,MAAM;IACNC,SAAS;IACTC,OAAO;IACPC;EACF,CAAC,CAAC;EACF,OAAOrB,QAAQ,CAACC,GAAG,EAAEC,IAAI,CAAC,CAACK,QAAQ;AACrC;;AAEA;AACA,OAAO,SAASoC,uBAAuBA,CACrCC,IAAY,EACZC,MAA+B,EAC/BC,MAA0B,GAAGvB,SAAS,EACnB;EACnB,OAAO,IAAIxB,iBAAiB,CAAC6C,IAAI,EAAEC,MAAM,EAAE;IACzCC,MAAM,EAAEA;EACV,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,182 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import * as py from "../src/index.js";
4
+ import { toSourceText } from "./utils.js";
5
+ describe("Atom", () => {
6
+ it("renders string value", () => {
7
+ expect(toSourceText([_$createComponent(py.Atom, {
8
+ jsValue: "Test"
9
+ }, {
10
+ fileName: import.meta.url,
11
+ lineNumber: 7,
12
+ columnNumber: 26
13
+ })])).toRenderTo('"Test"');
14
+ });
15
+ it("renders null/undefined object", () => {
16
+ expect(toSourceText([_$createComponent(py.Atom, {
17
+ jsValue: undefined
18
+ }, {
19
+ fileName: import.meta.url,
20
+ lineNumber: 11,
21
+ columnNumber: 26
22
+ })])).toRenderTo("None");
23
+ });
24
+ it("renders number", () => {
25
+ expect(toSourceText([_$createComponent(py.Atom, {
26
+ jsValue: 123
27
+ }, {
28
+ fileName: import.meta.url,
29
+ lineNumber: 15,
30
+ columnNumber: 26
31
+ })])).toRenderTo("123");
32
+ });
33
+ it("renders floating point number", () => {
34
+ expect(toSourceText([_$createComponent(py.Atom, {
35
+ jsValue: 123.456
36
+ }, {
37
+ fileName: import.meta.url,
38
+ lineNumber: 19,
39
+ columnNumber: 26
40
+ })])).toRenderTo("123.456");
41
+ });
42
+ it("renders floating point number when hinted", () => {
43
+ expect(toSourceText([_$createComponent(py.Atom, {
44
+ jsValue: 123.456,
45
+ asFloat: true
46
+ }, {
47
+ fileName: import.meta.url,
48
+ lineNumber: 23,
49
+ columnNumber: 26
50
+ })])).toRenderTo("123.456");
51
+ });
52
+ it("renders floating point number with decimal point zero when hinted", () => {
53
+ expect(toSourceText([_$createComponent(py.Atom, {
54
+ jsValue: 123.0,
55
+ asFloat: true
56
+ }, {
57
+ fileName: import.meta.url,
58
+ lineNumber: 29,
59
+ columnNumber: 26
60
+ })])).toRenderTo("123.0");
61
+ });
62
+ it("renders integer as float when hinted", () => {
63
+ expect(toSourceText([_$createComponent(py.Atom, {
64
+ jsValue: 123,
65
+ asFloat: true
66
+ }, {
67
+ fileName: import.meta.url,
68
+ lineNumber: 35,
69
+ columnNumber: 26
70
+ })])).toRenderTo("123.0");
71
+ });
72
+ it("renders small positive float when hinted", () => {
73
+ expect(toSourceText([_$createComponent(py.Atom, {
74
+ jsValue: 0.07,
75
+ asFloat: true
76
+ }, {
77
+ fileName: import.meta.url,
78
+ lineNumber: 41,
79
+ columnNumber: 26
80
+ })])).toRenderTo("0.07");
81
+ });
82
+ it("renders large positive numbers as float when hinted", () => {
83
+ expect(toSourceText([_$createComponent(py.Atom, {
84
+ jsValue: 2 ** 64,
85
+ asFloat: true
86
+ }, {
87
+ fileName: import.meta.url,
88
+ lineNumber: 47,
89
+ columnNumber: 26
90
+ })])).toRenderTo("18446744073709551616.0");
91
+ });
92
+ it("renders boolean - True", () => {
93
+ expect(toSourceText([_$createComponent(py.Atom, {
94
+ jsValue: true
95
+ }, {
96
+ fileName: import.meta.url,
97
+ lineNumber: 53,
98
+ columnNumber: 26
99
+ })])).toRenderTo("True");
100
+ });
101
+ it("renders boolean - False", () => {
102
+ expect(toSourceText([_$createComponent(py.Atom, {
103
+ jsValue: false
104
+ }, {
105
+ fileName: import.meta.url,
106
+ lineNumber: 57,
107
+ columnNumber: 26
108
+ })])).toRenderTo("False");
109
+ });
110
+ it("renders array", () => {
111
+ expect(toSourceText([_$createComponent(py.Atom, {
112
+ jsValue: [1, 2, 3]
113
+ }, {
114
+ fileName: import.meta.url,
115
+ lineNumber: 61,
116
+ columnNumber: 26
117
+ })])).toRenderTo("[1, 2, 3]");
118
+ });
119
+ it("renders object", () => {
120
+ expect(toSourceText([_$createComponent(py.Atom, {
121
+ jsValue: {
122
+ a: 1,
123
+ b: 2
124
+ }
125
+ }, {
126
+ fileName: import.meta.url,
127
+ lineNumber: 67,
128
+ columnNumber: 26
129
+ })])).toRenderTo('{"a": 1, "b": 2}');
130
+ });
131
+ it("renders more complex object", () => {
132
+ expect(toSourceText([_$createComponent(py.Atom, {
133
+ jsValue: {
134
+ a: "1",
135
+ b: 2,
136
+ c: true
137
+ }
138
+ }, {
139
+ fileName: import.meta.url,
140
+ lineNumber: 74,
141
+ columnNumber: 21
142
+ })])).toRenderTo('{"a": "1", "b": 2, "c": True}');
143
+ });
144
+ it("renders empty object", () => {
145
+ expect(toSourceText([_$createComponent(py.Atom, {
146
+ jsValue: {}
147
+ }, {
148
+ fileName: import.meta.url,
149
+ lineNumber: 79,
150
+ columnNumber: 26
151
+ })])).toRenderTo("{}");
152
+ });
153
+ it("renders function", () => {
154
+ function Test() {
155
+ return ["Test"];
156
+ }
157
+ expect(toSourceText([_$createComponent(py.Atom, {
158
+ jsValue: Test
159
+ }, {
160
+ fileName: import.meta.url,
161
+ lineNumber: 87,
162
+ columnNumber: 26
163
+ })])).toRenderTo("Test");
164
+ });
165
+ it("renders nested object", () => {
166
+ expect(toSourceText([_$createComponent(py.Atom, {
167
+ jsValue: {
168
+ a: {
169
+ b: {
170
+ c: 1
171
+ }
172
+ },
173
+ d: 2
174
+ }
175
+ }, {
176
+ fileName: import.meta.url,
177
+ lineNumber: 92,
178
+ columnNumber: 21
179
+ })])).toRenderTo('{"a": {"b": {"c": 1}}, "d": 2}');
180
+ });
181
+ });
182
+ //# sourceMappingURL=values.test.js.map