diff --git a/src/chord_sheet/chord_pro/composite.js b/src/chord_sheet/chord_pro/composite.js index 23e88d84..7e078675 100644 --- a/src/chord_sheet/chord_pro/composite.js +++ b/src/chord_sheet/chord_pro/composite.js @@ -13,6 +13,13 @@ class Composite { isRenderable() { return true; } + + clone() { + return new Composite({ + expressions: this.expressions.map((expression) => expression.clone()), + variable: this.variable, + }); + } } export default Composite; diff --git a/src/chord_sheet/chord_pro/literal.js b/src/chord_sheet/chord_pro/literal.js index 61c7d459..3e8fd13c 100644 --- a/src/chord_sheet/chord_pro/literal.js +++ b/src/chord_sheet/chord_pro/literal.js @@ -10,6 +10,10 @@ class Literal { isRenderable() { return true; } + + clone() { + return new Literal(this.string); + } } export default Literal; diff --git a/src/chord_sheet/chord_pro/ternary.js b/src/chord_sheet/chord_pro/ternary.js index a7ee3898..0d9fda13 100644 --- a/src/chord_sheet/chord_pro/ternary.js +++ b/src/chord_sheet/chord_pro/ternary.js @@ -65,6 +65,18 @@ class Ternary { isRenderable() { return true; } + + clone() { + return new Ternary({ + variable: this.variable, + valueTest: this.valueTest, + trueExpression: this.trueExpression?.map((part) => part.clone()), + falseExpression: this.falseExpression?.map((part) => part.clone()), + line: this.line, + column: this.column, + offset: this.offset, + }); + } } export default Ternary; diff --git a/test/chord_sheet/song.test.js b/test/chord_sheet/song.test.js index d9c4a1af..8222e665 100644 --- a/test/chord_sheet/song.test.js +++ b/test/chord_sheet/song.test.js @@ -1,10 +1,8 @@ import { Song, - Metadata, ChordSheetSerializer, } from '../../src'; -import LineStub from '../cloneable_stub'; import { createSong } from '../utilities'; import exampleSong from '../fixtures/song'; import serializedSong from '../fixtures/serialized_song.json'; @@ -106,14 +104,10 @@ describe('Song', () => { describe('#clone', () => { it('returns a clone of the song', () => { - const song = new Song(); - song.lines = ['foo', 'bar'].map((value) => new LineStub(value)); - song.metadata = new Metadata({ foo: 'bar' }); - const clonedSong = song.clone(); - - const actualValues = clonedSong.lines.map((line) => line.value); - expect(actualValues).toEqual(['foo', 'bar']); - expect(clonedSong.metadata).toEqual({ foo: 'bar' }); + const serializedExampleSong = new ChordSheetSerializer().serialize(exampleSong); + const clone = exampleSong.clone(); + const serializedClone = new ChordSheetSerializer().serialize(clone); + expect(serializedClone).toEqual(serializedExampleSong); }); });