@goast/kotlin 0.4.0 → 0.4.2-beta1

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