@@ -337,6 +337,15 @@ This part is [G]key
337
337
expect ( song . title ) . toEqual ( 'my {title}' ) ;
338
338
} ) ;
339
339
340
+ it ( 'allows conditional directives' , ( ) => {
341
+ const chordSheet = '{title-guitar: Guitar song}' ;
342
+ const song = new ChordProParser ( ) . parse ( chordSheet ) ;
343
+
344
+ const tag = song . lines [ 0 ] . items [ 0 ] as Tag ;
345
+
346
+ expect ( tag ) . toBeTag ( 'title' , 'Guitar song' , 'guitar' ) ;
347
+ } ) ;
348
+
340
349
it ( 'parses annotation' , ( ) => {
341
350
const chordSheet = '[*Full band!]Let it be' ;
342
351
const song = new ChordProParser ( ) . parse ( chordSheet ) ;
@@ -670,6 +679,32 @@ Let it [Am]be
670
679
expect ( lines [ 2 ] . items [ 0 ] ) . toBeLiteral ( 'LY line 2' ) ;
671
680
} ) ;
672
681
682
+ it ( 'parses conditional sections' , ( ) => {
683
+ const chordSheet = heredoc `
684
+ {start_of_ly-guitar: Intro}
685
+ LY line 1
686
+ LY line 2
687
+ {end_of_ly}
688
+ ` ;
689
+
690
+ const parser = new ChordProParser ( ) ;
691
+ const song = parser . parse ( chordSheet ) ;
692
+ const { paragraphs } = song ;
693
+ const paragraph = paragraphs [ 0 ] ;
694
+ const { lines } = paragraph ;
695
+
696
+ expect ( paragraphs ) . toHaveLength ( 1 ) ;
697
+ expect ( paragraph . type ) . toEqual ( LILYPOND ) ;
698
+ expect ( paragraph . selector ) . toEqual ( 'guitar' ) ;
699
+ expect ( lines ) . toHaveLength ( 3 ) ;
700
+
701
+ expect ( lines [ 0 ] . items [ 0 ] ) . toBeTag ( 'start_of_ly' , 'Intro' , 'guitar' ) ;
702
+ expect ( lines [ 1 ] . items [ 0 ] ) . toBeLiteral ( 'LY line 1' ) ;
703
+ expect ( lines [ 2 ] . items [ 0 ] ) . toBeLiteral ( 'LY line 2' ) ;
704
+
705
+ expect ( lines . every ( ( line ) => line . selector === 'guitar' ) ) . toBe ( true ) ;
706
+ } ) ;
707
+
673
708
it ( 'parses soft line breaks when enabled' , ( ) => {
674
709
const chordSheet = heredoc `
675
710
[Am]Let it be,\\ let it [C/G]be
@@ -748,6 +783,23 @@ Let it [Am]be
748
783
fingers : [ ] ,
749
784
} ) ;
750
785
} ) ;
786
+
787
+ it ( 'parses conditional chord definitions' , ( ) => {
788
+ const chordSheet = '{define-guitar: Am base-fret 1 frets 0 2 2 1 0 0}' ;
789
+ const parser = new ChordProParser ( ) ;
790
+ const song = parser . parse ( chordSheet ) ;
791
+ const tag = song . lines [ 0 ] . items [ 0 ] ;
792
+ const { chordDefinition } = ( tag as Tag ) ;
793
+
794
+ expect ( tag ) . toBeTag ( 'define' , 'Am base-fret 1 frets 0 2 2 1 0 0' , 'guitar' ) ;
795
+
796
+ expect ( chordDefinition ) . toEqual ( {
797
+ name : 'Am' ,
798
+ baseFret : 1 ,
799
+ frets : [ 0 , 2 , 2 , 1 , 0 , 0 ] ,
800
+ fingers : [ ] ,
801
+ } ) ;
802
+ } ) ;
751
803
} ) ;
752
804
753
805
describe ( '{chord} chord definitions' , ( ) => {
@@ -786,5 +838,23 @@ Let it [Am]be
786
838
fingers : [ ] ,
787
839
} ) ;
788
840
} ) ;
841
+
842
+ it ( 'parses conditional chord definitions' , ( ) => {
843
+ const chordSheet = '{chord-ukulele: D7 base-fret 3 frets x 3 2 3 1 x }' ;
844
+
845
+ const parser = new ChordProParser ( ) ;
846
+ const song = parser . parse ( chordSheet ) ;
847
+ const tag = song . lines [ 0 ] . items [ 0 ] ;
848
+ const { chordDefinition } = ( tag as Tag ) ;
849
+
850
+ expect ( tag ) . toBeTag ( 'chord' , 'D7 base-fret 3 frets x 3 2 3 1 x' , 'ukulele' ) ;
851
+
852
+ expect ( chordDefinition ) . toEqual ( {
853
+ name : 'D7' ,
854
+ baseFret : 3 ,
855
+ frets : [ 'x' , 3 , 2 , 3 , 1 , 'x' ] ,
856
+ fingers : [ ] ,
857
+ } ) ;
858
+ } ) ;
789
859
} ) ;
790
860
} ) ;
0 commit comments