]> git.donarmstrong.com Git - lilypond.git/blob - input/no-notation/display-lily-tests.ly
*** empty log message ***
[lilypond.git] / input / no-notation / display-lily-tests.ly
1 \version "2.7.6"
2
3 #(use-modules (srfi srfi-13)
4               (ice-9 format))
5
6 %%%
7 %%% Testing utilities
8 %%%
9 #(define (my-parse-string-result str parser)
10   "Parse `str', which is supposed to contain a music expression."
11   (ly:parser-parse-string parser
12                           (format #f "parseStringResult = \\notemode { ~a }" str))
13   (ly:parser-lookup parser 'parseStringResult))
14
15 #(define (my-read-lily-expression chr port)
16   (let ((lily-string (call-with-output-string
17                       (lambda (out)
18                         (do ((c (read-char port) (read-char port)))
19                             ((and (char=? c #\#)
20                                   (char=? (peek-char port) #\]))
21                              (read-char port))
22                           (display c out))))))
23     `(let* ((parser-clone (ly:clone-parser parser))
24             (input-str (string-trim-both ,lily-string))
25             (music (car (ly:music-property (my-parse-string-result input-str parser-clone)
26                                            'elements)))
27             (result-str (string-trim-both (music->lily-string music))))
28        (cons input-str result-str))))
29
30 #(read-hash-extend #\[ my-read-lily-expression)
31
32 #(define test-number 0)
33   
34 #(define (lily-string->markup str)
35    (make-column-markup (string-split str #\NewLine)))
36
37 test = #(def-music-function (parser location result-info strings) (string? pair?)
38          (display-lily-init parser)
39           (let ((input (car strings))
40                 (output (cdr strings)))
41             (set! test-number (1+ test-number))
42             (if (string=? input output)
43                 (make-music 'SequentialMusic)
44                 (make-music 'SequentialMusic
45                             'elements
46                             (list (make-music 'EventChord
47                                    'elements (list (make-music 'BreakEvent
48                                                     'page-penalty 0
49                                                     'penalty -10001)))
50                                   (make-music 'EventChord
51                                    'elements (list (make-music 'SkipEvent
52                                                     'duration (ly:make-duration 0 0 1 1))
53                                                    (make-music 'TextScriptEvent
54                                                     'direction -1
55                                                     'text (markup #:column (#:simple (format #f "Test #~a "
56                                                                                       test-number)
57                                                                             (if (string-null? result-info) 
58                                                                                 (markup #:bold "BUG") 
59                                                                                 (markup #:simple result-info))
60                                                                             #:typewriter (lily-string->markup input)
61                                                                             #:typewriter (lily-string->markup output)))))))))))
62
63 %%%
64 %%% Tests
65 %%%
66 \header {
67   texidoc = \markup \column { \line { \typewriter display-lily-music unit tests }
68                               \line { Real bugs (regressions) are marked as \bold BUG. }
69                               \line { Known bugs are marked as TODO. } }
70 }
71
72 \layout {
73   raggedright = ##t 
74   indent = 0.0\cm
75   \context {
76     \Staff
77     \override StaffSymbol #'line-count = #1
78     %\remove "Staff_symbol_engraver"
79     \remove "Time_signature_engraver"
80     \remove "Clef_engraver"
81   }
82   \context {
83     \Score
84     \remove "Bar_number_engraver"
85   }
86 }
87 {
88   %% Sequential music
89   \test #"" ##[ { { a b } { c d } } #]                  % SequentialMusic
90   \test #"" ##[ << { a b } { c d } >> #]                % SimultaneousMusic
91   \test #"" ##[ << { a b } \\ { c d } >> #]             % VoiceSeparator
92   
93   %% Chords and Notes
94   \test #"" ##[ { ceses ces c cis cisis } #]            % NoteEvent
95   \test #"" ##[ { deses des d dis disis } #]
96   \test #"" ##[ { eeses ees e eis eisis } #]
97   \test #"" ##[ { feses fes f fis fisis } #]
98   \test #"" ##[ { geses ges g gis gisis } #]
99   \test #"" ##[ { aeses aes a ais aisis } #]
100   \test #"" ##[ { beses bes b bis bisis } #]
101   \test #"" ##[ { c,, d' } #]
102   \test #"" ##[ { c' d'=' } #]
103   \test #"" ##[ { c! c? } #]
104   \test #"" ##[ r1.*4/3 #]                              % RestEvent
105   \test #"" ##[ c1\rest #]                              % RestEvent
106   \test #"" ##[ s2..*3/4 #]                             % SkipEvent
107   \test #"" ##[ R1.*2/3 #]                              % MultiMeasureRestMusicGroup, MultiMeasureRestEvent
108   \test #"" ##[ \skip 2.*3/4 #]                         % SkipMusic
109   \test #"" ##[ < c\1 e\3 >4.*3/4-. #]                  % EventChord, NoteEvent, StringNumberEvent, ArticulationEvent
110
111   %% tags
112   \test #"" ##[ { \tag #'foo { c4 d } } #]
113   \test #"" ##[ c-\tag #'foo -\tag #'baz -^ -. #]
114
115   %% Graces
116   \test #"" ##[ { \grace c8 d2 } #]                     % GraceMusic
117   \test #"" ##[ { \appoggiatura c8 d2 } #]
118   \test #"" ##[ { \acciaccatura c8 d2 } #]
119   \test #"" ##[ { c1 \afterGrace { b,16 c } d2 } #]
120
121   %% Clusters
122   \test #"" ##[ { \makeClusters { c4 g } } #]           % ClusterNoteEvent
123
124   %% Figured bass
125   \test #"" ##[ \figures { < 6 > } #]                   % BassFigureEvent
126   \test #"" ##[ \figuremode { < 1-- 3- > < 2+ 4++ > < _! 7! > } #]
127   \test #"" ##[ \figuremode { < [6 > < 5] > } #]
128
129   %% Lyrics
130   \test #"" ##[ \lyrics { a b } #]
131   \test #"" ##[ \lyricmode { a --  b } #]               % HyphenEvent
132   \test #"" ##[ \lyricmode { a __  b } #]               % ExtenderEvent
133   \test #"" ##[ \lyricmode { "a " } #]                  % LyricEvent
134   \test #"" ##[ \lyricsto "foo" { bla bla } #]          % LyricCombineMusic
135   \test #"" ##[ { { c d }
136   \addlyrics { bla bla } } #]
137   \test #"" ##[ \oldaddlyrics { c d }
138 \lyricmode { bla bla } #]                               % OldLyricCombineMusic
139
140   %% Drums
141   \test #"" ##[ \drums { hihat } #]
142   \test #"" ##[ \drummode { hihat4.*3/4 } #]
143
144   %% Expressive marks
145   \test #"" ##[ c4 ~ #]                                 % TieEvent
146   \test #"" ##[ c\noBeam #]                             % BeamForbidEvent
147   \test #"" ##[ c\1 #]                                  % StringNumberEvent
148   \test #"" ##[ { c:  c:1  } #]                         % TremoloEvent
149   \test #"" ##[ { c-^  c^^  c_^  } #]                   % ArticulationEvent
150   \test #"" ##[ { c-+  c^+  c_+  } #]
151   \test #"" ##[ { c--  c^-  c_-  } #]
152   \test #"" ##[ { c-|  c^|  c_|  } #]
153   \test #"" ##[ { c->  c^>  c_>  } #]
154   \test #"" ##[ { c-.  c^.  c_.  } #]
155   \test #"" ##[ { c-_  c^_  c__  } #]
156   \test #"" ##[ { c-\trill  c^\trill  c_\trill  } #]
157   \test #"" ##[ { c-1  c^2  c_3  } #]                   % FingerEvent
158   \test #"" ##[ { c-"foo"  c^"foo"  c_"foo"  } #]       % TextScriptEvent
159   \test #"" ##[ { R1*4 -"foo"  R ^"foo"  R _"foo"  } #] % MultiMeasureTextEvent
160   \test #"" ##[ { c4-\harmonic  c^\harmonic  c_\harmonic  } #]  % HarmonicEvent
161   \test #"" ##[ { c-\glissando  c^\glissando  c_\glissando  } #] % GlissandoEvent
162   \test #"" ##[ { c-\arpeggio  c^\arpeggio  c_\arpeggio  } #]   % ArpeggioEvent
163   \test #"" ##[ { c\p  c^\ff  c_\sfz  } #]              % AbsoluteDynamicEvent
164   \test #"" ##[ { c[  c]  c^[  c^]  c_[  c_]  } #]      % BeamEvent
165   \test #"" ##[ { c(  c)  c^(  c^)  c_(  c_)  } #]      % SlurEvent
166   \test #"" ##[ { c\<  c\!  c^\<  c^\!  c_\<  c_\!  } #]        % CrescendoEvent
167   \test #"" ##[ { c\>  c\!  c^\>  c^\!  c_\>  c_\!  } #]        % DecrescendoEvent
168   \test #"" ##[ { c\(  c\)  c^\(  c^\)  c_\(  c_\)  } #]        % PhrasingSlurEvent
169   \test #"" ##[ { c\sustainDown  c\sustainUp  } #] % SustainEvent
170   \test #"" ##[ { c\sostenutoDown  c\sostenutoUp  } #] % SostenutoEvent
171   \test #"" ##[ { c\melisma  c\melismaEnd  } #]         % ManualMelismaEvent
172   \test #"" ##[ { c\startTextSpan  c\stopTextSpan  } #] % TextSpanEvent
173   \test #"" ##[ { c\startTrillSpan  c\stopTrillSpan  } #] % TrillSpanEvent
174   \test #"" ##[ { c \startStaff c \stopStaff } #]       % StaffSpanEvent
175   \test #"" ##[ { c\startGroup  c\stopGroup  c^\startGroup  c^\stopGroup  c_\startGroup  c_\stopGroup  } #] % NoteGroupingEvent
176   \test #"" ##[ { c\unaCorda  c\treCorde  } #] % UnaCordaEvent
177   \test #"" ##[ \breathe #]
178   \test #"" ##[ { c \[  c \]  } #]                      % LigatureEvent
179   \test #"" ##[ \~ #]                                   % PesOrFlexaEvent
180
181   \test #"" ##[ \break #]
182
183   %% Checks
184   \test #"" ##[ \octave a' #]                           % RelativeOctaveCheck
185   \test #"" ##[ | #]                                    % BarCheck
186
187   %% Marks
188   \test #"" ##[ \mark \default #]                       % MarkEvent
189   \test #"" ##[ \mark "Allegro" #]
190   \test #"" ##[ \tempo 4 = 120 #]                       % MetronomeChangeEvent
191
192   %% key, time, clef, bar
193   \test #"" ##[ \key \default #]                        % KeyChangeEvent
194   \test #"" ##[ \key e \minor #]
195   \test #"" ##[ \clef "bass" #]
196   \test #"" ##[ \clef "french^2" #]
197   \test #"" ##[ \clef "alto_3" #]
198   \test #"" ##[ \time 2/4 #]
199   \test #"" ##[ #(set-time-signature 5 8 '(3 2)) #]
200   \test #"" ##[ \bar "|." #]
201
202   %% staff switches
203   \test #"" ##[ \autochange { c d } #]                  % AutoChangeMusic
204   \test #"" ##[ { \change Staff = "up" { c d } } #]     % ContextChange
205
206   %% Tuplets
207   \test #"" ##[ \times 2/3 { c8 d e } #]                                % TimeScaledMusic
208   \test #"" ##[ \times 4/6 { c16 d e f g a } #]
209
210   %% \relative and \tranpose
211   \test #"NOT A BUG" ##[ \relative c' { c b } #]        % RelativeOctaveMusic
212   \test #"NOT A BUG" ##[ \transpose c d { c d } #]      % TransposedMusic
213   
214   %% Repeats
215   \test #"" ##[ \repeat volta 2 { c d } #]              % VoltaRepeatedMusic
216   \test #"" ##[ \repeat unfold 2 { c d } #]             % UnfoldedRepeatedMusic
217   \test #"" ##[ \repeat fold 2 { c d } #]               % FoldedRepeatedMusic
218   \test #"" ##[ \repeat percent 2 { c d } #]            % PercentRepeatedMusic
219   \test #"" ##[ \repeat tremolo 4 { c16 d } #]          % TremoloRepeatedMusic
220   \test #"" ##[ \repeat volta 2 { c4 d } \alternative { { c d } { e f } } #] % 
221
222   %% Context creation
223   \test #"" ##[ \new Staff { c d } #]                   % ContextSpeccedMusic
224   \test #"" ##[ \new Staff = "up" { c d } #]                    % ContextSpeccedMusic
225   \test #"" ##[ \context Staff { c d } #]
226   \test #"" ##[ \context Staff = "up" { c d } #]
227   \test #"" ##[
228 \new Staff \with {
229   \consists "Timing_engraver"
230   \remove "Clef_engraver"
231 } { c d } #]
232   %% Context properties
233   \test #"" ##[ \once \set Score . skipBars = ##t #]    % PropertySet
234   \test #"" ##[ \set autoBeaming = ##f #]
235   \test #"" ##[ \unset Score . skipBars #]              % PropertyUnset
236   \test #"" ##[ \unset autoBeaming #]
237   %% Layout properties
238   \test #"" ##[ \override Staff . Stem #'thickness = #4.0 #]    % OverrideProperty
239   \test #"" ##[ \once \override Beam #'thickness = #0.6 #]
240   \test #"" ##[ \revert Staff . Stem #'thickness #]     % RevertProperty
241   \test #"" ##[ \revert Beam #'thickness #]
242
243   %% \partial
244
245
246   \test #"" ##[ \partial 2 #]
247   \test #"" ##[ \partial 8. #]
248   \test #"TODO? exotic durations in \\partial" ##[ \partial 4*2/3 #]
249
250   %% \partcombine
251   \test #"" ##[ \partcombine { c e }
252 { d f } #]                                              % PartCombineMusic UnrelativableMusic
253
254   %% Cue notes
255   \test #"" ##[ \cueDuring #"foo" #1 { c d } #]
256   \test #"" ##[ \quoteDuring #"foo" { c d } #]
257 }
258