Skip to content

Commit

Permalink
test: added initial test specs for refile
Browse files Browse the repository at this point in the history
  • Loading branch information
lervag committed Jul 20, 2023
1 parent 1c733d3 commit 088c54c
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/test-refile/Makefile
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
24 changes: 24 additions & 0 deletions test/test-refile/test-bad-input.vim
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()
19 changes: 19 additions & 0 deletions test/test-refile/test-samefile.vim
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()
25 changes: 25 additions & 0 deletions test/test-refile/test-targetA-subsec.vim
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()
30 changes: 30 additions & 0 deletions test/test-refile/test-targetA.vim
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()
11 changes: 11 additions & 0 deletions test/test-refile/wiki/index.ref
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.

13 changes: 13 additions & 0 deletions test/test-refile/wiki/index.ref2
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

15 changes: 15 additions & 0 deletions test/test-refile/wiki/index.wiki
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
11 changes: 11 additions & 0 deletions test/test-refile/wiki/links.wiki
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]]
26 changes: 26 additions & 0 deletions test/test-refile/wiki/sourceSameFile.ref
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.

26 changes: 26 additions & 0 deletions test/test-refile/wiki/sourceSameFile.wiki
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.

15 changes: 15 additions & 0 deletions test/test-refile/wiki/targetA.ref
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
13 changes: 13 additions & 0 deletions test/test-refile/wiki/targetA.ref2
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
11 changes: 11 additions & 0 deletions test/test-refile/wiki/targetA.wiki
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

0 comments on commit 088c54c

Please sign in to comment.