Skip to content

Commit

Permalink
Rename the package insert-docstring as python-insert-docstring
Browse files Browse the repository at this point in the history
This commit fixes one issue discussed in melpa/melpa#7768.
  • Loading branch information
macurovc committed Nov 1, 2021
1 parent 8f1057f commit 0b5ce21
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 194 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ The text gets automatically *indented* and *split* on multiple lines.
### With [use-package](https://github.com/jwiegley/use-package) and [quelpa](https://github.com/quelpa/quelpa)

```elisp
(use-package insert-docstring
(use-package python-insert-docstring
:ensure nil
:quelpa (insert-docstring
:quelpa (python-insert-docstring
:fetcher github
:repo "macurovc/insert-docstring"))
```

### Manually

Place [insert-docstring.el](insert-docstring.el) in your Emacs `load-path`. E.g.:
Place [python-insert-docstring.el](python-insert-docstring.el) in your Emacs `load-path`. E.g.:

```elisp
(add-to-list 'load-path (expand-file-name "~/{path/to}/insert-docstring"))
(require 'insert-docstring)
(require 'python-insert-docstring)
```

## Usage
Expand All @@ -52,7 +52,7 @@ Set in the `~/.emacs` file a keybinding such as:

```elisp
(defun set-python-keybindings ()
(local-set-key (kbd "C-c i") 'insert-docstring-at-point-with-google-style)
(local-set-key (kbd "C-c i") 'python-insert-docstring-with-google-style-at-point)
)
(add-hook 'python-mode-hook 'set-python-keybindings)
```
Expand All @@ -63,12 +63,12 @@ the instructions.
## Contributing

Any contribution is welcome. The file
[insert-docstring-tests.el](insert-docstring-tests.el) contains tests for the
[python-insert-docstring-tests.el](python-insert-docstring-tests.el) contains tests for the
functions that don't require user inputs and don't modify a buffer. The tests
can be run with the following command:

```bash
emacs -batch -l insert-docstring.el -l insert-docstring-tests.el -f ert-run-tests-batch-and-exit
emacs -batch -l python-insert-docstring.el -l python-insert-docstring-tests.el -f ert-run-tests-batch-and-exit
```

Each contribution must respect the following requirements:
Expand Down
122 changes: 61 additions & 61 deletions insert-docstring-tests.el → python-insert-docstring-tests.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; insert-docstring-tests.el --- Tests for the Python Google docstring inserter -*- lexical-binding: t; -*-
;;; python-insert-docstring-tests.el --- Tests for the Python Google docstring inserter -*- lexical-binding: t; -*-

;; Copyright (c) 2021 Marco Vocialta

Expand All @@ -24,120 +24,120 @@

;;; Commentary:

;; This file contains tests for the functions in insert-docstring.el that don't
;; require user inputs and don't modify a buffer.
;; This file contains tests for the functions in python-insert-docstring.el that
;; don't require user inputs and don't modify a buffer.

;;; Code:

(defconst insert-docstring--fill-column 79)
(defconst python-insert-docstring--fill-column 79)

(ert-deftest python-python-function-name-test ()
"Match the name of a simple function."
(let ((string "def something()"))
(should (equal (string-match insert-docstring-python-function-name-regex string) 0))
(should (equal (string-match python-insert-docstring-function-name-regex string) 0))
(should (equal (match-string 1 string) "something"))))

(ert-deftest python-function-name-with-indent-test ()
"Match the name of a function with some indentation."
(let ((string "\n \t def something ("))
(should (equal (string-match insert-docstring-python-function-name-regex string) 6))
(should (equal (string-match python-insert-docstring-function-name-regex string) 6))
(should (equal (match-string 1 string) "something"))))

(ert-deftest python-function-name-with-underscores-test ()
"Match the name of a function with underscores."
(let ((string "\n \t def _something_else ("))
(should (equal (string-match insert-docstring-python-function-name-regex string) 6))
(should (equal (string-match python-insert-docstring-function-name-regex string) 6))
(should (equal (match-string 1 string) "_something_else"))))

