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