@goast/kotlin 0.4.7-beta2 → 0.4.8

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 (509) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +45 -45
  3. package/assets/client/okhttp3/ApiClient.kt +250 -250
  4. package/esm/_dnt.test_polyfills.d.ts +29 -0
  5. package/esm/_dnt.test_polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.test_polyfills.js +31 -0
  7. package/esm/_dnt.test_shims.d.ts +6 -0
  8. package/esm/_dnt.test_shims.d.ts.map +1 -0
  9. package/esm/_dnt.test_shims.js +61 -0
  10. package/esm/deps/jsr.io/@std/assert/1.0.9/assertion_error.d.ts +26 -0
  11. package/esm/deps/jsr.io/@std/assert/1.0.9/assertion_error.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/assert/1.0.9/assertion_error.js +30 -0
  13. package/esm/deps/jsr.io/@std/assert/1.0.9/equal.d.ts +17 -0
  14. package/esm/deps/jsr.io/@std/assert/1.0.9/equal.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/assert/1.0.9/equal.js +183 -0
  16. package/esm/deps/jsr.io/@std/assert/1.0.9/equals.d.ts +35 -0
  17. package/esm/deps/jsr.io/@std/assert/1.0.9/equals.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/assert/1.0.9/equals.js +58 -0
  19. package/esm/deps/jsr.io/@std/assert/1.0.9/false.d.ts +18 -0
  20. package/esm/deps/jsr.io/@std/assert/1.0.9/false.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@std/assert/1.0.9/false.js +22 -0
  22. package/esm/deps/jsr.io/@std/assert/1.0.9/instance_of.d.ts +23 -0
  23. package/esm/deps/jsr.io/@std/assert/1.0.9/instance_of.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@std/assert/1.0.9/instance_of.js +53 -0
  25. package/esm/deps/jsr.io/@std/assert/1.0.9/is_error.d.ts +25 -0
  26. package/esm/deps/jsr.io/@std/assert/1.0.9/is_error.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/assert/1.0.9/is_error.js +54 -0
  28. package/esm/deps/jsr.io/@std/assert/1.0.9/match.d.ts +18 -0
  29. package/esm/deps/jsr.io/@std/assert/1.0.9/match.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/assert/1.0.9/match.js +26 -0
  31. package/esm/deps/jsr.io/@std/assert/1.0.9/not_instance_of.d.ts +20 -0
  32. package/esm/deps/jsr.io/@std/assert/1.0.9/not_instance_of.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@std/assert/1.0.9/not_instance_of.js +29 -0
  34. package/esm/deps/jsr.io/@std/assert/1.0.9/not_match.d.ts +18 -0
  35. package/esm/deps/jsr.io/@std/assert/1.0.9/not_match.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@std/assert/1.0.9/not_match.js +26 -0
  37. package/esm/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.d.ts +23 -0
  38. package/esm/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.js +32 -0
  40. package/esm/deps/jsr.io/@std/assert/1.0.9/rejects.d.ts +42 -0
  41. package/esm/deps/jsr.io/@std/assert/1.0.9/rejects.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@std/assert/1.0.9/rejects.js +53 -0
  43. package/esm/deps/jsr.io/@std/assert/1.0.9/strict_equals.d.ts +24 -0
  44. package/esm/deps/jsr.io/@std/assert/1.0.9/strict_equals.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@std/assert/1.0.9/strict_equals.js +57 -0
  46. package/esm/deps/jsr.io/@std/expect/1.0.9/_assert_equals.d.ts +20 -0
  47. package/esm/deps/jsr.io/@std/expect/1.0.9/_assert_equals.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@std/expect/1.0.9/_assert_equals.js +29 -0
  49. package/esm/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.d.ts +17 -0
  50. package/esm/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.js +26 -0
  52. package/esm/deps/jsr.io/@std/expect/1.0.9/_assertions.d.ts +4 -0
  53. package/esm/deps/jsr.io/@std/expect/1.0.9/_assertions.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@std/expect/1.0.9/_assertions.js +13 -0
  55. package/esm/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.d.ts +46 -0
  56. package/esm/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.js +160 -0
  58. package/esm/deps/jsr.io/@std/expect/1.0.9/_build_message.d.ts +6 -0
  59. package/esm/deps/jsr.io/@std/expect/1.0.9/_build_message.d.ts.map +1 -0
  60. package/esm/deps/jsr.io/@std/expect/1.0.9/_build_message.js +29 -0
  61. package/esm/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.d.ts +4 -0
  62. package/esm/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.js +11 -0
  64. package/esm/deps/jsr.io/@std/expect/1.0.9/_equal.d.ts +9 -0
  65. package/esm/deps/jsr.io/@std/expect/1.0.9/_equal.d.ts.map +1 -0
  66. package/esm/deps/jsr.io/@std/expect/1.0.9/_equal.js +191 -0
  67. package/esm/deps/jsr.io/@std/expect/1.0.9/_extend.d.ts +4 -0
  68. package/esm/deps/jsr.io/@std/expect/1.0.9/_extend.d.ts.map +1 -0
  69. package/esm/deps/jsr.io/@std/expect/1.0.9/_extend.js +11 -0
  70. package/esm/deps/jsr.io/@std/expect/1.0.9/_inspect_args.d.ts +3 -0
  71. package/esm/deps/jsr.io/@std/expect/1.0.9/_inspect_args.d.ts.map +1 -0
  72. package/esm/deps/jsr.io/@std/expect/1.0.9/_inspect_args.js +12 -0
  73. package/esm/deps/jsr.io/@std/expect/1.0.9/_matchers.d.ts +34 -0
  74. package/esm/deps/jsr.io/@std/expect/1.0.9/_matchers.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@std/expect/1.0.9/_matchers.js +568 -0
  76. package/esm/deps/jsr.io/@std/expect/1.0.9/_mock_util.d.ts +11 -0
  77. package/esm/deps/jsr.io/@std/expect/1.0.9/_mock_util.d.ts.map +1 -0
  78. package/esm/deps/jsr.io/@std/expect/1.0.9/_mock_util.js +10 -0
  79. package/esm/deps/jsr.io/@std/expect/1.0.9/_serializer.d.ts +4 -0
  80. package/esm/deps/jsr.io/@std/expect/1.0.9/_serializer.d.ts.map +1 -0
  81. package/esm/deps/jsr.io/@std/expect/1.0.9/_serializer.js +10 -0
  82. package/esm/deps/jsr.io/@std/expect/1.0.9/_types.d.ts +839 -0
  83. package/esm/deps/jsr.io/@std/expect/1.0.9/_types.d.ts.map +1 -0
  84. package/esm/deps/jsr.io/@std/expect/1.0.9/_types.js +3 -0
  85. package/esm/deps/jsr.io/@std/expect/1.0.9/_utils.d.ts +9 -0
  86. package/esm/deps/jsr.io/@std/expect/1.0.9/_utils.d.ts.map +1 -0
  87. package/esm/deps/jsr.io/@std/expect/1.0.9/_utils.js +218 -0
  88. package/esm/deps/jsr.io/@std/expect/1.0.9/expect.d.ts +60 -0
  89. package/esm/deps/jsr.io/@std/expect/1.0.9/expect.d.ts.map +1 -0
  90. package/esm/deps/jsr.io/@std/expect/1.0.9/expect.js +523 -0
  91. package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts +160 -0
  92. package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  93. package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.js +199 -0
  94. package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +82 -0
  95. package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
  96. package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js +111 -0
  97. package/esm/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +140 -0
  98. package/esm/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
  99. package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js +277 -0
  100. package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +99 -0
  101. package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
  102. package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js +180 -0
  103. package/esm/deps/jsr.io/@std/internal/1.0.5/format.d.ts +2 -0
  104. package/esm/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
  105. package/esm/deps/jsr.io/@std/internal/1.0.5/format.js +37 -0
  106. package/esm/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +159 -0
  107. package/esm/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
  108. package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js +207 -0
  109. package/esm/deps/jsr.io/@std/internal/1.0.5/types.d.ts +16 -0
  110. package/esm/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
  111. package/esm/deps/jsr.io/@std/internal/1.0.5/types.js +2 -0
  112. package/esm/deps/jsr.io/@std/testing/1.0.6/_mock_utils.d.ts +15 -0
  113. package/esm/deps/jsr.io/@std/testing/1.0.6/_mock_utils.d.ts.map +1 -0
  114. package/esm/deps/jsr.io/@std/testing/1.0.6/_mock_utils.js +35 -0
  115. package/esm/deps/jsr.io/@std/testing/1.0.6/_test_suite.d.ts +74 -0
  116. package/esm/deps/jsr.io/@std/testing/1.0.6/_test_suite.d.ts.map +1 -0
  117. package/esm/deps/jsr.io/@std/testing/1.0.6/_test_suite.js +350 -0
  118. package/esm/deps/jsr.io/@std/testing/1.0.6/bdd.d.ts +736 -0
  119. package/esm/deps/jsr.io/@std/testing/1.0.6/bdd.d.ts.map +1 -0
  120. package/esm/deps/jsr.io/@std/testing/1.0.6/bdd.js +652 -0
  121. package/esm/deps/jsr.io/@std/testing/1.0.6/mock.d.ts +674 -0
  122. package/esm/deps/jsr.io/@std/testing/1.0.6/mock.d.ts.map +1 -0
  123. package/esm/deps/jsr.io/@std/testing/1.0.6/mock.js +1083 -0
  124. package/esm/src/ast/nodes/annotation.test.d.ts +2 -0
  125. package/esm/src/ast/nodes/annotation.test.d.ts.map +1 -0
  126. package/esm/src/ast/nodes/annotation.test.js +56 -0
  127. package/esm/src/ast/nodes/argument.test.d.ts +2 -0
  128. package/esm/src/ast/nodes/argument.test.d.ts.map +1 -0
  129. package/esm/src/ast/nodes/argument.test.js +33 -0
  130. package/esm/src/ast/nodes/call.test.d.ts +2 -0
  131. package/esm/src/ast/nodes/call.test.d.ts.map +1 -0
  132. package/esm/src/ast/nodes/call.test.js +35 -0
  133. package/esm/src/ast/nodes/class.test.d.ts +2 -0
  134. package/esm/src/ast/nodes/class.test.d.ts.map +1 -0
  135. package/esm/src/ast/nodes/class.test.js +219 -0
  136. package/esm/src/ast/nodes/constructor.test.d.ts +2 -0
  137. package/esm/src/ast/nodes/constructor.test.d.ts.map +1 -0
  138. package/esm/src/ast/nodes/constructor.test.js +139 -0
  139. package/esm/src/ast/nodes/doc-tag.test.d.ts +2 -0
  140. package/esm/src/ast/nodes/doc-tag.test.d.ts.map +1 -0
  141. package/esm/src/ast/nodes/doc-tag.test.js +67 -0
  142. package/esm/src/ast/nodes/doc.test.d.ts +2 -0
  143. package/esm/src/ast/nodes/doc.test.d.ts.map +1 -0
  144. package/esm/src/ast/nodes/doc.test.js +33 -0
  145. package/esm/src/ast/nodes/enum-value.test.d.ts +2 -0
  146. package/esm/src/ast/nodes/enum-value.test.d.ts.map +1 -0
  147. package/esm/src/ast/nodes/enum-value.test.js +115 -0
  148. package/esm/src/ast/nodes/enum.test.d.ts +2 -0
  149. package/esm/src/ast/nodes/enum.test.d.ts.map +1 -0
  150. package/esm/src/ast/nodes/enum.test.js +129 -0
  151. package/esm/src/ast/nodes/function.test.d.ts +2 -0
  152. package/esm/src/ast/nodes/function.test.d.ts.map +1 -0
  153. package/esm/src/ast/nodes/function.test.js +160 -0
  154. package/esm/src/ast/nodes/generic-parameter.test.d.ts +2 -0
  155. package/esm/src/ast/nodes/generic-parameter.test.d.ts.map +1 -0
  156. package/esm/src/ast/nodes/generic-parameter.test.js +49 -0
  157. package/esm/src/ast/nodes/init-block.test.d.ts +2 -0
  158. package/esm/src/ast/nodes/init-block.test.d.ts.map +1 -0
  159. package/esm/src/ast/nodes/init-block.test.js +28 -0
  160. package/esm/src/ast/nodes/interface.test.d.ts +2 -0
  161. package/esm/src/ast/nodes/interface.test.d.ts.map +1 -0
  162. package/esm/src/ast/nodes/interface.test.js +121 -0
  163. package/esm/src/ast/nodes/object.test.d.ts +2 -0
  164. package/esm/src/ast/nodes/object.test.d.ts.map +1 -0
  165. package/esm/src/ast/nodes/object.test.js +78 -0
  166. package/esm/src/ast/nodes/parameter.test.d.ts +2 -0
  167. package/esm/src/ast/nodes/parameter.test.d.ts.map +1 -0
  168. package/esm/src/ast/nodes/parameter.test.js +152 -0
  169. package/esm/src/ast/nodes/property.test.d.ts +2 -0
  170. package/esm/src/ast/nodes/property.test.d.ts.map +1 -0
  171. package/esm/src/ast/nodes/property.test.js +206 -0
  172. package/esm/src/ast/nodes/reference.test.d.ts +2 -0
  173. package/esm/src/ast/nodes/reference.test.d.ts.map +1 -0
  174. package/esm/src/ast/nodes/reference.test.js +36 -0
  175. package/esm/src/ast/nodes/string.test.d.ts +2 -0
  176. package/esm/src/ast/nodes/string.test.d.ts.map +1 -0
  177. package/esm/src/ast/nodes/string.test.js +48 -0
  178. package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +26 -26
  179. package/esm/src/generators/services/spring-controllers/models.d.ts +1 -0
  180. package/esm/src/generators/services/spring-controllers/models.d.ts.map +1 -1
  181. package/esm/src/generators/services/spring-controllers/models.js +1 -0
  182. package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts +1 -1
  183. package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
  184. package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +11 -4
  185. package/esm/src/import-collection.test.d.ts +2 -0
  186. package/esm/src/import-collection.test.d.ts.map +1 -0
  187. package/esm/src/import-collection.test.js +99 -0
  188. package/esm/tests/openapi-models.test.d.ts +2 -0
  189. package/esm/tests/openapi-models.test.d.ts.map +1 -0
  190. package/esm/tests/openapi-models.test.js +45 -0
  191. package/package.json +1 -1
  192. package/script/_dnt.test_polyfills.d.ts +29 -0
  193. package/script/_dnt.test_polyfills.d.ts.map +1 -0
  194. package/script/_dnt.test_polyfills.js +32 -0
  195. package/script/_dnt.test_shims.d.ts +6 -0
  196. package/script/_dnt.test_shims.d.ts.map +1 -0
  197. package/script/_dnt.test_shims.js +65 -0
  198. package/script/deps/jsr.io/@std/assert/1.0.9/assertion_error.d.ts +26 -0
  199. package/script/deps/jsr.io/@std/assert/1.0.9/assertion_error.d.ts.map +1 -0
  200. package/script/deps/jsr.io/@std/assert/1.0.9/assertion_error.js +34 -0
  201. package/script/deps/jsr.io/@std/assert/1.0.9/equal.d.ts +17 -0
  202. package/script/deps/jsr.io/@std/assert/1.0.9/equal.d.ts.map +1 -0
  203. package/script/deps/jsr.io/@std/assert/1.0.9/equal.js +187 -0
  204. package/script/deps/jsr.io/@std/assert/1.0.9/equals.d.ts +35 -0
  205. package/script/deps/jsr.io/@std/assert/1.0.9/equals.d.ts.map +1 -0
  206. package/script/deps/jsr.io/@std/assert/1.0.9/equals.js +61 -0
  207. package/script/deps/jsr.io/@std/assert/1.0.9/false.d.ts +18 -0
  208. package/script/deps/jsr.io/@std/assert/1.0.9/false.d.ts.map +1 -0
  209. package/script/deps/jsr.io/@std/assert/1.0.9/false.js +25 -0
  210. package/script/deps/jsr.io/@std/assert/1.0.9/instance_of.d.ts +23 -0
  211. package/script/deps/jsr.io/@std/assert/1.0.9/instance_of.d.ts.map +1 -0
  212. package/script/deps/jsr.io/@std/assert/1.0.9/instance_of.js +56 -0
  213. package/script/deps/jsr.io/@std/assert/1.0.9/is_error.d.ts +25 -0
  214. package/script/deps/jsr.io/@std/assert/1.0.9/is_error.d.ts.map +1 -0
  215. package/script/deps/jsr.io/@std/assert/1.0.9/is_error.js +57 -0
  216. package/script/deps/jsr.io/@std/assert/1.0.9/match.d.ts +18 -0
  217. package/script/deps/jsr.io/@std/assert/1.0.9/match.d.ts.map +1 -0
  218. package/script/deps/jsr.io/@std/assert/1.0.9/match.js +29 -0
  219. package/script/deps/jsr.io/@std/assert/1.0.9/not_instance_of.d.ts +20 -0
  220. package/script/deps/jsr.io/@std/assert/1.0.9/not_instance_of.d.ts.map +1 -0
  221. package/script/deps/jsr.io/@std/assert/1.0.9/not_instance_of.js +32 -0
  222. package/script/deps/jsr.io/@std/assert/1.0.9/not_match.d.ts +18 -0
  223. package/script/deps/jsr.io/@std/assert/1.0.9/not_match.d.ts.map +1 -0
  224. package/script/deps/jsr.io/@std/assert/1.0.9/not_match.js +29 -0
  225. package/script/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.d.ts +23 -0
  226. package/script/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.d.ts.map +1 -0
  227. package/script/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.js +35 -0
  228. package/script/deps/jsr.io/@std/assert/1.0.9/rejects.d.ts +42 -0
  229. package/script/deps/jsr.io/@std/assert/1.0.9/rejects.d.ts.map +1 -0
  230. package/script/deps/jsr.io/@std/assert/1.0.9/rejects.js +56 -0
  231. package/script/deps/jsr.io/@std/assert/1.0.9/strict_equals.d.ts +24 -0
  232. package/script/deps/jsr.io/@std/assert/1.0.9/strict_equals.d.ts.map +1 -0
  233. package/script/deps/jsr.io/@std/assert/1.0.9/strict_equals.js +60 -0
  234. package/script/deps/jsr.io/@std/expect/1.0.9/_assert_equals.d.ts +20 -0
  235. package/script/deps/jsr.io/@std/expect/1.0.9/_assert_equals.d.ts.map +1 -0
  236. package/script/deps/jsr.io/@std/expect/1.0.9/_assert_equals.js +32 -0
  237. package/script/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.d.ts +17 -0
  238. package/script/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.d.ts.map +1 -0
  239. package/script/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.js +29 -0
  240. package/script/deps/jsr.io/@std/expect/1.0.9/_assertions.d.ts +4 -0
  241. package/script/deps/jsr.io/@std/expect/1.0.9/_assertions.d.ts.map +1 -0
  242. package/script/deps/jsr.io/@std/expect/1.0.9/_assertions.js +18 -0
  243. package/script/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.d.ts +46 -0
  244. package/script/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.d.ts.map +1 -0
  245. package/script/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.js +182 -0
  246. package/script/deps/jsr.io/@std/expect/1.0.9/_build_message.d.ts +6 -0
  247. package/script/deps/jsr.io/@std/expect/1.0.9/_build_message.d.ts.map +1 -0
  248. package/script/deps/jsr.io/@std/expect/1.0.9/_build_message.js +33 -0
  249. package/script/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.d.ts +4 -0
  250. package/script/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.d.ts.map +1 -0
  251. package/script/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.js +15 -0
  252. package/script/deps/jsr.io/@std/expect/1.0.9/_equal.d.ts +9 -0
  253. package/script/deps/jsr.io/@std/expect/1.0.9/_equal.d.ts.map +1 -0
  254. package/script/deps/jsr.io/@std/expect/1.0.9/_equal.js +194 -0
  255. package/script/deps/jsr.io/@std/expect/1.0.9/_extend.d.ts +4 -0
  256. package/script/deps/jsr.io/@std/expect/1.0.9/_extend.d.ts.map +1 -0
  257. package/script/deps/jsr.io/@std/expect/1.0.9/_extend.js +15 -0
  258. package/script/deps/jsr.io/@std/expect/1.0.9/_inspect_args.d.ts +3 -0
  259. package/script/deps/jsr.io/@std/expect/1.0.9/_inspect_args.d.ts.map +1 -0
  260. package/script/deps/jsr.io/@std/expect/1.0.9/_inspect_args.js +17 -0
  261. package/script/deps/jsr.io/@std/expect/1.0.9/_matchers.d.ts +34 -0
  262. package/script/deps/jsr.io/@std/expect/1.0.9/_matchers.d.ts.map +1 -0
  263. package/script/deps/jsr.io/@std/expect/1.0.9/_matchers.js +602 -0
  264. package/script/deps/jsr.io/@std/expect/1.0.9/_mock_util.d.ts +11 -0
  265. package/script/deps/jsr.io/@std/expect/1.0.9/_mock_util.d.ts.map +1 -0
  266. package/script/deps/jsr.io/@std/expect/1.0.9/_mock_util.js +14 -0
  267. package/script/deps/jsr.io/@std/expect/1.0.9/_serializer.d.ts +4 -0
  268. package/script/deps/jsr.io/@std/expect/1.0.9/_serializer.d.ts.map +1 -0
  269. package/script/deps/jsr.io/@std/expect/1.0.9/_serializer.js +14 -0
  270. package/script/deps/jsr.io/@std/expect/1.0.9/_types.d.ts +839 -0
  271. package/script/deps/jsr.io/@std/expect/1.0.9/_types.d.ts.map +1 -0
  272. package/script/deps/jsr.io/@std/expect/1.0.9/_types.js +4 -0
  273. package/script/deps/jsr.io/@std/expect/1.0.9/_utils.d.ts +9 -0
  274. package/script/deps/jsr.io/@std/expect/1.0.9/_utils.d.ts.map +1 -0
  275. package/script/deps/jsr.io/@std/expect/1.0.9/_utils.js +226 -0
  276. package/script/deps/jsr.io/@std/expect/1.0.9/expect.d.ts +60 -0
  277. package/script/deps/jsr.io/@std/expect/1.0.9/expect.d.ts.map +1 -0
  278. package/script/deps/jsr.io/@std/expect/1.0.9/expect.js +527 -0
  279. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts +160 -0
  280. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  281. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.js +204 -0
  282. package/script/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +82 -0
  283. package/script/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
  284. package/script/deps/jsr.io/@std/internal/1.0.5/build_message.js +116 -0
  285. package/script/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +140 -0
  286. package/script/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
  287. package/script/deps/jsr.io/@std/internal/1.0.5/diff.js +284 -0
  288. package/script/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +99 -0
  289. package/script/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
  290. package/script/deps/jsr.io/@std/internal/1.0.5/diff_str.js +186 -0
  291. package/script/deps/jsr.io/@std/internal/1.0.5/format.d.ts +2 -0
  292. package/script/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
  293. package/script/deps/jsr.io/@std/internal/1.0.5/format.js +41 -0
  294. package/script/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +159 -0
  295. package/script/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
  296. package/script/deps/jsr.io/@std/internal/1.0.5/styles.js +220 -0
  297. package/script/deps/jsr.io/@std/internal/1.0.5/types.d.ts +16 -0
  298. package/script/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
  299. package/script/deps/jsr.io/@std/internal/1.0.5/types.js +3 -0
  300. package/script/deps/jsr.io/@std/testing/1.0.6/_mock_utils.d.ts +15 -0
  301. package/script/deps/jsr.io/@std/testing/1.0.6/_mock_utils.d.ts.map +1 -0
  302. package/script/deps/jsr.io/@std/testing/1.0.6/_mock_utils.js +41 -0
  303. package/script/deps/jsr.io/@std/testing/1.0.6/_test_suite.d.ts +74 -0
  304. package/script/deps/jsr.io/@std/testing/1.0.6/_test_suite.d.ts.map +1 -0
  305. package/script/deps/jsr.io/@std/testing/1.0.6/_test_suite.js +355 -0
  306. package/script/deps/jsr.io/@std/testing/1.0.6/bdd.d.ts +736 -0
  307. package/script/deps/jsr.io/@std/testing/1.0.6/bdd.d.ts.map +1 -0
  308. package/script/deps/jsr.io/@std/testing/1.0.6/bdd.js +663 -0
  309. package/script/deps/jsr.io/@std/testing/1.0.6/mock.d.ts +674 -0
  310. package/script/deps/jsr.io/@std/testing/1.0.6/mock.d.ts.map +1 -0
  311. package/script/deps/jsr.io/@std/testing/1.0.6/mock.js +1102 -0
  312. package/script/src/ast/nodes/annotation.test.d.ts +2 -0
  313. package/script/src/ast/nodes/annotation.test.d.ts.map +1 -0
  314. package/script/src/ast/nodes/annotation.test.js +58 -0
  315. package/script/src/ast/nodes/argument.test.d.ts +2 -0
  316. package/script/src/ast/nodes/argument.test.d.ts.map +1 -0
  317. package/script/src/ast/nodes/argument.test.js +35 -0
  318. package/script/src/ast/nodes/call.test.d.ts +2 -0
  319. package/script/src/ast/nodes/call.test.d.ts.map +1 -0
  320. package/script/src/ast/nodes/call.test.js +37 -0
  321. package/script/src/ast/nodes/class.test.d.ts +2 -0
  322. package/script/src/ast/nodes/class.test.d.ts.map +1 -0
  323. package/script/src/ast/nodes/class.test.js +221 -0
  324. package/script/src/ast/nodes/constructor.test.d.ts +2 -0
  325. package/script/src/ast/nodes/constructor.test.d.ts.map +1 -0
  326. package/script/src/ast/nodes/constructor.test.js +141 -0
  327. package/script/src/ast/nodes/doc-tag.test.d.ts +2 -0
  328. package/script/src/ast/nodes/doc-tag.test.d.ts.map +1 -0
  329. package/script/src/ast/nodes/doc-tag.test.js +69 -0
  330. package/script/src/ast/nodes/doc.test.d.ts +2 -0
  331. package/script/src/ast/nodes/doc.test.d.ts.map +1 -0
  332. package/script/src/ast/nodes/doc.test.js +35 -0
  333. package/script/src/ast/nodes/enum-value.test.d.ts +2 -0
  334. package/script/src/ast/nodes/enum-value.test.d.ts.map +1 -0
  335. package/script/src/ast/nodes/enum-value.test.js +117 -0
  336. package/script/src/ast/nodes/enum.test.d.ts +2 -0
  337. package/script/src/ast/nodes/enum.test.d.ts.map +1 -0
  338. package/script/src/ast/nodes/enum.test.js +131 -0
  339. package/script/src/ast/nodes/function.test.d.ts +2 -0
  340. package/script/src/ast/nodes/function.test.d.ts.map +1 -0
  341. package/script/src/ast/nodes/function.test.js +162 -0
  342. package/script/src/ast/nodes/generic-parameter.test.d.ts +2 -0
  343. package/script/src/ast/nodes/generic-parameter.test.d.ts.map +1 -0
  344. package/script/src/ast/nodes/generic-parameter.test.js +51 -0
  345. package/script/src/ast/nodes/init-block.test.d.ts +2 -0
  346. package/script/src/ast/nodes/init-block.test.d.ts.map +1 -0
  347. package/script/src/ast/nodes/init-block.test.js +30 -0
  348. package/script/src/ast/nodes/interface.test.d.ts +2 -0
  349. package/script/src/ast/nodes/interface.test.d.ts.map +1 -0
  350. package/script/src/ast/nodes/interface.test.js +123 -0
  351. package/script/src/ast/nodes/object.test.d.ts +2 -0
  352. package/script/src/ast/nodes/object.test.d.ts.map +1 -0
  353. package/script/src/ast/nodes/object.test.js +80 -0
  354. package/script/src/ast/nodes/parameter.test.d.ts +2 -0
  355. package/script/src/ast/nodes/parameter.test.d.ts.map +1 -0
  356. package/script/src/ast/nodes/parameter.test.js +154 -0
  357. package/script/src/ast/nodes/property.test.d.ts +2 -0
  358. package/script/src/ast/nodes/property.test.d.ts.map +1 -0
  359. package/script/src/ast/nodes/property.test.js +208 -0
  360. package/script/src/ast/nodes/reference.test.d.ts +2 -0
  361. package/script/src/ast/nodes/reference.test.d.ts.map +1 -0
  362. package/script/src/ast/nodes/reference.test.js +38 -0
  363. package/script/src/ast/nodes/string.test.d.ts +2 -0
  364. package/script/src/ast/nodes/string.test.d.ts.map +1 -0
  365. package/script/src/ast/nodes/string.test.js +50 -0
  366. package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +26 -26
  367. package/script/src/generators/services/spring-controllers/models.d.ts +1 -0
  368. package/script/src/generators/services/spring-controllers/models.d.ts.map +1 -1
  369. package/script/src/generators/services/spring-controllers/models.js +1 -0
  370. package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts +1 -1
  371. package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
  372. package/script/src/generators/services/spring-controllers/spring-controller-generator.js +12 -5
  373. package/script/src/import-collection.test.d.ts +2 -0
  374. package/script/src/import-collection.test.d.ts.map +1 -0
  375. package/script/src/import-collection.test.js +101 -0
  376. package/script/tests/openapi-models.test.d.ts +2 -0
  377. package/script/tests/openapi-models.test.d.ts.map +1 -0
  378. package/script/tests/openapi-models.test.js +48 -0
  379. package/src/_dnt.test_polyfills.ts +70 -0
  380. package/src/_dnt.test_shims.ts +64 -0
  381. package/src/deps/jsr.io/@std/assert/1.0.9/assertion_error.ts +31 -0
  382. package/src/deps/jsr.io/@std/assert/1.0.9/equal.ts +210 -0
  383. package/src/deps/jsr.io/@std/assert/1.0.9/equals.ts +65 -0
  384. package/src/deps/jsr.io/@std/assert/1.0.9/false.ts +26 -0
  385. package/src/deps/jsr.io/@std/assert/1.0.9/instance_of.ts +64 -0
  386. package/src/deps/jsr.io/@std/assert/1.0.9/is_error.ts +65 -0
  387. package/src/deps/jsr.io/@std/assert/1.0.9/match.ts +30 -0
  388. package/src/deps/jsr.io/@std/assert/1.0.9/not_instance_of.ts +33 -0
  389. package/src/deps/jsr.io/@std/assert/1.0.9/not_match.ts +30 -0
  390. package/src/deps/jsr.io/@std/assert/1.0.9/not_strict_equals.ts +42 -0
  391. package/src/deps/jsr.io/@std/assert/1.0.9/rejects.ts +123 -0
  392. package/src/deps/jsr.io/@std/assert/1.0.9/strict_equals.ts +67 -0
  393. package/src/deps/jsr.io/@std/expect/1.0.9/_assert_equals.ts +38 -0
  394. package/src/deps/jsr.io/@std/expect/1.0.9/_assert_not_equals.ts +35 -0
  395. package/src/deps/jsr.io/@std/expect/1.0.9/_assertions.ts +18 -0
  396. package/src/deps/jsr.io/@std/expect/1.0.9/_asymmetric_matchers.ts +193 -0
  397. package/src/deps/jsr.io/@std/expect/1.0.9/_build_message.ts +51 -0
  398. package/src/deps/jsr.io/@std/expect/1.0.9/_custom_equality_tester.ts +19 -0
  399. package/src/deps/jsr.io/@std/expect/1.0.9/_equal.ts +230 -0
  400. package/src/deps/jsr.io/@std/expect/1.0.9/_extend.ts +16 -0
  401. package/src/deps/jsr.io/@std/expect/1.0.9/_inspect_args.ts +15 -0
  402. package/src/deps/jsr.io/@std/expect/1.0.9/_matchers.ts +838 -0
  403. package/src/deps/jsr.io/@std/expect/1.0.9/_mock_util.ts +22 -0
  404. package/src/deps/jsr.io/@std/expect/1.0.9/_serializer.ts +15 -0
  405. package/src/deps/jsr.io/@std/expect/1.0.9/_types.ts +919 -0
  406. package/src/deps/jsr.io/@std/expect/1.0.9/_utils.ts +283 -0
  407. package/src/deps/jsr.io/@std/expect/1.0.9/expect.ts +620 -0
  408. package/src/deps/jsr.io/@std/internal/1.0.5/assertion_state.ts +214 -0
  409. package/src/deps/jsr.io/@std/internal/1.0.5/build_message.ts +134 -0
  410. package/src/deps/jsr.io/@std/internal/1.0.5/diff.ts +317 -0
  411. package/src/deps/jsr.io/@std/internal/1.0.5/diff_str.ts +204 -0
  412. package/src/deps/jsr.io/@std/internal/1.0.5/format.ts +39 -0
  413. package/src/deps/jsr.io/@std/internal/1.0.5/styles.ts +233 -0
  414. package/src/deps/jsr.io/@std/internal/1.0.5/types.ts +18 -0
  415. package/src/deps/jsr.io/@std/testing/1.0.6/_mock_utils.ts +43 -0
  416. package/src/deps/jsr.io/@std/testing/1.0.6/_test_suite.ts +410 -0
  417. package/src/deps/jsr.io/@std/testing/1.0.6/bdd.ts +1285 -0
  418. package/src/deps/jsr.io/@std/testing/1.0.6/mock.ts +1807 -0
  419. package/src/mod.ts +8 -0
  420. package/src/src/assets.ts +9 -0
  421. package/src/src/ast/_index.ts +66 -0
  422. package/src/src/ast/common.ts +1 -0
  423. package/src/src/ast/index.ts +1 -0
  424. package/src/src/ast/node.ts +10 -0
  425. package/src/src/ast/nodes/annotation.test.ts +69 -0
  426. package/src/src/ast/nodes/annotation.ts +79 -0
  427. package/src/src/ast/nodes/argument.test.ts +41 -0
  428. package/src/src/ast/nodes/argument.ts +62 -0
  429. package/src/src/ast/nodes/call.test.ts +44 -0
  430. package/src/src/ast/nodes/call.ts +66 -0
  431. package/src/src/ast/nodes/class.test.ts +274 -0
  432. package/src/src/ast/nodes/class.ts +178 -0
  433. package/src/src/ast/nodes/collection-literal.ts +49 -0
  434. package/src/src/ast/nodes/constructor.test.ts +178 -0
  435. package/src/src/ast/nodes/constructor.ts +126 -0
  436. package/src/src/ast/nodes/doc-tag.test.ts +84 -0
  437. package/src/src/ast/nodes/doc-tag.ts +138 -0
  438. package/src/src/ast/nodes/doc.test.ts +42 -0
  439. package/src/src/ast/nodes/doc.ts +111 -0
  440. package/src/src/ast/nodes/enum-value.test.ts +146 -0
  441. package/src/src/ast/nodes/enum-value.ts +100 -0
  442. package/src/src/ast/nodes/enum.test.ts +167 -0
  443. package/src/src/ast/nodes/enum.ts +163 -0
  444. package/src/src/ast/nodes/function.test.ts +194 -0
  445. package/src/src/ast/nodes/function.ts +176 -0
  446. package/src/src/ast/nodes/generic-parameter.test.ts +60 -0
  447. package/src/src/ast/nodes/generic-parameter.ts +54 -0
  448. package/src/src/ast/nodes/init-block.test.ts +36 -0
  449. package/src/src/ast/nodes/init-block.ts +38 -0
  450. package/src/src/ast/nodes/interface.test.ts +151 -0
  451. package/src/src/ast/nodes/interface.ts +133 -0
  452. package/src/src/ast/nodes/lambda-type.ts +68 -0
  453. package/src/src/ast/nodes/lambda.ts +68 -0
  454. package/src/src/ast/nodes/object.test.ts +101 -0
  455. package/src/src/ast/nodes/object.ts +102 -0
  456. package/src/src/ast/nodes/parameter.test.ts +191 -0
  457. package/src/src/ast/nodes/parameter.ts +118 -0
  458. package/src/src/ast/nodes/property.test.ts +253 -0
  459. package/src/src/ast/nodes/property.ts +225 -0
  460. package/src/src/ast/nodes/reference.test.ts +47 -0
  461. package/src/src/ast/nodes/reference.ts +178 -0
  462. package/src/src/ast/nodes/string.test.ts +61 -0
  463. package/src/src/ast/nodes/string.ts +114 -0
  464. package/src/src/ast/nodes/types.ts +23 -0
  465. package/src/src/ast/references/index.ts +8 -0
  466. package/src/src/ast/references/jackson.ts +16 -0
  467. package/src/src/ast/references/jakarta.ts +10 -0
  468. package/src/src/ast/references/java.ts +19 -0
  469. package/src/src/ast/references/kotlin.ts +40 -0
  470. package/src/src/ast/references/okhttp3.ts +5 -0
  471. package/src/src/ast/references/reactor.ts +5 -0
  472. package/src/src/ast/references/spring.ts +64 -0
  473. package/src/src/ast/references/swagger.ts +23 -0
  474. package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
  475. package/src/src/ast/utils/to-kt-node.ts +31 -0
  476. package/src/src/ast/utils/write-kt-annotations.ts +15 -0
  477. package/src/src/ast/utils/write-kt-arguments.ts +45 -0
  478. package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
  479. package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
  480. package/src/src/ast/utils/write-kt-members.ts +25 -0
  481. package/src/src/ast/utils/write-kt-node.ts +37 -0
  482. package/src/src/ast/utils/write-kt-parameters.ts +25 -0
  483. package/src/src/common-results.ts +4 -0
  484. package/src/src/config.ts +41 -0
  485. package/src/src/file-builder.ts +108 -0
  486. package/src/src/generators/file-generator.ts +29 -0
  487. package/src/src/generators/index.ts +4 -0
  488. package/src/src/generators/models/args.ts +128 -0
  489. package/src/src/generators/models/index.ts +4 -0
  490. package/src/src/generators/models/model-generator.ts +602 -0
  491. package/src/src/generators/models/models-generator.ts +65 -0
  492. package/src/src/generators/models/models.ts +95 -0
  493. package/src/src/generators/services/okhttp3-clients/args.ts +78 -0
  494. package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
  495. package/src/src/generators/services/okhttp3-clients/models.ts +62 -0
  496. package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +557 -0
  497. package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +130 -0
  498. package/src/src/generators/services/okhttp3-clients/refs.ts +55 -0
  499. package/src/src/generators/services/spring-controllers/args.ts +88 -0
  500. package/src/src/generators/services/spring-controllers/index.ts +4 -0
  501. package/src/src/generators/services/spring-controllers/models.ts +66 -0
  502. package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +754 -0
  503. package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +70 -0
  504. package/src/src/import-collection.test.ts +116 -0
  505. package/src/src/import-collection.ts +98 -0
  506. package/src/src/types.ts +3 -0
  507. package/src/src/utils.ts +39 -0
  508. package/src/tests/openapi-models.test.ts +63 -0
  509. package/test_runner.js +227 -0