(ert-deftest python-end-of-function-test ()
"Match the end of a function definition."
(should (equal (string-match insert-docstring-python-function-end-regex "):") 0))
(should (equal (string-match insert-docstring-python-function-end-regex ") -> None : ") 0)))
(should (equal (string-match python-insert-docstring-function-end-regex "):") 0))
(should (equal (string-match python-insert-docstring-function-end-regex ") -> None : ") 0)))

(ert-deftest python-end-of-function-with-newline-test ()
"Match the end of a function definition with a None return type and newlines."
(let ((string ") \n ->\n \n\nNone:\n"))
(should (equal (string-match insert-docstring-python-function-end-regex string) 0))))
(should (equal (string-match python-insert-docstring-function-end-regex string) 0))))

(ert-deftest python-end-of-function-with-type-test ()
"Match the end of a function definition with an elaborate return type."
(let ((string " ) \n ->\n \n\nMap[int, int]:\n"))
(should (equal (string-match insert-docstring-python-function-end-regex string) 2))))
(should (equal (string-match python-insert-docstring-function-end-regex string) 2))))

(ert-deftest python-argument-string-regex-test ()
"Match the arguments string."
(let ((string "def toto_blabla(hey1):"))
(should (equal (string-match insert-docstring-python-function-arguments-regex string) 15))
(should (equal (string-match python-insert-docstring-function-arguments-regex string) 15))
(should (equal (match-string 1 string) "hey1"))))

(ert-deftest python-argument-string-regex-test ()
"Match the arguments string."
(let ((string "\ndef\n\ntoto( bubu : List[str] , lala ) -> \n\nNone : "))
(should (equal (string-match insert-docstring-python-function-arguments-regex string) 10))
(should (equal (string-match python-insert-docstring-function-arguments-regex string) 10))
(should (equal (match-string 1 string) " bubu : List[str] , lala "))))

(ert-deftest python-argument-string-regex-with-newlines-test ()
"Match the arguments string."
(let ((string "\ndef\n\ntoto( bubu : List[str] ,\n lala ) -> \n\nNone : "))
(should (equal (string-match insert-docstring-python-function-arguments-regex string) 10))
(should (equal (string-match python-insert-docstring-function-arguments-regex string) 10))
(should (equal (match-string 1 string) " bubu : List[str] ,\n lala "))))

(ert-deftest python-function-indentation-test ()
"Match the arguments string."
(let ((string "\ndef\n\ntoto() -> \n\nNone : "))
(should (equal (string-match insert-docstring-python-function-indentation-regex string) 1))
(should (equal (string-match python-insert-docstring-function-indentation-regex string) 1))
(should (equal (match-string 1 string) ""))))

(ert-deftest python-function-indentation-with-tabs-and-spaces-test ()
"Match the arguments string."
(let ((string "\n \t def\n\ntoto() -> \n\nNone : "))
(should (equal (string-match insert-docstring-python-function-indentation-regex string) 1))
(should (equal (string-match python-insert-docstring-function-indentation-regex string) 1))
(should (equal (match-string 1 string) " \t "))))

