Skip to content

Commit

Permalink
Fix bug in Accidental Tests with 'this' being undefined.
Browse files Browse the repository at this point in the history
Clean up more tests.
  • Loading branch information
ronyeh committed Jul 30, 2021
1 parent 2db426c commit c0be3b3
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 268 deletions.
9 changes: 7 additions & 2 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ export class Registry {
}
}

// Register element `elem` with this registry. This adds the element to its index and watches
// it for attribute changes.
/**
* Register element `elem` with this registry.
* This adds the element to its index and watches it for attribute changes.
* @param elem
* @param id
* @returns this
*/
register(elem: Element, id?: string): this {
id = id || elem.getAttribute('id');
if (!id) {
Expand Down
2 changes: 1 addition & 1 deletion src/stave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export class Stave extends Element {
return this;
}

addEndClef(clef: string, size: string, annotation: string): this {
addEndClef(clef: string, size?: string, annotation?: string): this {
this.addClef(clef, size, annotation, StaveModifier.Position.END);
return this;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/accidental_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//
// Accidental Tests

/* eslint-disable */
// @ts-nocheck
/* xeslint-disable */
// x@ts-nocheck

import { VexFlowTests, TestOptions } from './vexflow_test_helpers';
import { QUnit, ok, equal } from './declarations';
Expand Down Expand Up @@ -33,7 +33,7 @@ function makeNewAccid(factory: any) {
}

const AccidentalTests = {
Start() {
Start(): void {
QUnit.module('Accidental');
VexFlowTests.runTests('Accidental Padding', this.formatAccidentalSpaces);
VexFlowTests.runTests('Basic', this.basic);
Expand Down Expand Up @@ -372,7 +372,7 @@ const AccidentalTests = {
.addAccidental(2, newAccid('##'))
.setStave(stave);

this.showNotes(note1, note2, stave, ctx, 60);
AccidentalTests.showNotes(note1, note2, stave, ctx, 60);

note1 = f
.StaveNote({ keys: ['c/4', 'e/4', 'c/5'], duration: '2', stem_direction: -1 })
Expand All @@ -386,7 +386,7 @@ const AccidentalTests = {
.addAccidental(0, newAccid('b'))
.setStave(stave);

this.showNotes(note1, note2, stave, ctx, 150);
AccidentalTests.showNotes(note1, note2, stave, ctx, 150);

note1 = f
.StaveNote({ keys: ['d/4', 'c/5', 'd/5'], duration: '2', stem_direction: -1 })
Expand All @@ -400,7 +400,7 @@ const AccidentalTests = {
.addAccidental(0, newAccid('b'))
.setStave(stave);

this.showNotes(note1, note2, stave, ctx, 250);
AccidentalTests.showNotes(note1, note2, stave, ctx, 250);
VexFlowTests.plotLegendForNoteWidth(ctx, 350, 150);

ok(true, 'Full Accidental');
Expand Down
28 changes: 14 additions & 14 deletions tests/bach_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import { VexFlowTests, TestOptions, concat } from './vexflow_test_helpers';
import { QUnit, ok } from './declarations';
import { Factory } from 'factory';
import { Registry } from 'registry';
import { Barline } from 'stavebarline';
import { BarlineType } from 'stavebarline';
import { Element } from 'element';

const BachDemoTests = {
Start: function () {
const runTests = VexFlowTests.runTests;
Start(): void {
QUnit.module('Bach Demo');
runTests('Minuet 1', BachDemoTests.minuet1);
VexFlowTests.runTests('Minuet 1', this.minuet1);
},

minuet1: function (options: TestOptions) {
minuet1(options: TestOptions): void {
const registry = new Registry();
Registry.enableDefaultRegistry(registry);
function id(id: string): Element {
return registry.getElementById(id) as Element;
}

const f: Factory = VexFlowTests.makeFactory(options, 1100, 900);
const score = f.EasyScore({ throwOnError: true });

Expand All @@ -29,16 +33,13 @@ const BachDemoTests = {

let x = 120;
let y = 80;

function makeSystem(width: number) {
const system = f.System({ x, y, width, spaceBetweenStaves: 10 });
x += width;
return system;
}

function id(id: any): any {
return registry.getElementById(id);
}

score.set({ time: '3/4' });

/* Measure 1 */
Expand Down Expand Up @@ -358,11 +359,11 @@ const BachDemoTests = {
.addStave({
voices: [score.set({ clef: 'treble' }).voice([notes('g4/h.[id="m16a"]')].reduce(concat))],
})
.setEndBarType(Barline.type.REPEAT_END);
.setEndBarType(BarlineType.REPEAT_END);

system
.addStave({ voices: [voice(notes('g3/h[id="m16b"], g2/q', { clef: 'bass' }))] })
.setEndBarType(Barline.type.REPEAT_END);
.setEndBarType(BarlineType.REPEAT_END);
system.addConnector('boldDoubleRight');

id('m16a').addModifier(f.Fingering({ number: '1' }), 0);
Expand Down Expand Up @@ -392,9 +393,9 @@ const BachDemoTests = {
voice([f.TextDynamics({ text: 'mf', duration: 'h', dots: 1, line: 10 })]),
],
})
.setBegBarType(Barline.type.REPEAT_BEGIN);
.setBegBarType(BarlineType.REPEAT_BEGIN);

system.addStave({ voices: [voice(notes('g3/h.', { clef: 'bass' }))] }).setBegBarType(Barline.type.REPEAT_BEGIN);
system.addStave({ voices: [voice(notes('g3/h.', { clef: 'bass' }))] }).setBegBarType(BarlineType.REPEAT_BEGIN);

system.addConnector('boldDoubleLeft');
system.addConnector('singleRight');
Expand Down Expand Up @@ -430,7 +431,6 @@ const BachDemoTests = {
});

/* Done */

f.draw();
Registry.disableDefaultRegistry();
ok(true, 'Bach Minuet 1');
Expand Down
54 changes: 30 additions & 24 deletions tests/curve_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
//
// Curve Tests

import { VexFlowTests, concat } from './vexflow_test_helpers';
/* eslint-disable */
// @ts-nocheck

function createTest(beamGroup1, beamGroup2, setupCurves) {
return function (options) {
import { VexFlowTests, concat, TestOptions } from './vexflow_test_helpers';
import { QUnit, ok } from './declarations';
import { Curve } from 'curve';
import { StaveNote } from 'stavenote';
import { Factory } from 'factory';

function createTest(beamGroup1, beamGroup2, setupCurves: (f: Factory, n: StaveNote[]) => void) {
return (options: TestOptions) => {
const f = VexFlowTests.makeFactory(options, 350, 200);
const stave = f.Stave({ y: 50 });
const score = f.EasyScore();

const notes = [
const notes: StaveNote[] = [
score.beam(score.notes.apply(score, beamGroup1)),
score.beam(score.notes.apply(score, beamGroup2)),
].reduce(concat);
Expand All @@ -29,15 +36,14 @@ function createTest(beamGroup1, beamGroup2, setupCurves) {
}

const CurveTests = {
Start() {
const run = VexFlowTests.runTests;

Start(): void {
QUnit.module('Curve');
const runTests = VexFlowTests.runTests;

run(
runTests(
'Simple Curve',
createTest(['c4/8, f5, d5, g5', { stem: 'up' }], ['d6/8, f5, d5, g5', { stem: 'down' }], function (vf, notes) {
vf.Curve({
createTest(['c4/8, f5, d5, g5', { stem: 'up' }], ['d6/8, f5, d5, g5', { stem: 'down' }], function (f, notes) {
f.Curve({
from: notes[0],
to: notes[3],
options: {
Expand All @@ -48,7 +54,7 @@ const CurveTests = {
},
});

vf.Curve({
f.Curve({
from: notes[4],
to: notes[7],
options: {
Expand All @@ -61,10 +67,10 @@ const CurveTests = {
})
);

run(
runTests(
'Rounded Curve',
createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], function (vf, notes) {
vf.Curve({
createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], function (f, notes) {
f.Curve({
from: notes[0],
to: notes[3],
options: {
Expand All @@ -77,7 +83,7 @@ const CurveTests = {
},
});

vf.Curve({
f.Curve({
from: notes[4],
to: notes[7],
options: {
Expand All @@ -90,10 +96,10 @@ const CurveTests = {
})
);

run(
runTests(
'Thick Thin Curves',
createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], function (vf, notes) {
vf.Curve({
createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], function (f, notes) {
f.Curve({
from: notes[0],
to: notes[3],
options: {
Expand All @@ -107,7 +113,7 @@ const CurveTests = {
},
});

vf.Curve({
f.Curve({
from: notes[4],
to: notes[7],
options: {
Expand All @@ -121,17 +127,17 @@ const CurveTests = {
})
);

run(
runTests(
'Top Curve',
createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], function (vf, notes) {
vf.Curve({
createTest(['c5/8, f4, d4, g5', { stem: 'up' }], ['d5/8, d6, d6, g5', { stem: 'down' }], function (f, notes) {
f.Curve({
from: notes[0],
to: notes[7],
options: {
x_shift: -3,
y_shift: 10,
position: VF.Curve.Position.NEAR_TOP,
position_end: VF.Curve.Position.NEAR_HEAD,
position: Curve.Position.NEAR_TOP,
position_end: Curve.Position.NEAR_HEAD,
cps: [
{ x: 0, y: 20 },
{ x: 40, y: 80 },
Expand Down
Loading

0 comments on commit c0be3b3

Please sign in to comment.