@@ -0,0 +1,1083 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ import { __setFunctionName } from "tslib";
3
+ /** A mocking and spying library.
4
+ *
5
+ * Test spies are function stand-ins that are used to assert if a function's
6
+ * internal behavior matches expectations. Test spies on methods keep the original
7
+ * behavior but allow you to test how the method is called and what it returns.
8
+ * Test stubs are an extension of test spies that also replaces the original
9
+ * methods behavior.
10
+ *
11
+ * ## Spying
12
+ *
13
+ * Say we have two functions, `square` and `multiply`, if we want to assert that
14
+ * the `multiply` function is called during execution of the `square` function we
15
+ * need a way to spy on the `multiply` function. There are a few ways to achieve
16
+ * this with Spies, one is to have the `square` function take the `multiply`
17
+ * multiply as a parameter.
18
+ *
19
+ * This way, we can call `square(multiply, value)` in the application code or wrap
20
+ * a spy function around the `multiply` function and call
21
+ * `square(multiplySpy, value)` in the testing code.
22
+ *
23
+ * ```ts
24
+ * import {
25
+ * assertSpyCall,
26
+ * assertSpyCalls,
27
+ * spy,
28
+ * } from "@std/testing/mock";
29
+ * import { assertEquals } from "@std/assert";
30
+ *
31
+ * function multiply(a: number, b: number): number {
32
+ * return a * b;
33
+ * }
34
+ *
35
+ * function square(
36
+ * multiplyFn: (a: number, b: number) => number,
37
+ * value: number,
38
+ * ): number {
39
+ * return multiplyFn(value, value);
40
+ * }
41
+ *
42
+ * Deno.test("square calls multiply and returns results", () => {
43
+ * const multiplySpy = spy(multiply);
44
+ *
45
+ * assertEquals(square(multiplySpy, 5), 25);
46
+ *
47
+ * // asserts that multiplySpy was called at least once and details about the first call.
48
+ * assertSpyCall(multiplySpy, 0, {
49
+ * args: [5, 5],
50
+ * returned: 25,
51
+ * });
52
+ *
53
+ * // asserts that multiplySpy was only called once.
54
+ * assertSpyCalls(multiplySpy, 1);
55
+ * });
56
+ * ```
57
+ *
58
+ * If you prefer not adding additional parameters for testing purposes only, you
59
+ * can use spy to wrap a method on an object instead. In the following example, the
60
+ * exported `_internals` object has the `multiply` function we want to call as a
61
+ * method and the `square` function calls `_internals.multiply` instead of
62
+ * `multiply`.
63
+ *
64
+ * This way, we can call `square(value)` in both the application code and testing
65
+ * code. Then spy on the `multiply` method on the `_internals` object in the
66
+ * testing code to be able to spy on how the `square` function calls the `multiply`
67
+ * function.
68
+ *
69
+ * ```ts
70
+ * import {
71
+ * assertSpyCall,
72
+ * assertSpyCalls,
73
+ * spy,
74
+ * } from "@std/testing/mock";
75
+ * import { assertEquals } from "@std/assert";
76
+ *
77
+ * function multiply(a: number, b: number): number {
78
+ * return a * b;
79
+ * }
80
+ *
81
+ * function square(value: number): number {
82
+ * return _internals.multiply(value, value);
83
+ * }
84
+ *
85
+ * const _internals = { multiply };
86
+ *
87
+ * Deno.test("square calls multiply and returns results", () => {
88
+ * const multiplySpy = spy(_internals, "multiply");
89
+ *
90
+ * try {
91
+ * assertEquals(square(5), 25);
92
+ * } finally {
93
+ * // unwraps the multiply method on the _internals object
94
+ * multiplySpy.restore();
95
+ * }
96
+ *
97
+ * // asserts that multiplySpy was called at least once and details about the first call.
98
+ * assertSpyCall(multiplySpy, 0, {
99
+ * args: [5, 5],
100
+ * returned: 25,
101
+ * });
102
+ *
103
+ * // asserts that multiplySpy was only called once.
104
+ * assertSpyCalls(multiplySpy, 1);
105
+ * });
106
+ * ```
107
+ *
108
+ * One difference you may have noticed between these two examples is that in the
109
+ * second we call the `restore` method on `multiplySpy` function. That is needed to
110
+ * remove the spy wrapper from the `_internals` object's `multiply` method. The
111
+ * `restore` method is called in a finally block to ensure that it is restored
112
+ * whether or not the assertion in the try block is successful. The `restore`
113
+ * method didn't need to be called in the first example because the `multiply`
114
+ * function was not modified in any way like the `_internals` object was in the
115
+ * second example.
116
+ *
117
+ * Method spys are disposable, meaning that you can have them automatically restore
118
+ * themselves with the `using` keyword. Using this approach is cleaner because you
119
+ * do not need to wrap your assertions in a try statement to ensure you restore the
120
+ * methods before the tests finish.
121
+ *
122
+ * ```ts
123
+ * import {
124
+ * assertSpyCall,
125
+ * assertSpyCalls,
126
+ * spy,
127
+ * } from "@std/testing/mock";
128
+ * import { assertEquals } from "@std/assert";
129
+ *
130
+ * function multiply(a: number, b: number): number {
131
+ * return a * b;
132
+ * }
133
+ *
134
+ * function square(value: number): number {
135
+ * return _internals.multiply(value, value);
136
+ * }
137
+ *
138
+ * const _internals = { multiply };
139
+ *
140
+ * Deno.test("square calls multiply and returns results", () => {
141
+ * using multiplySpy = spy(_internals, "multiply");
142
+ *
143
+ * assertEquals(square(5), 25);
144
+ *
145
+ * // asserts that multiplySpy was called at least once and details about the first call.
146
+ * assertSpyCall(multiplySpy, 0, {
147
+ * args: [5, 5],
148
+ * returned: 25,
149
+ * });
150
+ *
151
+ * // asserts that multiplySpy was only called once.
152
+ * assertSpyCalls(multiplySpy, 1);
153
+ * });
154
+ * ```
155
+ *
156
+ * ## Stubbing
157
+ *
158
+ * Say we have two functions, `randomMultiple` and `randomInt`, if we want to
159
+ * assert that `randomInt` is called during execution of `randomMultiple` we need a
160
+ * way to spy on the `randomInt` function. That could be done with either of the
161
+ * spying techniques previously mentioned. To be able to verify that the
162
+ * `randomMultiple` function returns the value we expect it to for what `randomInt`
163
+ * returns, the easiest way would be to replace the `randomInt` function's behavior
164
+ * with more predictable behavior.
165
+ *
166
+ * You could use the first spying technique to do that but that would require
167
+ * adding a `randomInt` parameter to the `randomMultiple` function.
168
+ *
169
+ * You could also use the second spying technique to do that, but your assertions
170
+ * would not be as predictable due to the `randomInt` function returning random
171
+ * values.
172
+ *
173
+ * Say we want to verify it returns correct values for both negative and positive
174
+ * random integers. We could easily do that with stubbing. The below example is
175
+ * similar to the second spying technique example but instead of passing the call
176
+ * through to the original `randomInt` function, we are going to replace
177
+ * `randomInt` with a function that returns pre-defined values.
178
+ *
179
+ * The mock module includes some helper functions to make creating common stubs
180
+ * easy. The `returnsNext` function takes an array of values we want it to return
181
+ * on consecutive calls.
182
+ *
183
+ * ```ts
184
+ * import {
185
+ * assertSpyCall,
186
+ * assertSpyCalls,
187
+ * returnsNext,
188
+ * stub,
189
+ * } from "@std/testing/mock";
190
+ * import { assertEquals } from "@std/assert";
191
+ *
192
+ * function randomInt(lowerBound: number, upperBound: number): number {
193
+ * return lowerBound + Math.floor(Math.random() * (upperBound - lowerBound));
194
+ * }
195
+ *
196
+ * function randomMultiple(value: number): number {
197
+ * return value * _internals.randomInt(-10, 10);
198
+ * }
199
+ *
200
+ * const _internals = { randomInt };
201
+ *
202
+ * Deno.test("randomMultiple uses randomInt to generate random multiples between -10 and 10 times the value", () => {
203
+ * const randomIntStub = stub(_internals, "randomInt", returnsNext([-3, 3]));
204
+ *
205
+ * try {
206
+ * assertEquals(randomMultiple(5), -15);
207
+ * assertEquals(randomMultiple(5), 15);
208
+ * } finally {
209
+ * // unwraps the randomInt method on the _internals object
210
+ * randomIntStub.restore();
211
+ * }
212
+ *
213
+ * // asserts that randomIntStub was called at least once and details about the first call.
214
+ * assertSpyCall(randomIntStub, 0, {
215
+ * args: [-10, 10],
216
+ * returned: -3,
217
+ * });
218
+ * // asserts that randomIntStub was called at least twice and details about the second call.
219
+ * assertSpyCall(randomIntStub, 1, {
220
+ * args: [-10, 10],
221
+ * returned: 3,
222
+ * });
223
+ *
224
+ * // asserts that randomIntStub was only called twice.
225
+ * assertSpyCalls(randomIntStub, 2);
226
+ * });
227
+ * ```
228
+ *
229
+ * Like method spys, stubs are disposable, meaning that you can have them automatically
230
+ * restore themselves with the `using` keyword. Using this approach is cleaner because
231
+ * you do not need to wrap your assertions in a try statement to ensure you restore the
232
+ * methods before the tests finish.
233
+ *
234
+ * ```ts
235
+ * import {
236
+ * assertSpyCall,
237
+ * assertSpyCalls,
238
+ * returnsNext,
239
+ * stub,
240
+ * } from "@std/testing/mock";
241
+ * import { assertEquals } from "@std/assert";
242
+ *
243
+ * function randomInt(lowerBound: number, upperBound: number): number {
244
+ * return lowerBound + Math.floor(Math.random() * (upperBound - lowerBound));
245
+ * }
246
+ *
247
+ * function randomMultiple(value: number): number {
248
+ * return value * _internals.randomInt(-10, 10);
249
+ * }
250
+ *
251
+ * const _internals = { randomInt };
252
+ *
253
+ * Deno.test("randomMultiple uses randomInt to generate random multiples between -10 and 10 times the value", () => {
254
+ * using randomIntStub = stub(_internals, "randomInt", returnsNext([-3, 3]));
255
+ *
256
+ * assertEquals(randomMultiple(5), -15);
257
+ * assertEquals(randomMultiple(5), 15);
258
+ *
259
+ * // asserts that randomIntStub was called at least once and details about the first call.
260
+ * assertSpyCall(randomIntStub, 0, {
261
+ * args: [-10, 10],
262
+ * returned: -3,
263
+ * });
264
+ * // asserts that randomIntStub was called at least twice and details about the second call.
265
+ * assertSpyCall(randomIntStub, 1, {
266
+ * args: [-10, 10],
267
+ * returned: 3,
268
+ * });
269
+ *
270
+ * // asserts that randomIntStub was only called twice.
271
+ * assertSpyCalls(randomIntStub, 2);
272
+ * });
273
+ * ```
274
+ *
275
+ * ## Faking time
276
+ *
277
+ * Say we have a function that has time based behavior that we would like to test.
278
+ * With real time, that could cause tests to take much longer than they should. If
279
+ * you fake time, you could simulate how your function would behave over time
280
+ * starting from any point in time. Below is an example where we want to test that
281
+ * the callback is called every second.
282
+ *
283
+ * With `FakeTime` we can do that. When the `FakeTime` instance is created, it
284
+ * splits from real time. The `Date`, `setTimeout`, `clearTimeout`, `setInterval`
285
+ * and `clearInterval` globals are replaced with versions that use the fake time
286
+ * until real time is restored. You can control how time ticks forward with the
287
+ * `tick` method on the `FakeTime` instance.
288
+ *
289
+ * ```ts
290
+ * import {
291
+ * assertSpyCalls,
292
+ * spy,
293
+ * } from "@std/testing/mock";
294
+ * import { FakeTime } from "@std/testing/time";
295
+ *
296
+ * function secondInterval(cb: () => void): number {
297
+ * return setInterval(cb, 1000);
298
+ * }
299
+ *
300
+ * Deno.test("secondInterval calls callback every second and stops after being cleared", () => {
301
+ * using time = new FakeTime();
302
+ *
303
+ * const cb = spy();
304
+ * const intervalId = secondInterval(cb);
305
+ * assertSpyCalls(cb, 0);
306
+ * time.tick(500);
307
+ * assertSpyCalls(cb, 0);
308
+ * time.tick(500);
309
+ * assertSpyCalls(cb, 1);
310
+ * time.tick(3500);
311
+ * assertSpyCalls(cb, 4);
312
+ *
313
+ * clearInterval(intervalId);
314
+ * time.tick(1000);
315
+ * assertSpyCalls(cb, 4);
316
+ * });
317
+ * ```
318
+ *
319
+ * @module
320
+ */
321
+ import { assertEquals } from "../../assert/1.0.9/equals.js";
322
+ import { assertIsError } from "../../assert/1.0.9/is_error.js";
323
+ import { assertRejects } from "../../assert/1.0.9/rejects.js";
324
+ import { AssertionError } from "../../assert/1.0.9/assertion_error.js";
325
+ import { isSpy, registerMock, sessions, unregisterMock, } from "./_mock_utils.js";
326
+ /**
327
+ * An error related to spying on a function or instance method.
328
+ *
329
+ * @example Usage
330
+ * ```ts
331
+ * import { MockError, spy } from "@std/testing/mock";
332
+ * import { assertThrows } from "@std/assert";
333
+ *
334
+ * assertThrows(() => {
335
+ * spy({} as any, "no-such-method");
336
+ * }, MockError);
337
+ * ```
338
+ */
339
+ export class MockError extends Error {
340
+ /**
341
+ * Construct MockError
342
+ *
343
+ * @param message The error message.
344
+ */
345
+ constructor(message) {
346
+ super(message);
347
+ this.name = "MockError";
348
+ }
349
+ }
350
+ /** Wraps a function with a Spy. */
351
+ function functionSpy(func) {
352
+ const original = func !== null && func !== void 0 ? func : (() => { });
353
+ const calls = [];
354
+ const spy = function (...args) {
355
+ const call = { args };
356
+ if (this)
357
+ call.self = this;
358
+ try {
359
+ call.returned = original.apply(this, args);
360
+ }
361
+ catch (error) {
362
+ call.error = error;
363
+ calls.push(call);
364
+ throw error;
365
+ }
366
+ calls.push(call);
367
+ return call.returned;
368
+ };
369
+ Object.defineProperties(spy, {
370
+ original: {
371
+ enumerable: true,
372
+ value: original,
373
+ },
374
+ calls: {
375
+ enumerable: true,
376
+ value: calls,
377
+ },
378
+ restored: {
379
+ enumerable: true,
380
+ get: () => false,
381
+ },
382
+ restore: {
383
+ enumerable: true,
384
+ value: () => {
385
+ throw new MockError("Cannot restore: function cannot be restored");
386
+ },
387
+ },
388
+ });
389
+ return spy;
390
+ }
391
+ export function mockSession(func) {
392
+ if (func) {
393
+ return function (...args) {
394
+ const id = sessions.length;
395
+ sessions.push(new Set());
396
+ try {
397
+ return func.apply(this, args);
398
+ }
399
+ finally {
400
+ restore(id);
401
+ }
402
+ };
403
+ }
404
+ else {
405
+ sessions.push(new Set());
406
+ return sessions.length - 1;
407
+ }
408
+ }
409
+ /**
410
+ * Creates an async session that tracks all mocks created before the promise resolves.
411
+ *
412
+ * @example Usage
413
+ * ```ts
414
+ * import { mockSessionAsync, restore, stub } from "@std/testing/mock";
415
+ * import { assertEquals, assertNotEquals } from "@std/assert";
416
+ *
417
+ * const setTimeout = globalThis.setTimeout;
418
+ * const session = mockSessionAsync(async () => {
419
+ * stub(globalThis, "setTimeout");
420
+ * assertNotEquals(globalThis.setTimeout, setTimeout);
421
+ * });
422
+ *
423
+ * await session();
424
+ *
425
+ * assertEquals(globalThis.setTimeout, setTimeout); // stub is restored
426
+ * ```
427
+ * @typeParam Self The self type of the function.
428
+ * @typeParam Args The arguments type of the function.
429
+ * @typeParam Return The return type of the function.
430
+ * @param func The function.
431
+ * @returns The return value of the function.
432
+ */
433
+ export function mockSessionAsync(func) {
434
+ return async function (...args) {
435
+ const id = sessions.length;
436
+ sessions.push(new Set());
437
+ try {
438
+ return await func.apply(this, args);
439
+ }
440
+ finally {
441
+ restore(id);
442
+ }
443
+ };
444
+ }
445
+ /**
446
+ * Restores all mocks registered in the current session that have not already been restored.
447
+ * If an id is provided, it will restore all mocks registered in the session associed with that id that have not already been restored.
448
+ *
449
+ * @example Usage
450
+ * ```ts
451
+ * import { mockSession, restore, stub } from "@std/testing/mock";
452
+ * import { assertEquals, assertNotEquals } from "@std/assert";
453
+ *
454
+ * const setTimeout = globalThis.setTimeout;
455
+ *
456
+ * stub(globalThis, "setTimeout");
457
+ *
458
+ * assertNotEquals(globalThis.setTimeout, setTimeout);
459
+ *
460
+ * restore();
461
+ *
462
+ * assertEquals(globalThis.setTimeout, setTimeout);
463
+ * ```
464
+ *
465
+ * @param id The id of the session to restore. If not provided, all mocks registered in the current session are restored.
466
+ */
467
+ export function restore(id) {
468
+ id !== null && id !== void 0 ? id : (id = (sessions.length || 1) - 1);
469
+ while (id < sessions.length) {
470
+ const session = sessions.pop();
471
+ if (session) {
472
+ for (const value of session) {
473
+ value.restore();
474
+ }
475
+ }
476
+ }
477
+ }
478
+ /** Wraps an instance method with a Spy. */
479
+ function methodSpy(self, property) {
480
+ var _a, _b;
481
+ if (typeof self[property] !== "function") {
482
+ throw new MockError("Cannot spy: property is not an instance method");
483
+ }
484
+ if (isSpy(self[property])) {
485
+ throw new MockError("Cannot spy: already spying on instance method");
486
+ }
487
+ const propertyDescriptor = Object.getOwnPropertyDescriptor(self, property);
488
+ if (propertyDescriptor && !propertyDescriptor.configurable) {
489
+ throw new MockError("Cannot spy: non-configurable instance method");
490
+ }
491
+ const original = self[property];
492
+ const calls = [];
493
+ let restored = false;
494
+ const spy = function (...args) {
495
+ const call = { args };
496
+ if (this)
497
+ call.self = this;
498
+ try {
499
+ call.returned = original.apply(this, args);
500
+ }
501
+ catch (error) {
502
+ call.error = error;
503
+ calls.push(call);
504
+ throw error;
505
+ }
506
+ calls.push(call);
507
+ return call.returned;
508
+ };
509
+ Object.defineProperties(spy, {
510
+ original: {
511
+ enumerable: true,
512
+ value: original,
513
+ },
514
+ calls: {
515
+ enumerable: true,
516
+ value: calls,
517
+ },
518
+ restored: {
519
+ enumerable: true,
520
+ get: () => restored,
521
+ },
522
+ restore: {
523
+ enumerable: true,
524
+ value: () => {
525
+ if (restored) {
526
+ throw new MockError("Cannot restore: instance method already restored");
527
+ }
528
+ if (propertyDescriptor) {
529
+ Object.defineProperty(self, property, propertyDescriptor);
530
+ }
531
+ else {
532
+ delete self[property];
533
+ }
534
+ restored = true;
535
+ unregisterMock(spy);
536
+ },
537
+ },
538
+ [Symbol.dispose]: {
539
+ value: () => {
540
+ spy.restore();
541
+ },
542
+ },
543
+ });
544
+ Object.defineProperty(self, property, {
545
+ configurable: true,
546
+ enumerable: (_a = propertyDescriptor === null || propertyDescriptor === void 0 ? void 0 : propertyDescriptor.enumerable) !== null && _a !== void 0 ? _a : false,
547
+ writable: (_b = propertyDescriptor === null || propertyDescriptor === void 0 ? void 0 : propertyDescriptor.writable) !== null && _b !== void 0 ? _b : false,
548
+ value: spy,
549
+ });
550
+ registerMock(spy);
551
+ return spy;
552
+ }
553
+ /** Wraps a constructor with a Spy. */
554
+ function constructorSpy(constructor) {
555
+ var _a;
556
+ const original = constructor;
557
+ const calls = [];
558
+ // @ts-ignore TS2509: Can't know the type of `original` statically.
559
+ const spy = (_a = class extends original {
560
+ // deno-lint-ignore constructor-super
561
+ constructor(...args) {
562
+ const call = { args };
563
+ try {
564
+ super(...args);
565
+ call.returned = this;
566
+ }
567
+ catch (error) {
568
+ call.error = error;
569
+ calls.push(call);
570
+ throw error;
571
+ }
572
+ calls.push(call);
573
+ }
574
+ static restore() {
575
+ throw new MockError("Cannot restore: constructor cannot be restored");
576
+ }
577
+ },
578
+ __setFunctionName(_a, "spy"),
579
+ Object.defineProperty(_a, "name", {
580
+ enumerable: true,
581
+ configurable: true,
582
+ writable: true,
583
+ value: original.name
584
+ }),
585
+ Object.defineProperty(_a, "original", {
586
+ enumerable: true,
587
+ configurable: true,
588
+ writable: true,
589
+ value: original
590
+ }),
591
+ Object.defineProperty(_a, "calls", {
592
+ enumerable: true,
593
+ configurable: true,
594
+ writable: true,
595
+ value: calls
596
+ }),
597
+ Object.defineProperty(_a, "restored", {
598
+ enumerable: true,
599
+ configurable: true,
600
+ writable: true,
601
+ value: false
602
+ }),
603
+ _a);
604
+ return spy;
605
+ }
606
+ export function spy(funcOrConstOrSelf, property) {
607
+ if (!funcOrConstOrSelf) {
608
+ return functionSpy();
609
+ }
610
+ else if (property !== undefined) {
611
+ return methodSpy(funcOrConstOrSelf, property);
612
+ }
613
+ else if (funcOrConstOrSelf.toString().startsWith("class")) {
614
+ return constructorSpy(funcOrConstOrSelf);
615
+ }
616
+ else {
617
+ return functionSpy(funcOrConstOrSelf);
618
+ }
619
+ }
620
+ export function stub(self, property, func) {
621
+ var _a, _b;
622
+ if (self[property] !== undefined && typeof self[property] !== "function") {
623
+ throw new MockError("Cannot stub: property is not an instance method");
624
+ }
625
+ if (isSpy(self[property])) {
626
+ throw new MockError("Cannot stub: already spying on instance method");
627
+ }
628
+ const propertyDescriptor = Object.getOwnPropertyDescriptor(self, property);
629
+ if (propertyDescriptor && !propertyDescriptor.configurable) {
630
+ throw new MockError("Cannot stub: non-configurable instance method");
631
+ }
632
+ const fake = func !== null && func !== void 0 ? func : (() => { });
633
+ const original = self[property];
634
+ const calls = [];
635
+ let restored = false;
636
+ const stub = function (...args) {
637
+ const call = { args };
638
+ if (this)
639
+ call.self = this;
640
+ try {
641
+ call.returned = fake.apply(this, args);
642
+ }
643
+ catch (error) {
644
+ call.error = error;
645
+ calls.push(call);
646
+ throw error;
647
+ }
648
+ calls.push(call);
649
+ return call.returned;
650
+ };
651
+ Object.defineProperties(stub, {
652
+ original: {
653
+ enumerable: true,
654
+ value: original,
655
+ },
656
+ fake: {
657
+ enumerable: true,
658
+ value: fake,
659
+ },
660
+ calls: {
661
+ enumerable: true,
662
+ value: calls,
663
+ },
664
+ restored: {
665
+ enumerable: true,
666
+ get: () => restored,
667
+ },
668
+ restore: {
669
+ enumerable: true,
670
+ value: () => {
671
+ if (restored) {
672
+ throw new MockError("Cannot restore: instance method already restored");
673
+ }
674
+ if (propertyDescriptor) {
675
+ Object.defineProperty(self, property, propertyDescriptor);
676
+ }
677
+ else {
678
+ delete self[property];
679
+ }
680
+ restored = true;
681
+ unregisterMock(stub);
682
+ },
683
+ },
684
+ [Symbol.dispose]: {
685
+ value: () => {
686
+ stub.restore();
687
+ },
688
+ },
689
+ });
690
+ Object.defineProperty(self, property, {
691
+ configurable: true,
692
+ enumerable: (_a = propertyDescriptor === null || propertyDescriptor === void 0 ? void 0 : propertyDescriptor.enumerable) !== null && _a !== void 0 ? _a : false,
693
+ writable: (_b = propertyDescriptor === null || propertyDescriptor === void 0 ? void 0 : propertyDescriptor.writable) !== null && _b !== void 0 ? _b : false,
694
+ value: stub,
695
+ });
696
+ registerMock(stub);
697
+ return stub;
698
+ }
699
+ /**
700
+ * Asserts that a spy is called as much as expected and no more.
701
+ *
702
+ * @example Usage
703
+ * ```ts
704
+ * import { assertSpyCalls, spy } from "@std/testing/mock";
705
+ *
706
+ * const func = spy();
707
+ *
708
+ * func();
709
+ * func();
710
+ *
711
+ * assertSpyCalls(func, 2);
712
+ * ```
713
+ *
714
+ * @typeParam Self The self type of the spy function.
715
+ * @typeParam Args The arguments type of the spy function.
716
+ * @typeParam Return The return type of the spy function.
717
+ * @param spy The spy to check
718
+ * @param expectedCalls The number of the expected calls.
719
+ */
720
+ export function assertSpyCalls(spy, expectedCalls) {
721
+ try {
722
+ assertEquals(spy.calls.length, expectedCalls);
723
+ }
724
+ catch (e) {
725
+ assertIsError(e);
726
+ let message = spy.calls.length < expectedCalls
727
+ ? "Spy not called as much as expected:\n"
728
+ : "Spy called more than expected:\n";
729
+ message += e.message.split("\n").slice(1).join("\n");
730
+ throw new AssertionError(message);
731
+ }
732
+ }
733
+ function getSpyCall(spy, callIndex) {
734
+ if (spy.calls.length < (callIndex + 1)) {
735
+ throw new AssertionError("Spy not called as much as expected");
736
+ }
737
+ return spy.calls[callIndex];
738
+ }
739
+ /**
740
+ * Asserts that a spy is called as expected.
741
+ *
742
+ * @example Usage
743
+ * ```ts
744
+ * import { assertSpyCall, spy } from "@std/testing/mock";
745
+ *
746
+ * const func = spy((a: number, b: number) => a + b);
747
+ *
748
+ * func(3, 4);
749
+ * func(5, 6);
750
+ *
751
+ * // asserts each call made to the spy function.
752
+ * assertSpyCall(func, 0, { args: [3, 4], returned: 7 });
753
+ * assertSpyCall(func, 1, { args: [5, 6], returned: 11 });
754
+ * ```
755
+ *
756
+ * @typeParam Self The self type of the spy function.
757
+ * @typeParam Args The arguments type of the spy function.
758
+ * @typeParam Return The return type of the spy function.
759
+ * @param spy The spy to check
760
+ * @param callIndex The index of the call to check
761
+ * @param expected The expected spy call.
762
+ */
763
+ export function assertSpyCall(spy, callIndex, expected) {
764
+ var _a, _b;
765
+ const call = getSpyCall(spy, callIndex);
766
+ if (expected) {
767
+ if (expected.args) {
768
+ try {
769
+ assertEquals(call.args, expected.args);
770
+ }
771
+ catch (e) {
772
+ assertIsError(e);
773
+ throw new AssertionError("Spy not called with expected args:\n" +
774
+ e.message.split("\n").slice(1).join("\n"));
775
+ }
776
+ }
777
+ if ("self" in expected) {
778
+ try {
779
+ assertEquals(call.self, expected.self);
780
+ }
781
+ catch (e) {
782
+ assertIsError(e);
783
+ let message = expected.self
784
+ ? "Spy not called as method on expected self:\n"
785
+ : "Spy not expected to be called as method on object:\n";
786
+ message += e.message.split("\n").slice(1).join("\n");
787
+ throw new AssertionError(message);
788
+ }
789
+ }
790
+ if ("returned" in expected) {
791
+ if ("error" in expected) {
792
+ throw new TypeError("Do not expect error and return, only one should be expected");
793
+ }
794
+ if (call.error) {
795
+ throw new AssertionError("Spy call did not return expected value, an error was thrown.");
796
+ }
797
+ try {
798
+ assertEquals(call.returned, expected.returned);
799
+ }
800
+ catch (e) {
801
+ assertIsError(e);
802
+ throw new AssertionError("Spy call did not return expected value:\n" +
803
+ e.message.split("\n").slice(1).join("\n"));
804
+ }
805
+ }
806
+ if ("error" in expected) {
807
+ if ("returned" in call) {
808
+ throw new AssertionError("Spy call did not throw an error, a value was returned.");
809
+ }
810
+ assertIsError(call.error, (_a = expected.error) === null || _a === void 0 ? void 0 : _a.Class, (_b = expected.error) === null || _b === void 0 ? void 0 : _b.msgIncludes);
811
+ }
812
+ }
813
+ }
814
+ /**
815
+ * Asserts that an async spy is called as expected.
816
+ *
817
+ * @example Usage
818
+ * ```ts
819
+ * import { assertSpyCallAsync, spy } from "@std/testing/mock";
820
+ *
821
+ * const func = spy((a: number, b: number) => new Promise((resolve) => {
822
+ * setTimeout(() => resolve(a + b), 100)
823
+ * }));
824
+ *
825
+ * await func(3, 4);
826
+ * await func(5, 6);
827
+ *
828
+ * // asserts each call made to the spy function.
829
+ * await assertSpyCallAsync(func, 0, { args: [3, 4], returned: 7 });
830
+ * await assertSpyCallAsync(func, 1, { args: [5, 6], returned: 11 });
831
+ * ```
832
+ *
833
+ * @typeParam Self The self type of the spy function.
834
+ * @typeParam Args The arguments type of the spy function.
835
+ * @typeParam Return The return type of the spy function.
836
+ * @param spy The spy to check
837
+ * @param callIndex The index of the call to check
838
+ * @param expected The expected spy call.
839
+ */
840
+ export async function assertSpyCallAsync(spy, callIndex, expected) {
841
+ var _a, _b, _c, _d;
842
+ const expectedSync = expected && { ...expected };
843
+ if (expectedSync) {
844
+ delete expectedSync.returned;
845
+ delete expectedSync.error;
846
+ }
847
+ assertSpyCall(spy, callIndex, expectedSync);
848
+ const call = getSpyCall(spy, callIndex);
849
+ if (call.error) {
850
+ throw new AssertionError("Spy call did not return a promise, an error was thrown.");
851
+ }
852
+ if (call.returned !== Promise.resolve(call.returned)) {
853
+ throw new AssertionError("Spy call did not return a promise, a value was returned.");
854
+ }
855
+ if (expected) {
856
+ if ("returned" in expected) {
857
+ if ("error" in expected) {
858
+ throw new TypeError("Do not expect error and return, only one should be expected");
859
+ }
860
+ let expectedResolved;
861
+ try {
862
+ expectedResolved = await expected.returned;
863
+ }
864
+ catch (_e) {
865
+ throw new TypeError("Do not expect rejected promise, expect error instead");
866
+ }
867
+ let resolved;
868
+ try {
869
+ resolved = await call.returned;
870
+ }
871
+ catch (_f) {
872
+ throw new AssertionError("Spy call returned promise was rejected");
873
+ }
874
+ try {
875
+ assertEquals(resolved, expectedResolved);
876
+ }
877
+ catch (e) {
878
+ assertIsError(e);
879
+ throw new AssertionError("Spy call did not resolve to expected value:\n" +
880
+ e.message.split("\n").slice(1).join("\n"));
881
+ }
882
+ }
883
+ if ("error" in expected) {
884
+ await assertRejects(() => Promise.resolve(call.returned), (_b = (_a = expected.error) === null || _a === void 0 ? void 0 : _a.Class) !== null && _b !== void 0 ? _b : Error, (_d = (_c = expected.error) === null || _c === void 0 ? void 0 : _c.msgIncludes) !== null && _d !== void 0 ? _d : "");
885
+ }
886
+ }
887
+ }
888
+ /**
889
+ * Asserts that a spy is called with a specific arg as expected.
890
+ *
891
+ * @example Usage
892
+ * ```ts
893
+ * import { assertSpyCallArg, spy } from "@std/testing/mock";
894
+ *
895
+ * const func = spy((a: number, b: number) => a + b);
896
+ *
897
+ * func(3, 4);
898
+ * func(5, 6);
899
+ *
900
+ * // asserts each call made to the spy function.
901
+ * assertSpyCallArg(func, 0, 0, 3);
902
+ * assertSpyCallArg(func, 0, 1, 4);
903
+ * assertSpyCallArg(func, 1, 0, 5);
904
+ * assertSpyCallArg(func, 1, 1, 6);
905
+ * ```
906
+ *
907
+ * @typeParam Self The self type of the spy function.
908
+ * @typeParam Args The arguments type of the spy function.
909
+ * @typeParam Return The return type of the spy function.
910
+ * @typeParam ExpectedArg The expected type of the argument for the spy to be called.
911
+ * @param spy The spy to check.
912
+ * @param callIndex The index of the call to check.
913
+ * @param argIndex The index of the arguments to check.
914
+ * @param expected The expected argument.
915
+ * @returns The actual argument.
916
+ */
917
+ export function assertSpyCallArg(spy, callIndex, argIndex, expected) {
918
+ const call = getSpyCall(spy, callIndex);
919
+ const arg = call === null || call === void 0 ? void 0 : call.args[argIndex];
920
+ assertEquals(arg, expected);
921
+ return arg;
922
+ }
923
+ export function assertSpyCallArgs(spy, callIndex, argsStart, argsEnd, expected) {
924
+ const call = getSpyCall(spy, callIndex);
925
+ if (!expected) {
926
+ expected = argsEnd;
927
+ argsEnd = undefined;
928
+ }
929
+ if (!expected) {
930
+ expected = argsStart;
931
+ argsStart = undefined;
932
+ }
933
+ const args = typeof argsEnd === "number"
934
+ ? call.args.slice(argsStart, argsEnd)
935
+ : typeof argsStart === "number"
936
+ ? call.args.slice(argsStart)
937
+ : call.args;
938
+ assertEquals(args, expected);
939
+ return args;
940
+ }
941
+ /**
942
+ * Creates a function that returns the instance the method was called on.
943
+ *
944
+ * @example Usage
945
+ * ```ts
946
+ * import { returnsThis } from "@std/testing/mock";
947
+ * import { assertEquals } from "@std/assert";
948
+ *
949
+ * const func = returnsThis();
950
+ * const obj = { func };
951
+ * assertEquals(obj.func(), obj);
952
+ * ```
953
+ *
954
+ * @typeParam Self The self type of the returned function.
955
+ * @typeParam Args The arguments type of the returned function.
956
+ * @returns A function that returns the instance the method was called on.
957
+ */
958
+ export function returnsThis() {
959
+ return function () {
960
+ return this;
961
+ };
962
+ }
963
+ /**
964
+ * Creates a function that returns one of its arguments.
965
+ *
966
+ * @example Usage
967
+ * ```ts
968
+ * import { returnsArg } from "@std/testing/mock";
969
+ * import { assertEquals } from "@std/assert";
970
+ *
971
+ * const func = returnsArg(1);
972
+ * assertEquals(func(1, 2, 3), 2);
973
+ * ```
974
+ *
975
+ * @typeParam Arg The type of returned argument.
976
+ * @typeParam Self The self type of the returned function.
977
+ * @param idx The index of the arguments to use.
978
+ * @returns A function that returns one of its arguments.
979
+ */
980
+ export function returnsArg(idx) {
981
+ return function (...args) {
982
+ return args[idx];
983
+ };
984
+ }
985
+ /**
986
+ * Creates a function that returns its arguments or a subset of them. If end is specified, it will return arguments up to but not including the end.
987
+ *
988
+ * @example Usage
989
+ * ```ts
990
+ * import { returnsArgs } from "@std/testing/mock";
991
+ * import { assertEquals } from "@std/assert";
992
+ *
993
+ * const func = returnsArgs();
994
+ * assertEquals(func(1, 2, 3), [1, 2, 3]);
995
+ * ```
996
+ *
997
+ * @typeParam Args The arguments type of the returned function
998
+ * @typeParam Self The self type of the returned function
999
+ * @param start The start index of the arguments to return. Default is 0.
1000
+ * @param end The end index of the arguments to return.
1001
+ * @returns A function that returns its arguments or a subset of them.
1002
+ */
1003
+ export function returnsArgs(start = 0, end) {
1004
+ return function (...args) {
1005
+ return args.slice(start, end);
1006
+ };
1007
+ }
1008
+ /**
1009
+ * Creates a function that returns the iterable values. Any iterable values that are errors will be thrown.
1010
+ *
1011
+ * @example Usage
1012
+ * ```ts
1013
+ * import { returnsNext } from "@std/testing/mock";
1014
+ * import { assertEquals, assertThrows } from "@std/assert";
1015
+ *
1016
+ * const func = returnsNext([1, 2, new Error("foo"), 3]);
1017
+ * assertEquals(func(), 1);
1018
+ * assertEquals(func(), 2);
1019
+ * assertThrows(() => func(), Error, "foo");
1020
+ * assertEquals(func(), 3);
1021
+ * ```
1022
+ *
1023
+ * @typeParam Return The type of each item of the iterable
1024
+ * @typeParam Self The self type of the returned function
1025
+ * @typeParam Args The arguments type of the returned function
1026
+ * @param values The iterable values
1027
+ * @return A function that returns the iterable values
1028
+ */
1029
+ export function returnsNext(values) {
1030
+ const gen = (function* returnsValue() {
1031
+ yield* values;
1032
+ })();
1033
+ let calls = 0;
1034
+ return function () {
1035
+ const next = gen.next();
1036
+ if (next.done) {
1037
+ throw new MockError(`Not expected to be called more than ${calls} time(s)`);
1038
+ }
1039
+ calls++;
1040
+ const { value } = next;
1041
+ if (value instanceof Error)
1042
+ throw value;
1043
+ return value;
1044
+ };
1045
+ }
1046
+ /**
1047
+ * Creates a function that resolves the awaited iterable values. Any awaited iterable values that are errors will be thrown.
1048
+ *
1049
+ * @example Usage
1050
+ * ```ts
1051
+ * import { resolvesNext } from "@std/testing/mock";
1052
+ * import { assertEquals, assertRejects } from "@std/assert";
1053
+ *
1054
+ * const func = resolvesNext([1, 2, new Error("foo"), 3]);
1055
+ * assertEquals(await func(), 1);
1056
+ * assertEquals(await func(), 2);
1057
+ * assertRejects(() => func(), Error, "foo");
1058
+ * assertEquals(await func(), 3);
1059
+ * ```
1060
+ *
1061
+ * @typeParam Return The type of each item of the iterable
1062
+ * @typeParam Self The self type of the returned function
1063
+ * @typeParam Args The type of arguments of the returned function
1064
+ * @param iterable The iterable to use
1065
+ * @returns A function that resolves the awaited iterable values
1066
+ */
1067
+ export function resolvesNext(iterable) {
1068
+ const gen = (async function* returnsValue() {
1069
+ yield* iterable;
1070
+ })();
1071
+ let calls = 0;
1072
+ return async function () {
1073
+ const next = await gen.next();
1074
+ if (next.done) {
1075
+ throw new MockError(`Not expected to be called more than ${calls} time(s)`);
1076
+ }
1077
+ calls++;
1078
+ const { value } = next;
1079
+ if (value instanceof Error)
1080
+ throw value;
1081
+ return value;
1082
+ };
1083
+ }