@@ -15,14 +15,52 @@ test('findNoteTitle#find should return a correct title (string)', t => {
1515 [ '====' , '====' ] ,
1616 [ '```\n# hoge\n```' , '```' ] ,
1717 [ 'hoge' , 'hoge' ] ,
18- [ '---\nlayout: test\n---\n # hoge' , '# hoge' ] ,
18+ [ '---\nlayout: test\n---\n # hoge' , '# hoge' ]
19+ ]
20+
21+ testCases . forEach ( testCase => {
22+ const [ input , expected ] = testCase
23+ t . is ( findNoteTitle ( input , false ) , expected , `Test for find() input: ${ input } expected: ${ expected } ` )
24+ } )
25+ } )
26+
27+ test ( 'findNoteTitle#find should ignore front matter when enableFrontMatterTitle=false' , t => {
28+ // [input, expected]
29+ const testCases = [
30+ [ '---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga' , '# fuga' ] ,
31+ [ '---\ntitle:hoge\n---\n# fuga' , '# fuga' ] ,
32+ [ 'title: fuga\n# hoge' , '# hoge' ]
33+ ]
34+
35+ testCases . forEach ( testCase => {
36+ const [ input , expected ] = testCase
37+ t . is ( findNoteTitle ( input , false ) , expected , `Test for find() input: ${ input } expected: ${ expected } ` )
38+ } )
39+ } )
40+
41+ test ( 'findNoteTitle#find should respect front matter when enableFrontMatterTitle=true' , t => {
42+ // [input, expected]
43+ const testCases = [
1944 [ '---\nlayout: test\ntitle: hoge hoge hoge \n---\n# fuga' , 'hoge hoge hoge' ] ,
2045 [ '---\ntitle:hoge\n---\n# fuga' , 'hoge' ] ,
2146 [ 'title: fuga\n# hoge' , '# hoge' ]
2247 ]
2348
2449 testCases . forEach ( testCase => {
2550 const [ input , expected ] = testCase
26- t . is ( findNoteTitle ( input ) , expected , `Test for find() input: ${ input } expected: ${ expected } ` )
51+ t . is ( findNoteTitle ( input , true ) , expected , `Test for find() input: ${ input } expected: ${ expected } ` )
2752 } )
2853} )
54+
55+ test ( 'findNoteTitle#find should respect frontMatterTitleField when provided' , t => {
56+ // [input, expected]
57+ const testCases = [
58+ [ '---\ntitle: hoge\n---\n# fuga' , '# fuga' ] ,
59+ [ '---\ncustom: hoge\n---\n# fuga' , 'hoge' ]
60+ ]
61+
62+ testCases . forEach ( testCase => {
63+ const [ input , expected ] = testCase
64+ t . is ( findNoteTitle ( input , true , 'custom' ) , expected , `Test for find() input: ${ input } expected: ${ expected } ` )
65+ } )
66+ } )
0 commit comments