PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/packs/stable/clojure-pack/lib/clj-refactor/features/step-definitions/clj-refactor-steps.el

https://gitlab.com/mechasparrow/myemacs
Emacs Lisp | 228 lines | 199 code | 26 blank | 3 comment | 5 complexity | 7747841ddf4ee90c071880386e209aaa MD5 | raw file
  1. (Given "^I open file \"\\(.+\\)\"$"
  2. (lambda (filename)
  3. (setq default-directory clj-refactor-root-path)
  4. (find-file filename)))
  5. (Given "^I have a project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
  6. (lambda (project-name dir-name)
  7. (setq default-directory clj-refactor-root-path)
  8. ;; delete old directory
  9. (when (file-exists-p dir-name)
  10. (delete-directory dir-name t))
  11. ;; create directory structure
  12. (mkdir (expand-file-name project-name (expand-file-name "src" dir-name)) t)
  13. (mkdir (expand-file-name project-name (expand-file-name "test" dir-name)) t)
  14. ;; add project.clj
  15. (with-temp-file (expand-file-name "project.clj" dir-name)
  16. (insert "(defproject " project-name " \"0.1.0-SNAPSHOT\")"))))
  17. (Given "^I have a clojure-file \"\\([^\"]+\\)\"$"
  18. (lambda (file-name)
  19. (setq default-directory clj-refactor-root-path)
  20. (find-file file-name)
  21. (save-buffer)
  22. (kill-buffer)))
  23. (Given "^I switch project-clean-prompt off$"
  24. (lambda ()
  25. (setq cljr-project-clean-prompt nil)))
  26. (Given "^I switch auto-sort off$"
  27. (lambda ()
  28. (setq cljr-auto-sort-ns nil)))
  29. (Given "^I switch auto-sort on$"
  30. (lambda ()
  31. (setq cljr-auto-sort-ns t)))
  32. (Given "^I set sort comparator to string length$"
  33. (lambda ()
  34. (setq cljr-sort-comparator 'cljr--string-length-comparator)))
  35. (Given "^I set sort comparator to semantic$"
  36. (lambda ()
  37. (setq cljr-sort-comparator 'cljr--semantic-comparator)))
  38. (Given "^I set sort comparator to string natural$"
  39. (lambda ()
  40. (setq cljr-sort-comparator 'cljr--string-natural-comparator)))
  41. (Given "^I exit multiple-cursors-mode"
  42. (lambda ()
  43. (multiple-cursors-mode 0)))
  44. (Given "^I don't use multiple-cursors"
  45. (lambda ()
  46. (setq cljr-use-multiple-cursors nil)))
  47. (Given "^I call the rename callback directly with mock data for foo->baz"
  48. (lambda ()
  49. (cljr--rename-occurrences "example.two"
  50. '((:line-beg 3 :line-end 4 :col-beg 7 :col-end 9
  51. :name "foo"
  52. :file "tmp/src/example/two.clj"
  53. :match "")
  54. (:line-beg 5 :line-end 5 :col-beg 15
  55. :col-end 23 :name "foo"
  56. :file "tmp/src/example/one.clj"
  57. :match ""))
  58. "baz")))
  59. (Given "^I call the rename callback directly with mock data for star->asterisk"
  60. (lambda ()
  61. (cljr--rename-occurrences "example.two"
  62. '((:line-beg 6 :line-end 7 :col-beg 7
  63. :col-end 10 :name "star*"
  64. :file "tmp/src/example/two.clj"
  65. :match "")
  66. (:line-beg 8 :line-end 8 :col-beg 17
  67. :col-end 27 :name "star*"
  68. :file "tmp/src/example/one.clj"
  69. :match ""))
  70. "asterisk*")))
  71. (Given "^I call the add-missing-libspec callback directly with mock data to import"
  72. (lambda ()
  73. (cljr--add-missing-libspec "Date" '((java.util.Date :class)))))
  74. (Given "^I call the add-missing-libspec callback directly with mock data to refer split"
  75. (lambda ()
  76. (cljr--add-missing-libspec "split" '((clojure.string :ns)))))
  77. (Given "^I call the add-missing-libspec callback directly with mock data to alias clojure.string"
  78. (lambda ()
  79. (cljr--add-missing-libspec "str/split" '((clojure.string :ns)))))
  80. (Given "^I call the add-missing-libspec callback directly with mock data to require WebrequestHandler"
  81. (lambda ()
  82. (cljr--add-missing-libspec "WebrequestHandler" '((modular.ring.WebrequestHandler :type)))))
  83. (Then "^the file should be named \"\\([^\"]+\\)\"$"
  84. (lambda (file-name-postfix)
  85. (assert (s-ends-with? file-name-postfix (buffer-file-name)) nil "Expected %S to end with %S" (buffer-file-name) file-name-postfix)))
  86. (And "^the cursor is inside the first defn form$"
  87. (lambda ()
  88. (goto-char (point-min))
  89. (re-search-forward "defn")))
  90. (Given "^I call the add-stubs function directly with mock data from the middleware"
  91. (lambda ()
  92. (cljr--insert-function-stubs (edn-read "(
  93. {:parameter-list \"[^int arg]\", :name \"remove\"}
  94. {:parameter-list \"[^int arg0 ^Object arg1]\", :name \"add\"}
  95. {:parameter-list \"[^java.util.function.UnaryOperator arg]\", :name \"replaceAll\"}
  96. {:parameter-list \"[^java.util.Collection arg]\", :name \"containsAll\"}
  97. {:parameter-list \"[^java.util.Collection arg]\", :name \"removeAll\"}
  98. {:parameter-list \"[]\", :name \"listIterator\"}
  99. {:parameter-list \"[^int arg0 ^int arg1]\", :name \"subList\"}
  100. {:parameter-list \"[]\", :name \"iterator\"}
  101. {:parameter-list \"[^Object arg]\", :name \"lastIndexOf\"}
  102. {:parameter-list \"[^int arg]\", :name \"listIterator\"}
  103. {:parameter-list \"[^int arg0 ^java.util.Collection arg1]\", :name \"addAll\"}
  104. {:parameter-list \"[^Object arg]\", :name \"add\"}
  105. {:parameter-list \"[^int arg]\", :name \"get\"}
  106. {:parameter-list \"[]\", :name \"toArray\"}
  107. {:parameter-list \"[]\", :name \"clear\"}
  108. {:parameter-list \"[^int arg0 ^Object arg1]\", :name \"set\"}
  109. {:parameter-list \"[^java.util.Collection arg]\", :name \"retainAll\"}
  110. {:parameter-list \"[]\", :name \"isEmpty\"}
  111. {:parameter-list \"[^java.util.Collection arg]\", :name \"addAll\"}
  112. {:parameter-list \"[]\", :name \"spliterator\"}
  113. {:parameter-list \"[^Object arg]\", :name \"indexOf\"}
  114. {:parameter-list \"[^Object... arg]\", :name \"toArray\"}
  115. {:parameter-list \"[^java.util.Comparator arg]\", :name \"sort\"}
  116. {:parameter-list \"[]\", :name \"size\"}
  117. {:parameter-list \"[^Object arg]\", :name \"equals\"}
  118. {:parameter-list \"[^Object arg]\", :name \"remove\"}
  119. {:parameter-list \"[]\", :name \"hashCode\"}
  120. {:parameter-list \"[^Object arg]\", :name \"contains\"})"))))
  121. (Given "I call the cljr--inline-symbol function directly with mockdata to inline my-constant"
  122. (lambda ()
  123. (let ((response (edn-read "{:occurrences ({:match \"(println my-constant my-constant another-val)))\"
  124. :file \"core.clj\"
  125. :name \"refactor-nrepl.test/my-constant\"
  126. :col-end 26
  127. :col-beg 14
  128. :line-end 5
  129. :line-beg 5} {:match \"(println my-constant my-constant another-val)))\"
  130. :file \"core.clj\"
  131. :name \"refactor-nrepl.test/my-constant\"
  132. :col-end 38
  133. :col-beg 26
  134. :line-end 5
  135. :line-beg 5})
  136. :definition {:line-beg 1
  137. :line-end 1
  138. :col-beg 1
  139. :col-end 22
  140. :name \"refactor-nrepl.test/my-constant\"
  141. :file \"core.clj\"
  142. :match \"(def my-constant 123)\"
  143. :definition \"123\"}}")))
  144. (cljr--inline-symbol "fake-ns" (gethash :definition response)
  145. (gethash :occurrences response)))))
  146. (Given "I call the cljr--inline-symbol function directly with mockdata to inline another-val"
  147. (lambda ()
  148. (let ((response (edn-read "{:definition {:line-beg 4
  149. :line-end 4
  150. :col-beg 9
  151. :col-end 21
  152. :name \"another-val\"
  153. :file \"core.clj\"
  154. :match \"(let [another-val 321]\"
  155. :definition \"321\"}
  156. :occurrences ({:match \"(println my-constant my-constant another-val)))\"
  157. :file \"core.clj\"
  158. :name \"another-val\"
  159. :col-end 50
  160. :col-beg 38
  161. :line-end 5
  162. :line-beg 5})}")))
  163. (cljr--inline-symbol "fake-ns" (gethash :definition response)
  164. (gethash :occurrences response)))))
  165. (Given "I call the cljr--inline-symbol function directly with mockdata to inline some-val"
  166. (lambda ()
  167. (let ((response (edn-read "{:definition {:line-beg 5
  168. :line-end 5
  169. :col-beg 9
  170. :col-end 17
  171. :name \"some-val\"
  172. :file \"core.clj\"
  173. :match \"some-val 110]\"
  174. :definition \"110\"}
  175. :occurrences ()}")))
  176. (cljr--inline-symbol "fake-ns" (gethash :definition response)
  177. (gethash :occurrences response)))))
  178. (Given "I call the cljr--inline-symbol function directly with mockdata to inline my-inc"
  179. (lambda ()
  180. (let ((response (edn-read "{:definition {:definition \"(fn [n]\\n (+ 1 n))\"
  181. :line-beg 1
  182. :line-end 2
  183. :col-beg 1
  184. :col-end 11
  185. :name \"refactor-nrepl.foo/my-inc\"
  186. :file \"core.clj\"
  187. :match \"(defn my-inc [n]\\n (+ 1 n))\"}
  188. :occurrences ({:line-beg 4
  189. :line-end 4
  190. :col-beg 5
  191. :col-end 12
  192. :name \"refactor-nrepl.foo/my-inc\"
  193. :file \"core.clj\"
  194. :match \"(+ (my-inc (- 17 4) 55))\"} {:line-beg 6
  195. :line-end 6
  196. :col-beg 6
  197. :col-end 13
  198. :name \"refactor-nrepl.foo/my-inc\"
  199. :file \"core.clj\"
  200. :match \"(map my-inc (range 10))\"})}")))
  201. (cljr--inline-symbol "fake-ns" (gethash :definition response)
  202. (gethash :occurrences response)))))