Skip to content

Commit

Permalink
TabSlideTests, ClefKeySignatureTests, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyeh committed Aug 30, 2021
1 parent f1723fc commit 07be11f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 61 deletions.
38 changes: 1 addition & 37 deletions tests/key_clef_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,22 @@
//
// Clef Key Signature Tests
//
// TODO: How is this different from keysignature_tests.ts?

import { VexFlowTests, TestOptions, MAJOR_KEYS, MINOR_KEYS } from './vexflow_test_helpers';
import { ContextBuilder } from 'renderer';
import { Flow } from 'flow';
import { KeySignature } from 'keysignature';
import { Stave } from 'stave';

const ClefKeySignatureTests = {
Start(): void {
QUnit.module('Clef Keys');
test('Key Parser Test', this.parser);
// Removed an identical 'Key Parser Test'. See keysignature_tests.ts.
const run = VexFlowTests.runTests;
run('Major Key Clef Test', this.keys, { majorKeys: true });
run('Minor Key Clef Test', this.keys, { majorKeys: false });
run('Stave Helper', this.staveHelper);
},

parser(): void {
expect(11);

function catchError(spec: string): void {
try {
Flow.keySignature(spec);
} catch (e) {
equal(e.code, 'BadKeySignature', e.message);
}
}

catchError('asdf');
catchError('D!');
catchError('E#');
catchError('D#');
catchError('#');
catchError('b');
catchError('Kb');
catchError('Fb');
catchError('Ab');
catchError('Dbm');
catchError('B#m');

Flow.keySignature('B');
Flow.keySignature('C');
Flow.keySignature('Fm');
Flow.keySignature('Ab');
Flow.keySignature('Abm');
Flow.keySignature('F#');
Flow.keySignature('G#m');

ok(true, 'all pass');
},

keys(options: TestOptions, contextBuilder: ContextBuilder): void {
const clefs = [
'treble',
Expand Down
24 changes: 12 additions & 12 deletions tests/keysignature_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
//
// Key Signature Tests
//
// TODO: How is this different from key_clef_tests.ts?

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

// TODO: KeySignature.alterKey(alterKeySpec: string) should accept a string[] instead.
// TODO: Factory.KeySigNote() should take a Partial<T>, or allow cancelKey and alterKey to be optional.

import { VexFlowTests, TestOptions, MAJOR_KEYS, MINOR_KEYS } from './vexflow_test_helpers';
import { ContextBuilder } from 'renderer';
import { Flow } from 'flow';
Expand Down Expand Up @@ -104,30 +106,28 @@ const KeySignatureTests = {
for (i = 0; i < 8; ++i) {
keySig = new KeySignature(keys[i]);
keySig.cancelKey('Cb');

keySig.padding = 18;
keySig.setPadding(18);
keySig.addToStave(stave1);
}

for (n = 8; n < keys.length; ++n) {
keySig = new KeySignature(keys[n]);
keySig.cancelKey('C#');
keySig.padding = 20;
keySig.setPadding(20);
keySig.addToStave(stave2);
}

for (i = 0; i < 8; ++i) {
keySig = new KeySignature(keys[i]);
keySig.cancelKey('E');

keySig.padding = 18;
keySig.setPadding(18);
keySig.addToStave(stave3);
}

for (n = 8; n < keys.length; ++n) {
keySig = new KeySignature(keys[n]);
keySig.cancelKey('Ab');
keySig.padding = 20;
keySig.setPadding(20);
keySig.addToStave(stave4);
}

Expand All @@ -152,7 +152,7 @@ const KeySignatureTests = {
let y = 20;
let tx = x;
['bass', 'tenor', 'soprano', 'mezzo-soprano', 'baritone-f'].forEach(function (clef) {
keys.forEach(function (key) {
keys.forEach((key) => {
const cancelKey = key === keys[0] ? keys[1] : keys[0];
const stave = new Stave(tx, y, 350);
stave.setClef(clef);
Expand Down Expand Up @@ -184,28 +184,28 @@ const KeySignatureTests = {
for (i = 0; i < 8; ++i) {
keySig = new KeySignature(keys[i]);
keySig.alterKey(['bs', 'bs']);
keySig.padding = 18;
keySig.setPadding(18);
keySig.addToStave(stave1);
}

for (n = 8; n < keys.length; ++n) {
keySig = new KeySignature(keys[n]);
keySig.alterKey(['+', '+', '+']);
keySig.padding = 20;
keySig.setPadding(20);
keySig.addToStave(stave2);
}

for (i = 0; i < 8; ++i) {
keySig = new KeySignature(keys[i]);
keySig.alterKey(['n', 'bs', 'bb']);
keySig.padding = 18;
keySig.setPadding(18);
keySig.addToStave(stave3);
}

for (n = 8; n < keys.length; ++n) {
keySig = new KeySignature(keys[n]);
keySig.alterKey(['++', '+', 'n', '+']);
keySig.padding = 20;
keySig.setPadding(20);
keySig.addToStave(stave4);
}

Expand Down
22 changes: 11 additions & 11 deletions tests/tabslide_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { TabStave } from 'tabstave';
import { RenderContext, TieNotes } from 'types/common';
import { Voice } from 'voice';

const tabNote = (tab_struct: TabNoteStruct) => new TabNote(tab_struct);

const TabSlideTests = {
Start(): void {
QUnit.module('TabSlide');
Expand All @@ -26,16 +24,16 @@ const TabSlideTests = {

simple(options: TestOptions, contextBuilder: ContextBuilder): void {
options.contextBuilder = contextBuilder;
const c = setupContext(options);
const { stave, context } = setupContext(options);

tieNotes(
[
tabNote({ positions: [{ str: 4, fret: 4 }], duration: 'h' }),
tabNote({ positions: [{ str: 4, fret: 6 }], duration: 'h' }),
],
[0],
c.stave,
c.context
stave,
context
);
ok(true, 'Simple Test');
},
Expand All @@ -51,7 +49,8 @@ const TabSlideTests = {
},
};

// Helper Functions
//#region Helper Functions
const tabNote = (tab_struct: TabNoteStruct) => new TabNote(tab_struct);

function tieNotes(notes: TabNote[], indices: number[], stave: TabStave, ctx: RenderContext): void {
const voice = new Voice(Flow.TIME4_4);
Expand Down Expand Up @@ -86,7 +85,7 @@ function setupContext(options: TestOptions, width?: number): { context: RenderCo
return { context, stave };
}

function multiTest(options: TestOptions, tabSlideFactory: (notes: TieNotes) => TabSlide): void {
function multiTest(options: TestOptions, tabSlide: (notes: TieNotes) => TabSlide): void {
const c = setupContext(options, 440);

const notes = [
Expand Down Expand Up @@ -128,7 +127,7 @@ function multiTest(options: TestOptions, tabSlideFactory: (notes: TieNotes) => T
new Formatter().joinVoices([voice]).format([voice], 300);
voice.draw(c.context, c.stave);

tabSlideFactory({
tabSlide({
first_note: notes[0],
last_note: notes[1],
first_indices: [0],
Expand All @@ -139,7 +138,7 @@ function multiTest(options: TestOptions, tabSlideFactory: (notes: TieNotes) => T

ok(true, 'Single note');

tabSlideFactory({
tabSlide({
first_note: notes[2],
last_note: notes[3],
first_indices: [0, 1],
Expand All @@ -150,7 +149,7 @@ function multiTest(options: TestOptions, tabSlideFactory: (notes: TieNotes) => T

ok(true, 'Chord');

tabSlideFactory({
tabSlide({
first_note: notes[4],
last_note: notes[5],
first_indices: [0],
Expand All @@ -161,7 +160,7 @@ function multiTest(options: TestOptions, tabSlideFactory: (notes: TieNotes) => T

ok(true, 'Single note high-fret');

tabSlideFactory({
tabSlide({
first_note: notes[6],
last_note: notes[7],
first_indices: [0, 1],
Expand All @@ -172,5 +171,6 @@ function multiTest(options: TestOptions, tabSlideFactory: (notes: TieNotes) => T

ok(true, 'Chord high-fret');
}
//#endregion Helper Functions

export { TabSlideTests };
2 changes: 1 addition & 1 deletion tests/textbracket_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// TextBracket Tests

import { TestOptions, VexFlowTests } from './vexflow_test_helpers';
import { VexFlowTests, TestOptions } from './vexflow_test_helpers';

const TextBracketTests = {
Start(): void {
Expand Down

0 comments on commit 07be11f

Please sign in to comment.