-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added initial test specs for refile
- Loading branch information
Showing
14 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
MYVIM ?= nvim --clean --headless | ||
export QUIT = 1 | ||
|
||
tests := $(wildcard test*.vim) | ||
|
||
.PHONY: cleanup $(tests) | ||
|
||
test: $(tests) | ||
|
||
$(tests): | ||
@rm -rf wiki-tmp | ||
@cp -r wiki wiki-tmp | ||
@$(MYVIM) -u $@ | ||
@rm -rf wiki-tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
source ../init.vim | ||
runtime plugin/wiki.vim | ||
|
||
let g:wiki_log_verbose = 0 | ||
|
||
silent edit wiki-tmp/index.wiki | ||
|
||
" Refile something not within a section should return with error message | ||
normal 2G | ||
silent call wiki#page#refile(#{target_page: 'targetA'}) | ||
let s:log = wiki#log#get() | ||
call assert_equal(1, len(s:log)) | ||
call assert_equal('error', s:log[0].type) | ||
call assert_equal('No source section recognized!', s:log[0].msg[0]) | ||
|
||
" Refile to nonexisting target should return with error message | ||
normal! 13G | ||
silent call wiki#page#refile(#{target_page: 'targetDoesNotExist'}) | ||
let s:log = wiki#log#get() | ||
call assert_equal(2, len(s:log)) | ||
call assert_equal('error', s:log[1].type) | ||
call assert_equal('Target page was not found!', s:log[1].msg[0]) | ||
|
||
call wiki#test#finished() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
source ../init.vim | ||
runtime plugin/wiki.vim | ||
|
||
" Refile Section 1 of index to targetA | ||
silent edit wiki-tmp/sourceSameFile.wiki | ||
normal! 10G | ||
silent call wiki#page#refile(#{target_lnum: 20}) | ||
|
||
" Check that content was properly removed from index and moved to targetA | ||
call assert_equal( | ||
\ readfile('wiki-tmp/sourceSameFile.ref'), | ||
\ readfile('wiki-tmp/sourceSameFile.wiki')) | ||
|
||
" Check that all links to the previous location are updated | ||
call assert_equal( | ||
\ '[[sourceSameFile#Tasks#Bar#Subheading]]', | ||
\ readfile('wiki-tmp/links.wiki')[10]) | ||
|
||
call wiki#test#finished() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
source ../init.vim | ||
runtime plugin/wiki.vim | ||
|
||
" Refile Section 1 of index to targetA | ||
silent edit wiki-tmp/index.wiki | ||
normal! 15G | ||
silent call wiki#page#refile(#{target_page: 'targetA', target_lnum: 10}) | ||
|
||
" Check that content was properly removed from index and moved to targetA | ||
call assert_equal( | ||
\ readfile('wiki-tmp/index.ref2'), | ||
\ readfile('wiki-tmp/index.wiki')) | ||
call assert_equal( | ||
\ readfile('wiki-tmp/targetA.ref2'), | ||
\ readfile('wiki-tmp/targetA.wiki')) | ||
|
||
" Check that all links to the previous location are updated | ||
call assert_equal( | ||
\ '[[targetA#Section 2#Foo bar Baz]]', | ||
\ readfile('wiki-tmp/index.wiki')[7]) | ||
call assert_equal( | ||
\ '[[targetA#Section 2#Foo bar Baz]]', | ||
\ readfile('wiki-tmp/links.wiki')[8]) | ||
|
||
call wiki#test#finished() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
source ../init.vim | ||
runtime plugin/wiki.vim | ||
|
||
silent edit wiki-tmp/index.wiki | ||
normal! 13G | ||
silent call wiki#page#refile(#{target_page: 'targetA'}) | ||
|
||
" Check that content was properly moved from index to targetA | ||
call assert_equal( | ||
\ readfile('wiki-tmp/index.ref'), | ||
\ readfile('wiki-tmp/index.wiki')) | ||
call assert_equal( | ||
\ readfile('wiki-tmp/targetA.ref'), | ||
\ readfile('wiki-tmp/targetA.wiki')) | ||
|
||
" Check that all links to the previous location are updated | ||
call assert_equal( | ||
\ '[[targetA#Section 1]]', | ||
\ readfile('wiki-tmp/index.wiki')[6]) | ||
call assert_equal( | ||
\ '[[targetA#Section 1#Foo bar Baz]]', | ||
\ readfile('wiki-tmp/index.wiki')[7]) | ||
call assert_equal( | ||
\ '[[targetA#Section 1]]', | ||
\ readfile('wiki-tmp/links.wiki')[7]) | ||
call assert_equal( | ||
\ '[[targetA#Section 1#Foo bar Baz]]', | ||
\ readfile('wiki-tmp/links.wiki')[8]) | ||
|
||
call wiki#test#finished() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Intro text here. | ||
|
||
# Intro | ||
|
||
This is a wiki. | ||
|
||
[[targetA#Section 1]] | ||
[[targetA#Section 1#Foo bar Baz]] | ||
|
||
This-is-a-wiki. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Intro text here. | ||
|
||
# Intro | ||
|
||
This is a wiki. | ||
|
||
[[#Section 1]] | ||
[[targetA#Section 2#Foo bar Baz]] | ||
|
||
This-is-a-wiki. | ||
|
||
# Section 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Intro text here. | ||
|
||
# Intro | ||
This is a wiki. | ||
|
||
[[#Section 1]] | ||
[[#Section 1#Foo bar Baz]] | ||
|
||
This-is-a-wiki. | ||
|
||
# Section 1 | ||
## Foo bar Baz | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Intro | ||
This is a wiki. | ||
|
||
[[BadName]] | ||
[[subdir/BadName]] | ||
|
||
[[index#Section 1]] | ||
[[index#Section 1#Foo bar Baz]] | ||
|
||
[[sourceSameFile#Inbox#Bar#Subheading]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Inbox | ||
Link to: [[#Tasks#Bar]] | ||
## Foo | ||
|
||
Random text here. | ||
|
||
# Tasks | ||
|
||
## Baz | ||
|
||
Even more random text here. | ||
|
||
## Bar | ||
|
||
More random text here. | ||
|
||
### Subheading | ||
|
||
More here. | ||
|
||
# Someday | ||
|
||
## Qux | ||
|
||
More text. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Inbox | ||
Link to: [[#Inbox#Bar]] | ||
## Foo | ||
Random text here. | ||
|
||
## Bar | ||
More random text here. | ||
|
||
### Subheading | ||
More here. | ||
|
||
# Tasks | ||
## Baz | ||
Even more random text here. | ||
|
||
# Someday | ||
## Qux | ||
More text. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Section 1 | ||
|
||
## Foo bar Baz | ||
|
||
# Section 1 | ||
|
||
## Subsection A | ||
|
||
## Subsection B | ||
|
||
# Section 2 | ||
|
||
## Subsection A | ||
|
||
## Subsection B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Section 1 | ||
|
||
## Subsection A | ||
|
||
## Subsection B | ||
|
||
# Section 2 | ||
|
||
## Subsection A | ||
|
||
## Foo bar Baz | ||
|
||
## Subsection B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Section 1 | ||
## Subsection A | ||
## Subsection B | ||
# Section 2 | ||
## Subsection A | ||
## Subsection B |