Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore empty line before element #30

Merged
merged 9 commits into from
Mar 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cask/
10 changes: 10 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(source gnu)
(source melpa)

(package-file "./yafolding.el")

(development
(depends-on "f")
(depends-on "ecukes")
(depends-on "ert-runner")
(depends-on "el-mock"))
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
## Debug

- [Using Edebug](https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Edebug.html#Using-Edebug)

## Testing

For testing, use [ecukes][https://github.com/ecukes/ecukes], installed
by [Cask](https://github.com/cask/cask). The tests are in the
[features](./features/) subdirectory, test data is in the
[data](./test/data) dir. Running tests can be done by issueing `cask
exec ecukes --[no-]win`.
33 changes: 33 additions & 0 deletions features/step-definitions/yafolding-steps.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;; This file contains your project specific step definitions. All
;; files in this directory whose names end with "-steps.el" will be
;; loaded automatically by Ecukes.

(Given "^I have an empty buffer$"
(lambda () (erase-buffer)))

(When "^I call yafolding-hide-all$"
(lambda () (yafolding-hide-all)))

(Then "^I should have an empty buffer$"
(lambda () (should (= (point-min) (point-max) 1))))

(Given "^I have a buffer with \"\\([^\"]+\\)\"$"
(lambda (filename)
(erase-buffer)
(insert-file-contents filename)))

(And "^I \\(?:am on\\|go to\\) line \\([0-9]+\\)$"
(lambda (line) (goto-line (string-to-number line))))

(And "^I call yafolding-hide-element$"
(lambda () (yafolding-hide-element)))

(Then "^I should see \\(?:only \\)?\\([0-9]+\\) lines?$"
(lambda (num-lines)
(save-excursion
(beginning-of-buffer)
(next-line (string-to-number num-lines))
(should (= (line-number-at-pos (point))
(line-number-at-pos (point-max)))))))

;; End of steps file
32 changes: 32 additions & 0 deletions features/support/env.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(require 'f)

(defvar yafolding-support-path
(f-dirname load-file-name))

(defvar yafolding-features-path
(f-parent yafolding-support-path))

(defvar yafolding-root-path
(f-parent yafolding-features-path))

(add-to-list 'load-path yafolding-root-path)

(require 'yafolding)
(require 'espuds)
(require 'ert)

(Setup
;; Before anything has run
)

(Before
;; Before each scenario is run
)

(After
;; After each scenario is run
)

(Teardown
;; After when everything has been run
)
23 changes: 23 additions & 0 deletions features/yafolding.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Fold all lines
In order to be able to visualize the outline of my file
As a user
I want to be able to fold all elements at once

Scenario: Empty buffers are not changed
Given I have an empty buffer
When I call yafolding-hide-all
Then I should have an empty buffer

Scenario: Test file from issue #23 should collapse correctly
Given I have a buffer with "test/data/issue-23.txt"
And I am on line 2
When I call yafolding-hide-all
And I go to line 1
And I call yafolding-hide-element
Then I should see only 1 line

Scenario: Elements after empty lines should collapse correctly
Given I have a buffer with "test/data/issue-29.txt"
And I am on line 3
When I call yafolding-hide-all
Then I should see 5 lines
File renamed without changes.
10 changes: 10 additions & 0 deletions test/data/issue-29.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Level 0

* Level 1
* Level 2
* Level 2
* Level 2

* Level 1 again
* Level 2
* Level 2
3 changes: 2 additions & 1 deletion yafolding.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
(goto-char (point-min))
(while (< (line-number-at-pos)
(line-number-at-pos (point-max)))
(if (= (yafolding-get-indent-level) indent-level)
(if (and (= (yafolding-get-indent-level) indent-level)
(not (yafolding-should-ignore-current-line-p)))
(yafolding-hide-element))
(forward-line 1))))

Expand Down