Skip to content

Commit

Permalink
StaveTieTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyeh committed Jul 29, 2021
1 parent fc5d04b commit 461f6eb
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/easyscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ interface BuilderElements {
accidentals: (Accidental | undefined)[][];
}

interface BuilderOptions {
export interface BuilderOptions {
stem?: string;
clef?: string;
// eslint-disable-next-line
Expand Down
4 changes: 2 additions & 2 deletions tests/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ VexFlowTests.run = function () {
FractionTests.Start();
ClefTests.Start();
KeySignatureTests.Start();
*/
TimeSignatureTests.Start();
// StaveTieTests.Start();
StaveTieTests.Start();
*/
// TabTieTests.Start();
// StaveTests.Start();
// TabStaveTests.Start();
Expand Down
227 changes: 114 additions & 113 deletions tests/stavetie_tests.ts
Original file line number Diff line number Diff line change
@@ -1,127 +1,128 @@
/**
* VexFlow - StaveTie Tests
* Copyright Mohit Muthanna 2010 <mohit@muthanna.com>
*/
const StaveTieTests = (function () {
function createTest(notesData, setupTies) {
return function (options) {
const f = VexFlowTests.makeFactory(options, 300);
const stave = f.Stave();
const score = f.EasyScore();
const voice = score.voice(score.notes.apply(score, notesData));
const notes = voice.getTickables();
// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
// MIT License
//
// StaveTie Tests

setupTies(f, notes, stave);
import { TestOptions, VexFlowTests } from './vexflow_test_helpers';
import { QUnit, ok } from './declarations';
import { Stem } from 'stem';
import { BuilderOptions } from 'easyscore';
import { Factory } from 'factory';
import { StaveNote } from 'stavenote';
import { Stave } from 'stave';

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
const createTest =
(notesData: [string, BuilderOptions], setupTies: (f: Factory, n: StaveNote[], s: Stave) => void) =>
(options: TestOptions) => {
const f = VexFlowTests.makeFactory(options, 300);
const stave = f.Stave();
const score = f.EasyScore();
const notes = score.notes(notesData[0], notesData[1]);
const voice = score.voice(notes);
// const tickables = voice.getTickables(); // same as the notes that we passed in.

f.draw();
setupTies(f, notes, stave);

ok(true);
};
}
f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
f.draw();
ok(true);
};

return {
Start: function () {
const run = VexFlowTests.runTests;
const StaveTieTests = {
Start(): void {
QUnit.module('StaveTie');
const runTests = VexFlowTests.runTests;

QUnit.module('StaveTie');
runTests(
'Simple StaveTie',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (f, notes) {
f.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1],
last_indices: [0, 1],
});
})
);

run(
'Simple StaveTie',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (vf, notes) {
vf.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1],
last_indices: [0, 1],
});
})
);
runTests(
'Chord StaveTie',
createTest(['(d4 e4 f4)/2, (cn4 f#4 a4)', { stem: 'down' }], function (f, notes) {
f.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1, 2],
last_indices: [0, 1, 2],
});
})
);

run(
'Chord StaveTie',
createTest(['(d4 e4 f4)/2, (cn4 f#4 a4)', { stem: 'down' }], function (vf, notes) {
vf.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1, 2],
last_indices: [0, 1, 2],
});
})
);
runTests(
'Stem Up StaveTie',
createTest(['(d4 e4 f4)/2, (cn4 f#4 a4)', { stem: 'up' }], function (f, notes) {
f.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1, 2],
last_indices: [0, 1, 2],
});
})
);

run(
'Stem Up StaveTie',
createTest(['(d4 e4 f4)/2, (cn4 f#4 a4)', { stem: 'up' }], function (vf, notes) {
vf.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1, 2],
last_indices: [0, 1, 2],
});
})
);
runTests(
'No End Note',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (f, notes, stave) {
stave.addEndClef('treble');
f.StaveTie({
from: notes[1],
to: null,
first_indices: [2],
last_indices: [2],
text: 'slow.',
});
})
);

run(
'No End Note',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (vf, notes, stave) {
stave.addEndClef('treble');
vf.StaveTie({
from: notes[1],
to: null,
first_indices: [2],
last_indices: [2],
text: 'slow.',
});
})
);
runTests(
'No Start Note',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (f, notes, stave) {
stave.addClef('treble');
f.StaveTie({
from: null,
to: notes[0],
first_indices: [2],
last_indices: [2],
text: 'H',
});
})
);

run(
'No Start Note',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (vf, notes, stave) {
stave.addClef('treble');
vf.StaveTie({
from: null,
to: notes[0],
first_indices: [2],
last_indices: [2],
text: 'H',
});
})
);
runTests(
'Set Direction Down',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (f, notes) {
f.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1],
last_indices: [0, 1],
options: { direction: Stem.DOWN },
});
})
);

run(
'Set Direction Down',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (vf, notes) {
vf.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1],
last_indices: [0, 1],
options: {
direction: VF.Stem.DOWN,
},
});
})
);
runTests(
'Set Direction Up',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (f, notes) {
f.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1],
last_indices: [0, 1],
options: { direction: Stem.UP },
});
})
);
},
};

run(
'Set Direction Up',
createTest(['(cb4 e#4 a4)/2, (d4 e4 f4)', { stem: 'down' }], function (vf, notes) {
vf.StaveTie({
from: notes[0],
to: notes[1],
first_indices: [0, 1],
last_indices: [0, 1],
options: {
direction: VF.Stem.UP,
},
});
})
);
},
};
})();
VexFlowTests.StaveTie = StaveTieTests;
export { StaveTieTests };

0 comments on commit 461f6eb

Please sign in to comment.