zkry / yaml-pro

Edit YAML in Emacs like a pro
GNU General Public License v3.0
137 stars 9 forks source link

add tests for yaml-pro-ts-* functions #28

Closed rodrigomorales1 closed 11 months ago

rodrigomorales1 commented 12 months ago

The introduced tests can be run by executing the following command in the root directory of the project.

emacs -batch \ -l ert \ -l yaml-pro-edit.el \ -l yaml-pro.el \ -l tests/yaml-pro-ts.el \ -f ert-run-tests-batch-and-exit

NOTE: In the future, I'm planning to add more tests. First, I've written these simple tests so @zkry (creator of this project) can confirm that this is correct behavior. Then, I'll write more complex tests.

Here's proof that these tests run successfully:

$ emacs -batch -l ert -l yaml-pro-edit.el -l yaml-pro.el -l tests/yaml-pro-ts.el -f ert-run-tests-batch-and-exit
Running 8 tests (2023-09-19 14:51:46-0500, selector ‘t’)
   passed  1/8  test-yaml-pro-ts-indent-subtree (0.004941 sec)
   passed  2/8  test-yaml-pro-ts-mark-subtree (0.000253 sec)
   passed  3/8  test-yaml-pro-ts-meta-return (0.000199 sec)
   passed  4/8  test-yaml-pro-ts-move-subtree-down (0.000263 sec)
   passed  5/8  test-yaml-pro-ts-move-subtree-up (0.000244 sec)
   passed  6/8  test-yaml-pro-ts-next-subtree (0.004427 sec)
   passed  7/8  test-yaml-pro-ts-prev-subtree (0.000256 sec)
   passed  8/8  test-yaml-pro-ts-unindent-subtree (0.000252 sec)

Ran 8 tests, 8 results as expected, 0 unexpected (2023-09-19 14:51:46-0500, 0.011128 sec)
rodrigomorales1 commented 11 months ago

UPDATE: Refer to https://github.com/zkry/yaml-pro/pull/28#issuecomment-1727059015

rodrigomorales1 commented 11 months ago

UPDATE: Refer to https://github.com/zkry/yaml-pro/pull/28#issuecomment-1727059015

rodrigomorales1 commented 11 months ago

In the last two commits 17be0a1 and 52514bd. I've introduced changes to modify behavior in yaml-pro-ts-meta-return in some scenarios. Please see minimal working examples below. The examples are the same from those of the introduced tests.

  1. test-yaml-pro-ts-meta-return
  2. test-yaml-pro-ts-meta-return-trailing-newline
  3. test-yaml-pro-ts-meta-return-trailing-newline-list

test-yaml-pro-ts-meta-return

(yaml-test-with-temp-text "- 1: one<point>\n"
  (yaml-pro-ts-meta-return)
  (buffer-substring-no-properties (point-min) (point-max)))

Version from master branch

"- 1: one

- "

Version from this commit

"- 1: one
- 
"

test-yaml-pro-ts-meta-return-trailing-newline

(yaml-test-with-temp-text "- 1: one<point>"
  (yaml-pro-ts-meta-return)
  (buffer-substring-no-properties
   (point-min)
   (point-max)))

Both versions produce the same result

"- 1: one
- "

test-yaml-pro-ts-meta-return-trailing-newline-list

test 1

(yaml-test-with-temp-text (concat
                           "- 1:\n"
                           "- 2:\n"
                           "- 3:<point>\n")
  (yaml-pro-ts-meta-return)
  (buffer-substring-no-properties
   (point-min)
   (point-max)))

Version from master branch

"- 1:
- 2:
- 3:

- "

Version from this commit

"- 1:
- 2:
- 3:
- 
"

test 2

(yaml-test-with-temp-text (concat
                           "- 1:\n"
                           "  1.1:\n"
                           "- 2:\n"
                           "  2.1:\n"
                           "- 3:<point>\n"
                           "  3.1:\n")
  (yaml-pro-ts-meta-return)
  (buffer-substring-no-properties (point-min) (point-max)))

Version from master branch

"- 1:
  1.1:
- 2:
  2.1:
- 3:
  3.1:

- "

Version from this commit

"- 1:
  1.1:
- 2:
  2.1:
- 3:
  3.1:
- 
"
rodrigomorales1 commented 11 months ago

In the latest commit 7f2b344, I've introduced changes to yaml-pro-ts-move-subtree to improve its behavior when the file has a trailing newline at the end. I also added some tests. Please see minimal working examples below (the examples are the same from those of the tests).

  1. test-yaml-pro-ts-move-subtree-down-point-beginning-of-line
  2. test-yaml-pro-ts-move-subtree-down-point-end-of-line
  3. test-yaml-pro-ts-move-subtree-down-no-trailing-newline
  4. test-yaml-pro-ts-move-subtree-down-trailing-newline

test-yaml-pro-ts-move-subtree-down-point-beginning-of-line

(yaml-test-with-temp-text (concat
                           "<point>1:\n"
                           "  1.1: null\n"
                           "2:\n"
                           "  2.1: null\n"
                           "3:\n"
                           "  3.1: null\n")
  (yaml-pro-ts-move-subtree-down)
  (buffer-substring-no-properties
   (point-min)
   (point-max)))

Both versions produce the same result

"2:
  2.1: null
1:
  1.1: null
3:
  3.1: null
"

test-yaml-pro-ts-move-subtree-down-point-end-of-line

(yaml-test-with-temp-text (concat
                           "1:<point>\n"
                           "  1.1: null\n"
                           "2:\n"
                           "  2.1: null\n"
                           "3:\n"
                           "  3.1: null\n")
  (yaml-pro-ts-move-subtree-down)
  (buffer-substring-no-properties
   (point-min)
   (point-max)))

Both versions produce the same result

"2:
  2.1: null
1:
  1.1: null
3:
  3.1: null
"

test-yaml-pro-ts-move-subtree-down-no-trailing-newline

(yaml-test-with-temp-text (concat
                           "1:\n"
                           "  1.1: null\n"
                           "2:<point>\n"
                           "  2.1: null\n"
                           "3:\n"
                           "  3.1: null")
  (yaml-pro-ts-move-subtree-down)
  (buffer-substring-no-properties (point-min) (point-max)))

Both versions produce the same result

"1:
  1.1: null
3:
  3.1: null
2:
  2.1: null"

test-yaml-pro-ts-move-subtree-down-trailing-newline

(yaml-test-with-temp-text (concat
                           "1:\n"
                           "  1.1: null\n"
                           "2:<point>\n"
                           "  2.1: null\n"
                           "3:\n"
                           "  3.1: null\n"
                           "\n"
                           "\n"
                           "\n")
  (yaml-pro-ts-move-subtree-down)
  (buffer-substring-no-properties (point-min) (point-max)))

Version from master branch

"1:
  1.1: null
3:
  3.1: null

2:
  2.1: null"

Version from this commit

"1:
  1.1: null
3:
  3.1: null

2:
  2.1: null
"
zkry commented 11 months ago

Thanks for this contribution. This is great!