Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Fix bug with default parameters in c++-mock-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewscottgordon committed Sep 27, 2022
1 parent ebf15b0 commit 5e5b593
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions site-lisp/mg-c++-mock-interface.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@

(defun mg-remove-default-parameters ()
(if (save-excursion
(let ((found-default-parameter (re-search-forward "=" (mg-find-matching-bracket) t 1)))
(if found-default-parameter
(let ((begin (1- (point))))
(re-search-forward "[^[:blank:]]" nil nil 1)
(delete-region begin (point))))
found-default-parameter))
(mg-remove-default-parameters)))

(let ((matching-bracket (mg-find-matching-bracket)))
(let ((found-default-parameter (re-search-forward "=" matching-bracket t 1)))
(if found-default-parameter
(let ((begin (1- (point))))
(re-search-forward "[^[:blank:]]+" matching-bracket nil 1)
(delete-region begin (1- (point)))))
found-default-parameter)))
(mg-remove-default-parameters)))


(defun c++-mock-interface ()
"Convert in interface declaration into a GMock mock object declaration implementing the interface."
(interactive)
(save-excursion (while (re-search-forward "=[[:blank:]]*0[[:blank:]]*;" nil t 1)
(back-to-indentation)
(re-search-forward "virtual[[:blank:]]+" (mg-end-of-line) nil 1)
(backward-kill-word 1) ;Delete "virtual"
(insert "MOCK_METHOD(")
; Attempt to match return type
(re-search-forward "\\(const\\)?[[:blank:]]*[a-zA-Z_][a-zA-Z0-9_]*[*&]?" (mg-end-of-line) nil 1)
(insert ",")
; Match function name
(re-search-forward "[a-zA-Z_][a-zA-Z0-9_]*" (mg-end-of-line) nil 1)
(insert ", ")
; Find limits of function parameters
(mg-remove-default-parameters)
(forward-sexp)
(insert ",")
(re-search-forward "[[:blank:]]*" (mg-end-of-line) nil 1)
(insert "(")
(if (re-search-forward "const" (mg-end-of-line) t 1) (insert ", "))
(insert "override));")
(kill-line nil)
(next-line)))
(back-to-indentation)
(re-search-forward "virtual[[:blank:]]+" (mg-end-of-line) nil 1)
(backward-kill-word 1) ;Delete "virtual"
(insert "MOCK_METHOD(")
; Attempt to match return type
(re-search-forward "\\(const\\)?[[:blank:]]*[a-zA-Z_][a-zA-Z0-9_]*[*&]?" (mg-end-of-line) nil 1)
(insert ",")
; Match function name
(re-search-forward "[a-zA-Z_][a-zA-Z0-9_]*" (mg-end-of-line) nil 1)
(insert ", ")
; Find limits of function parameters
(mg-remove-default-parameters)
(forward-sexp)
(insert ",")
(re-search-forward "[[:blank:]]*" (mg-end-of-line) nil 1)
(insert "(")
(if (re-search-forward "const" (mg-end-of-line) t 1) (insert ", "))
(insert "override));")
(kill-line nil)
(next-line)))
(save-excursion (while (re-search-forward "^[[:blank:]]*\\(//.*\\)?[[:blank:]]*$" nil t 1)
(move-beginning-of-line nil)
(kill-whole-line nil))))
(move-beginning-of-line nil)
(kill-whole-line nil))))

0 comments on commit 5e5b593

Please sign in to comment.