Skip to content

Commit 088c54c

Browse files
committed
test: added initial test specs for refile
1 parent 1c733d3 commit 088c54c

File tree

14 files changed

+253
-0
lines changed

14 files changed

+253
-0
lines changed

test/test-refile/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MYVIM ?= nvim --clean --headless
2+
export QUIT = 1
3+
4+
tests := $(wildcard test*.vim)
5+
6+
.PHONY: cleanup $(tests)
7+
8+
test: $(tests)
9+
10+
$(tests):
11+
@rm -rf wiki-tmp
12+
@cp -r wiki wiki-tmp
13+
@$(MYVIM) -u $@
14+
@rm -rf wiki-tmp
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
source ../init.vim
2+
runtime plugin/wiki.vim
3+
4+
let g:wiki_log_verbose = 0
5+
6+
silent edit wiki-tmp/index.wiki
7+
8+
" Refile something not within a section should return with error message
9+
normal 2G
10+
silent call wiki#page#refile(#{target_page: 'targetA'})
11+
let s:log = wiki#log#get()
12+
call assert_equal(1, len(s:log))
13+
call assert_equal('error', s:log[0].type)
14+
call assert_equal('No source section recognized!', s:log[0].msg[0])
15+
16+
" Refile to nonexisting target should return with error message
17+
normal! 13G
18+
silent call wiki#page#refile(#{target_page: 'targetDoesNotExist'})
19+
let s:log = wiki#log#get()
20+
call assert_equal(2, len(s:log))
21+
call assert_equal('error', s:log[1].type)
22+
call assert_equal('Target page was not found!', s:log[1].msg[0])
23+
24+
call wiki#test#finished()

test/test-refile/test-samefile.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
source ../init.vim
2+
runtime plugin/wiki.vim
3+
4+
" Refile Section 1 of index to targetA
5+
silent edit wiki-tmp/sourceSameFile.wiki
6+
normal! 10G
7+
silent call wiki#page#refile(#{target_lnum: 20})
8+
9+
" Check that content was properly removed from index and moved to targetA
10+
call assert_equal(
11+
\ readfile('wiki-tmp/sourceSameFile.ref'),
12+
\ readfile('wiki-tmp/sourceSameFile.wiki'))
13+
14+
" Check that all links to the previous location are updated
15+
call assert_equal(
16+
\ '[[sourceSameFile#Tasks#Bar#Subheading]]',
17+
\ readfile('wiki-tmp/links.wiki')[10])
18+
19+
call wiki#test#finished()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
source ../init.vim
2+
runtime plugin/wiki.vim
3+
4+
" Refile Section 1 of index to targetA
5+
silent edit wiki-tmp/index.wiki
6+
normal! 15G
7+
silent call wiki#page#refile(#{target_page: 'targetA', target_lnum: 10})
8+
9+
" Check that content was properly removed from index and moved to targetA
10+
call assert_equal(
11+
\ readfile('wiki-tmp/index.ref2'),
12+
\ readfile('wiki-tmp/index.wiki'))
13+
call assert_equal(
14+
\ readfile('wiki-tmp/targetA.ref2'),
15+
\ readfile('wiki-tmp/targetA.wiki'))
16+
17+
" Check that all links to the previous location are updated
18+
call assert_equal(
19+
\ '[[targetA#Section 2#Foo bar Baz]]',
20+
\ readfile('wiki-tmp/index.wiki')[7])
21+
call assert_equal(
22+
\ '[[targetA#Section 2#Foo bar Baz]]',
23+
\ readfile('wiki-tmp/links.wiki')[8])
24+
25+
call wiki#test#finished()

test/test-refile/test-targetA.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
source ../init.vim
2+
runtime plugin/wiki.vim
3+
4+
silent edit wiki-tmp/index.wiki
5+
normal! 13G
6+
silent call wiki#page#refile(#{target_page: 'targetA'})
7+
8+
" Check that content was properly moved from index to targetA
9+
call assert_equal(
10+
\ readfile('wiki-tmp/index.ref'),
11+
\ readfile('wiki-tmp/index.wiki'))
12+
call assert_equal(
13+
\ readfile('wiki-tmp/targetA.ref'),
14+
\ readfile('wiki-tmp/targetA.wiki'))
15+
16+
" Check that all links to the previous location are updated
17+
call assert_equal(
18+
\ '[[targetA#Section 1]]',
19+
\ readfile('wiki-tmp/index.wiki')[6])
20+
call assert_equal(
21+
\ '[[targetA#Section 1#Foo bar Baz]]',
22+
\ readfile('wiki-tmp/index.wiki')[7])
23+
call assert_equal(
24+
\ '[[targetA#Section 1]]',
25+
\ readfile('wiki-tmp/links.wiki')[7])
26+
call assert_equal(
27+
\ '[[targetA#Section 1#Foo bar Baz]]',
28+
\ readfile('wiki-tmp/links.wiki')[8])
29+
30+
call wiki#test#finished()

test/test-refile/wiki/index.ref

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Intro text here.
2+
3+
# Intro
4+
5+
This is a wiki.
6+
7+
[[targetA#Section 1]]
8+
[[targetA#Section 1#Foo bar Baz]]
9+
10+
This-is-a-wiki.
11+

test/test-refile/wiki/index.ref2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Intro text here.
2+
3+
# Intro
4+
5+
This is a wiki.
6+
7+
[[#Section 1]]
8+
[[targetA#Section 2#Foo bar Baz]]
9+
10+
This-is-a-wiki.
11+
12+
# Section 1
13+

test/test-refile/wiki/index.wiki

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Intro text here.
2+
3+
# Intro
4+
5+
This is a wiki.
6+
7+
[[#Section 1]]
8+
[[#Section 1#Foo bar Baz]]
9+
10+
This-is-a-wiki.
11+
12+
# Section 1
13+
14+
## Foo bar Baz
15+

test/test-refile/wiki/links.wiki

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Intro
2+
3+
This is a wiki.
4+
5+
[[BadName]]
6+
[[subdir/BadName]]
7+
8+
[[index#Section 1]]
9+
[[index#Section 1#Foo bar Baz]]
10+
11+
[[sourceSameFile#Inbox#Bar#Subheading]]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Inbox
2+
Link to: [[#Tasks#Bar]]
3+
## Foo
4+
5+
Random text here.
6+
7+
# Tasks
8+
9+
## Baz
10+
11+
Even more random text here.
12+
13+
## Bar
14+
15+
More random text here.
16+
17+
### Subheading
18+
19+
More here.
20+
21+
# Someday
22+
23+
## Qux
24+
25+
More text.
26+

0 commit comments

Comments
 (0)