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