-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
81 lines (77 loc) · 3.33 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { test } from 'tape'
import { remark } from 'remark'
import remarkGfm from 'remark-gfm'
import remarkBibtex from './index.js'
const bibtexFilePath = './example/example.bib'
test('Infer citation A', async (t) => {
return remark()
.use(remarkGfm)
.use(remarkBibtex, { bibtexFile: bibtexFilePath })
.process('(@Wasserman1994)')
.then((content) => {
return content.toString()
})
.then((markdown) => {
t.equal(
markdown,
'[^1]\n\n[^1]: 1\\. Wasserman S, Faust K. Social Network Analysis. Cambridge: Cambridge University Press; 1994. \n'
)
})
.catch((err) => console.error(err))
})
test('Infer citation B', async (t) => {
return remark()
.use(remarkGfm)
.use(remarkBibtex, { bibtexFile: bibtexFilePath })
.process('(@Harris2020)')
.then((content) => content.toString())
.then((markdown) => {
t.equal(
markdown,
'[^1]\n\n[^1]: 1\\. Harris CR, Millman KJ, van der Walt SJ, Gommers R, Virtanen P, Cournapeau D, et al. Array programming with NumPy. Nature \\[Internet]. 2020 Sep;585(7825):357–62. Available from: http\\://www\\.nature.com/articles/s41586-020-2649-2\n'
)
})
.catch((err) => console.error(err))
})
test('Infer citation A in context', async (t) => {
return remark()
.use(remarkGfm)
.use(remarkBibtex, { bibtexFile: bibtexFilePath })
.process('# My Document\n\nSo here is my citation (@Wasserman1994). End of story.\n\n')
.then((content) => content.toString())
.then((markdown) => {
t.equal(
markdown,
'# My Document\n\nSo here is my citation[^1]. End of story.\n\n[^1]: 1\\. Wasserman S, Faust K. Social Network Analysis. Cambridge: Cambridge University Press; 1994. \n'
)
})
.catch((err) => console.error(err))
})
test('Infer citations A & B', async (t) => {
return remark()
.use(remarkGfm)
.use(remarkBibtex, { bibtexFile: bibtexFilePath })
.process('Ref A: (@Harris2020) Ref B: (@Wasserman1994)')
.then((content) => content.toString())
.then((markdown) => {
t.equal(
markdown,
'Ref A:[^1] Ref B:[^2]\n\n[^1]: 1\\. Harris CR, Millman KJ, van der Walt SJ, Gommers R, Virtanen P, Cournapeau D, et al. Array programming with NumPy. Nature \\[Internet]. 2020 Sep;585(7825):357–62. Available from: http\\://www\\.nature.com/articles/s41586-020-2649-2\n\n\n[^2]: 1\\. Wasserman S, Faust K. Social Network Analysis. Cambridge: Cambridge University Press; 1994. \n'
)
})
.catch((err) => console.error(err))
})
test('Infer citations A & B with reverse order and duplicate entry', async (t) => {
return remark()
.use(remarkGfm)
.use(remarkBibtex, { bibtexFile: bibtexFilePath })
.process('Ref A: (@Wasserman1994) Ref B: (@Harris2020) Ref C: (@Wasserman1994)')
.then((content) => content.toString())
.then((markdown) => {
t.equal(
markdown,
'Ref A:[^1] Ref B:[^2] Ref C:[^1]\n\n[^1]: 1\\. Wasserman S, Faust K. Social Network Analysis. Cambridge: Cambridge University Press; 1994. \n\n\n[^2]: 1\\. Harris CR, Millman KJ, van der Walt SJ, Gommers R, Virtanen P, Cournapeau D, et al. Array programming with NumPy. Nature \\[Internet]. 2020 Sep;585(7825):357–62. Available from: http\\://www\\.nature.com/articles/s41586-020-2649-2\n'
)
})
.catch((err) => console.error(err))
})