Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Song#getChords() returns unique chords #1487

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/chord_sheet/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Tag, {
} from './tag';
import SongBuilder from '../song_builder';
import ChordDefinition from './chord_pro/chord_definition';
import Chord from '../chord';

type EachItemCallback = (_item: Item) => void;

Expand Down Expand Up @@ -435,7 +436,11 @@ Or set the song key before changing key:
const itemChords = (item as ChordLyricsPair).chords;

if (itemChords && itemChords.length > 0) {
chords.add(itemChords);
const parsedChord = Chord.parse(itemChords);

if (parsedChord) {
chords.add(parsedChord.toString());
}
}
});

Expand Down
5 changes: 4 additions & 1 deletion test/chord_sheet/song.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,18 @@ describe('Song', () => {
createChordLyricsPair('CM7', 'let'),
createChordLyricsPair('', 'it'),
createChordLyricsPair('Dm7', ''),
createChordLyricsPair('Dm7 ', ''),
]),
createLine([]),
createLine([
createChordLyricsPair('F#', 'be'),
createChordLyricsPair('d#', 'be'),
createChordLyricsPair(' F#', 'be'),
createChordLyricsPair('', 'changed'),
]),
]);

expect(song.getChords()).toEqual(['CM7', 'Dm7', 'F#']);
expect(song.getChords()).toEqual(['CM7', 'Dm7', 'F#', 'D#']);
});

it('returns an empty array if there are no chords in the song', () => {
Expand Down
Loading