(ert-deftest python-parse-argument-list-test ()
"Test the arguments list parser function."
(progn
(should (equal (insert-docstring--get-python-arguments-names-from-string "") nil))
(should (equal (insert-docstring--get-python-arguments-names-from-string
(should (equal (python-insert-docstring--get-arguments-names-from-string "") nil))
(should (equal (python-insert-docstring--get-arguments-names-from-string
"one") '("one")))
(should (equal (insert-docstring--get-python-arguments-names-from-string
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first, second, third ") '("first" "second" "third")))
(should (equal (insert-docstring--get-python-arguments-names-from-string
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first: Type, second: Map[some, other], third : Dict[str, List[str]] ")
'("first" "second" "third")))
(should (equal (insert-docstring--get-python-arguments-names-from-string
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first: Type\n,\n second:\n Map[some, other]") '("first" "second")))
(should (equal (insert-docstring--get-python-arguments-names-from-string
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first: Type = 1,\n second: Map[some, other] = 2") '("first" "second")))
(should (equal (insert-docstring--get-python-arguments-names-from-string
(should (equal (python-insert-docstring--get-arguments-names-from-string
" first = 1,\n second = 2") '("first" "second")))))

(ert-deftest prefix-lines-test ()
"Test the function to prefix lines with blanks."
(should (equal (insert-docstring--prefix-lines '("some" "lines") " ") '(" some" " lines")))
(should (equal (insert-docstring--prefix-lines '("some" "") " ") '(" some" ""))))
(should (equal (python-insert-docstring--prefix-lines '("some" "lines") " ") '(" some" " lines")))
(should (equal (python-insert-docstring--prefix-lines '("some" "") " ") '(" some" ""))))

(ert-deftest python-google-docstring-arguments-test ()
"Test the generation of the argument list in the docstring."
(should (equal (insert-docstring--python-google-docstring-arguments () "") nil))
(let ((arguments (list (make-insert-docstring--argument-data :name "one" :description "this one")
(make-insert-docstring--argument-data :name "two" :description "this two"))))
(should (equal (insert-docstring--python-google-docstring-arguments arguments "pre")
(should (equal (python-insert-docstring--google-docstring-arguments () "") nil))
(let ((arguments (list (make-python-insert-docstring--argument-data :name "one" :description "this one")
(make-python-insert-docstring--argument-data :name "two" :description "this two"))))
(should (equal (python-insert-docstring--google-docstring-arguments arguments "pre")
'("" "preArgs:" "pre one: this one" "pre two: this two")))))

(ert-deftest python-google-docstring-returns-test ()
"Test the generation of the return statement in the docstring."
(should (equal (insert-docstring--python-google-docstring-returns nil "") nil))
(should (equal (insert-docstring--python-google-docstring-returns "something" "")
(should (equal (python-insert-docstring--google-docstring-returns nil "") nil))
(should (equal (python-insert-docstring--google-docstring-returns "something" "")
'("" "Returns:" " something")))
(should (equal (insert-docstring--python-google-docstring-returns "something" " ")
(should (equal (python-insert-docstring--google-docstring-returns "something" " ")
'("" " Returns:" " something"))))

(ert-deftest python-google-docstring-title-only ()
"Test the generation of the entire docstring."
(should (equal
(insert-docstring--python-google-docstring
(make-insert-docstring--function-data
(python-insert-docstring--google-docstring
(make-python-insert-docstring--function-data
:indentation-string ""
:short-description "title"
:long-description nil
Expand All @@ -150,8 +150,8 @@
(ert-deftest python-google-docstring-title-and-return ()
"Test the generation of the entire docstring."
(should (equal
(insert-docstring--python-google-docstring
(make-insert-docstring--function-data
(python-insert-docstring--google-docstring
(make-python-insert-docstring--function-data
:indentation-string ""
:short-description "title"
:long-description nil
Expand All @@ -167,13 +167,13 @@
(ert-deftest python-google-docstring-title-args-and-return ()
"Test the generation of the entire docstring."
(should (equal
(insert-docstring--python-google-docstring
(make-insert-docstring--function-data
(python-insert-docstring--google-docstring
(make-python-insert-docstring--function-data
:indentation-string ""
:short-description "title"
:long-description nil
:arguments (list (make-insert-docstring--argument-data :name "one" :description "this one")
(make-insert-docstring--argument-data :name "two" :description "this two"))
:arguments (list (make-python-insert-docstring--argument-data :name "one" :description "this one")
(make-python-insert-docstring--argument-data :name "two" :description "this two"))
:return "something"))
'(" \"\"\"title"
""
Expand All @@ -189,13 +189,13 @@
(ert-deftest python-google-docstring-title-and-args ()
"Test the generation of the entire docstring."
(should (equal
(insert-docstring--python-google-docstring
(make-insert-docstring--function-data
(python-insert-docstring--google-docstring
(make-python-insert-docstring--function-data
:indentation-string ""
:short-description "title"
:long-description nil
:arguments (list (make-insert-docstring--argument-data :name "one" :description "this one")
(make-insert-docstring--argument-data :name "two" :description "this two"))
:arguments (list (make-python-insert-docstring--argument-data :name "one" :description "this one")
(make-python-insert-docstring--argument-data :name "two" :description "this two"))
:return nil))
'(" \"\"\"title"
""
Expand All @@ -208,15 +208,15 @@
(ert-deftest python-google-docstring-all-fields ()
"Test the generation of the entire docstring."
(should (equal
(insert-docstring--python-google-docstring
(make-insert-docstring--function-data
(python-insert-docstring--google-docstring
(make-python-insert-docstring--function-data
:indentation-string " "
:short-description "this is a very very very very very very very very very very very very long title"
:long-description "this is a very very very very very very very very very very very very long description"
:arguments (list (make-insert-docstring--argument-data
:arguments (list (make-python-insert-docstring--argument-data
:name "one"
:description "this one is very very very very very very very very very very long")
(make-insert-docstring--argument-data :name "two" :description "this two"))
(make-python-insert-docstring--argument-data :name "two" :description "this two"))
:return "what a very very very very very very very very very very very very long return"))
'(" \"\"\"this is a very very very very very very very very very very very"
" very long title"
Expand All @@ -238,34 +238,34 @@

(ert-deftest indentation-length ()
"Test the computation of the indentation length."
(should (equal (insert-docstring--indentation-length "") 0))
(should (equal (insert-docstring--indentation-length " ") 1))
(should (equal (insert-docstring--indentation-length " ") 3))
(should (equal (insert-docstring--indentation-length " \t " 2) 5))
(should (equal (insert-docstring--indentation-length " \t \t " 3) 11)))
(should (equal (python-insert-docstring--indentation-length "") 0))
(should (equal (python-insert-docstring--indentation-length " ") 1))
(should (equal (python-insert-docstring--indentation-length " ") 3))
(should (equal (python-insert-docstring--indentation-length " \t " 2) 5))
(should (equal (python-insert-docstring--indentation-length " \t \t " 3) 11)))


(ert-deftest append-words-to-paragraph ()
"Test the function to append words to a paragraph."
(should (equal (insert-docstring--append-words-to-paragraph () 5 '("one" "two" "three"))
(should (equal (python-insert-docstring--append-words-to-paragraph () 5 '("one" "two" "three"))
'("one" "two" "three")))
(should (equal (insert-docstring--append-words-to-paragraph () 7 '("one" "two" "three"))
(should (equal (python-insert-docstring--append-words-to-paragraph () 7 '("one" "two" "three"))
'("one two" "three")))
(should (equal (insert-docstring--append-words-to-paragraph () 13 '("one" "two" "three"))
(should (equal (python-insert-docstring--append-words-to-paragraph () 13 '("one" "two" "three"))
'("one two three")))
(should (equal (insert-docstring--append-words-to-paragraph '("one") 7 '("two" "three"))
(should (equal (python-insert-docstring--append-words-to-paragraph '("one") 7 '("two" "three"))
'("one two" "three")))
(should (equal (insert-docstring--append-words-to-paragraph '("one") 7 '("two" "three") " ")
(should (equal (python-insert-docstring--append-words-to-paragraph '("one") 7 '("two" "three") " ")
'("one two" " three")))
(should (equal (insert-docstring--append-words-to-paragraph () 7 '("two" "three") " ")
(should (equal (python-insert-docstring--append-words-to-paragraph () 7 '("two" "three") " ")
'("two" " three"))))


(ert-deftest line-to-indented-paragraph ()
"Test splitting a line into a paragraph."
(should (equal (insert-docstring--line-to-indented-paragraph "this is a line" " " " " 9)
(should (equal (python-insert-docstring--line-to-indented-paragraph "this is a line" " " " " 9)
'(" this is" " a line"))))

;; End:

;;; insert-docstring-tests.el ends here
;;; python-insert-docstring-tests.el ends here
Loading

0 comments on commit 0b5ce21

Please sign in to comment.