songsheet 6.0.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,6 +112,14 @@ describe('parse spent-some-time-in-buffalo', () => {
112
112
  expect(song.author).toBe('WILLIE COTTON')
113
113
  })
114
114
 
115
+ it('extracts BPM', () => {
116
+ expect(song.bpm).toBe(100)
117
+ })
118
+
119
+ it('has null timeSignature when not specified', () => {
120
+ expect(song.timeSignature).toBeNull()
121
+ })
122
+
115
123
  it('counts sections correctly', () => {
116
124
  expect(song.sections.verse.count).toBe(3)
117
125
  expect(song.sections.chorus.count).toBe(3)
@@ -180,6 +188,14 @@ describe('parse song-of-myself', () => {
180
188
  expect(song.author).toBe('WILLIE AND WALT')
181
189
  })
182
190
 
191
+ it('extracts time signature', () => {
192
+ expect(song.timeSignature).toEqual({ beats: 3, value: 4 })
193
+ })
194
+
195
+ it('has null BPM when not specified', () => {
196
+ expect(song.bpm).toBeNull()
197
+ })
198
+
183
199
  it('counts sections correctly', () => {
184
200
  expect(song.sections.verse.count).toBe(1)
185
201
  expect(song.sections.chorus.count).toBe(1)
@@ -238,6 +254,54 @@ describe('parse song-of-myself', () => {
238
254
  })
239
255
  })
240
256
 
257
+ describe('time signature parsing', () => {
258
+ it('returns null timeSignature when only BPM is present', () => {
259
+ const song = parse('SONG - AUTHOR\n(120 BPM)\n\nG\nLyrics')
260
+ expect(song.bpm).toBe(120)
261
+ expect(song.timeSignature).toBeNull()
262
+ })
263
+
264
+ it('parses time signature without BPM', () => {
265
+ const song = parse('SONG - AUTHOR\n(3/4 time)\n\nG\nLyrics')
266
+ expect(song.bpm).toBeNull()
267
+ expect(song.timeSignature).toEqual({ beats: 3, value: 4 })
268
+ })
269
+
270
+ it('parses both BPM and time signature together', () => {
271
+ const song = parse('SONG - AUTHOR\n(100 BPM, 3/4 time)\n\nG\nLyrics')
272
+ expect(song.bpm).toBe(100)
273
+ expect(song.timeSignature).toEqual({ beats: 3, value: 4 })
274
+ })
275
+
276
+ it('parses reversed order: time signature before BPM', () => {
277
+ const song = parse('SONG - AUTHOR\n(3/4 time, 100 BPM)\n\nG\nLyrics')
278
+ expect(song.bpm).toBe(100)
279
+ expect(song.timeSignature).toEqual({ beats: 3, value: 4 })
280
+ })
281
+
282
+ it('parses 6/8 time', () => {
283
+ const song = parse('SONG - AUTHOR\n(6/8 Time)\n\nG\nLyrics')
284
+ expect(song.timeSignature).toEqual({ beats: 6, value: 8 })
285
+ })
286
+
287
+ it('is case insensitive for TIME', () => {
288
+ const song = parse('SONG - AUTHOR\n(3/4 TIME)\n\nG\nLyrics')
289
+ expect(song.timeSignature).toEqual({ beats: 3, value: 4 })
290
+ })
291
+
292
+ it('returns both null when no metadata parens present', () => {
293
+ const song = parse('SONG - AUTHOR\n\nG\nLyrics')
294
+ expect(song.bpm).toBeNull()
295
+ expect(song.timeSignature).toBeNull()
296
+ })
297
+
298
+ it('does not match non-metadata parens like (live)', () => {
299
+ const song = parse('SONG - AUTHOR\n(live)\n\nG\nLyrics')
300
+ expect(song.bpm).toBeNull()
301
+ expect(song.timeSignature).toBeNull()
302
+ })
303
+ })
304
+
241
305
  describe('bar line parsing', () => {
242
306
  it('parses bar lines in chord lines', () => {
243
307
  const song = parse('TEST SONG - AUTHOR\n\n| G | C | D |\nSome lyrics here')
@@ -56,6 +56,19 @@ describe('transposeChord', () => {
56
56
  expect(transposeChord({ root: 'B', type: '' }, 1, false)).toEqual({ root: 'C', type: '' })
57
57
  expect(transposeChord({ root: 'C', type: '' }, -1, false)).toEqual({ root: 'B', type: '' })
58
58
  })
59
+
60
+ it('transposes slash chord bass note', () => {
61
+ expect(transposeChord({ root: 'G', type: '', bass: 'B' }, 2, false)).toEqual({ root: 'A', type: '', bass: 'C#' })
62
+ })
63
+
64
+ it('transposes slash chord bass note with flats', () => {
65
+ expect(transposeChord({ root: 'C', type: 'maj7', bass: 'Bb' }, 2, true)).toEqual({ root: 'D', type: 'maj7', bass: 'C' })
66
+ })
67
+
68
+ it('does not add bass when not present', () => {
69
+ const result = transposeChord({ root: 'G', type: '' }, 2, false)
70
+ expect(result.bass).toBeUndefined()
71
+ })
59
72
  })
60
73
 
61
74
  describe('transpose full song', () => {