diff --git a/test/test-refile/Makefile b/test/test-refile/Makefile new file mode 100644 index 0000000..07a4101 --- /dev/null +++ b/test/test-refile/Makefile @@ -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 diff --git a/test/test-refile/test-bad-input.vim b/test/test-refile/test-bad-input.vim new file mode 100644 index 0000000..44f82ce --- /dev/null +++ b/test/test-refile/test-bad-input.vim @@ -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() diff --git a/test/test-refile/test-samefile.vim b/test/test-refile/test-samefile.vim new file mode 100644 index 0000000..f479823 --- /dev/null +++ b/test/test-refile/test-samefile.vim @@ -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() diff --git a/test/test-refile/test-targetA-subsec.vim b/test/test-refile/test-targetA-subsec.vim new file mode 100644 index 0000000..4650843 --- /dev/null +++ b/test/test-refile/test-targetA-subsec.vim @@ -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() diff --git a/test/test-refile/test-targetA.vim b/test/test-refile/test-targetA.vim new file mode 100644 index 0000000..5c8307b --- /dev/null +++ b/test/test-refile/test-targetA.vim @@ -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() diff --git a/test/test-refile/wiki/index.ref b/test/test-refile/wiki/index.ref new file mode 100644 index 0000000..27431b6 --- /dev/null +++ b/test/test-refile/wiki/index.ref @@ -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. + diff --git a/test/test-refile/wiki/index.ref2 b/test/test-refile/wiki/index.ref2 new file mode 100644 index 0000000..501e9e0 --- /dev/null +++ b/test/test-refile/wiki/index.ref2 @@ -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 + diff --git a/test/test-refile/wiki/index.wiki b/test/test-refile/wiki/index.wiki new file mode 100644 index 0000000..fdaa3fd --- /dev/null +++ b/test/test-refile/wiki/index.wiki @@ -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 + diff --git a/test/test-refile/wiki/links.wiki b/test/test-refile/wiki/links.wiki new file mode 100644 index 0000000..1a55ff1 --- /dev/null +++ b/test/test-refile/wiki/links.wiki @@ -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]] diff --git a/test/test-refile/wiki/sourceSameFile.ref b/test/test-refile/wiki/sourceSameFile.ref new file mode 100644 index 0000000..78ad988 --- /dev/null +++ b/test/test-refile/wiki/sourceSameFile.ref @@ -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. + diff --git a/test/test-refile/wiki/sourceSameFile.wiki b/test/test-refile/wiki/sourceSameFile.wiki new file mode 100644 index 0000000..b193024 --- /dev/null +++ b/test/test-refile/wiki/sourceSameFile.wiki @@ -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. + diff --git a/test/test-refile/wiki/targetA.ref b/test/test-refile/wiki/targetA.ref new file mode 100644 index 0000000..931e84e --- /dev/null +++ b/test/test-refile/wiki/targetA.ref @@ -0,0 +1,15 @@ +# Section 1 + +## Foo bar Baz + +# Section 1 + +## Subsection A + +## Subsection B + +# Section 2 + +## Subsection A + +## Subsection B diff --git a/test/test-refile/wiki/targetA.ref2 b/test/test-refile/wiki/targetA.ref2 new file mode 100644 index 0000000..bd737d5 --- /dev/null +++ b/test/test-refile/wiki/targetA.ref2 @@ -0,0 +1,13 @@ +# Section 1 + +## Subsection A + +## Subsection B + +# Section 2 + +## Subsection A + +## Foo bar Baz + +## Subsection B diff --git a/test/test-refile/wiki/targetA.wiki b/test/test-refile/wiki/targetA.wiki new file mode 100644 index 0000000..2ef92b8 --- /dev/null +++ b/test/test-refile/wiki/targetA.wiki @@ -0,0 +1,11 @@ +# Section 1 + +## Subsection A + +## Subsection B + +# Section 2 + +## Subsection A + +## Subsection B