-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve test for `Song#changeKey` * Add test for `Song#setKey` * Implement transposing for `Song`
- Loading branch information
1 parent
12c7bf0
commit 2b5b5d8
Showing
7 changed files
with
225 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ChordProFormatter, ChordProParser } from '../../src'; | ||
|
||
describe('setting the key of an existing song', () => { | ||
it('updates the key directive', () => { | ||
const chordpro = ` | ||
{key: C} | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const changedSheet = ` | ||
{key: D} | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const song = new ChordProParser().parse(chordpro); | ||
const updatedSong = song.setKey('D'); | ||
|
||
expect(updatedSong.key).toEqual('D'); | ||
expect(new ChordProFormatter().format(updatedSong)).toEqual(changedSheet); | ||
}); | ||
|
||
it('adds the key directive', () => { | ||
const chordpro = ` | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const changedSheet = ` | ||
{key: D} | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const song = new ChordProParser().parse(chordpro); | ||
const updatedSong = song.setKey('D'); | ||
|
||
expect(updatedSong.key).toEqual('D'); | ||
expect(new ChordProFormatter().format(updatedSong)).toEqual(changedSheet); | ||
}); | ||
|
||
it('removes the key directive when passing null', () => { | ||
const chordpro = ` | ||
{key: C} | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const changedSheet = ` | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const song = new ChordProParser().parse(chordpro); | ||
const updatedSong = song.setKey(null); | ||
|
||
expect(updatedSong.key).toEqual(null); | ||
expect(new ChordProFormatter().format(updatedSong)).toEqual(changedSheet); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ChordProFormatter, ChordProParser } from '../../src'; | ||
|
||
describe('transposing a song', () => { | ||
it('transposes with a delta', () => { | ||
const chordpro = ` | ||
{key: C} | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const changedSheet = ` | ||
{key: D} | ||
Let it [Bm]be, let it [D/A]be, let it [G]be, let it [D]be`.substring(1); | ||
|
||
const song = new ChordProParser().parse(chordpro); | ||
const updatedSong = song.transpose(2); | ||
|
||
expect(updatedSong.key).toEqual('D'); | ||
expect(new ChordProFormatter().format(updatedSong)).toEqual(changedSheet); | ||
}); | ||
|
||
it('transposes up', () => { | ||
const chordpro = ` | ||
{key: C} | ||
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be`.substring(1); | ||
|
||
const changedSheet = ` | ||
{key: C#} | ||
Let it [A#m]be, let it [C#/G#]be, let it [F#]be, let it [C#]be`.substring(1); | ||
|
||
const song = new ChordProParser().parse(chordpro); | ||
const updatedSong = song.transposeUp(); | ||
|
||
expect(updatedSong.key).toEqual('C#'); | ||
expect(new ChordProFormatter().format(updatedSong)).toEqual(changedSheet); | ||
}); | ||
|
||
it('transposes down', () => { | ||
const chordpro = ` | ||
{key: D} | ||
Let it [Bm]be, let it [D/A]be, let it [G]be, let it [D]be`.substring(1); | ||
|
||
const changedSheet = ` | ||
{key: Db} | ||
Let it [Bbm]be, let it [Db/Ab]be, let it [Gb]be, let it [Db]be`.substring(1); | ||
|
||
const song = new ChordProParser().parse(chordpro); | ||
const updatedSong = song.transposeDown(); | ||
|
||
expect(updatedSong.key).toEqual('Db'); | ||
expect(new ChordProFormatter().format(updatedSong)).toEqual(changedSheet); | ||
}); | ||
}); |