UNPKG

satie

Version:

A sheet music renderer for the web

217 lines (216 loc) 8.46 kB
/** * @source: https://github.com/jnetterf/satie/ * * @license * (C) Josh Netterfield <joshua@nettek.ca> 2015. * Part of the Satie music engraver <https://github.com/jnetterf/satie>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ "use strict"; /** * @file part of Satie test suite */ var musicxml_interfaces_1 = require("musicxml-interfaces"); var lodash_1 = require("lodash"); var chai_1 = require("chai"); var document_1 = require("../document"); var private_lineBounds_1 = require("../private_lineBounds"); var etestutil_1 = require("./etestutil"); var engine_processors_validate_1 = require("../engine_processors_validate"); describe("[engine.ts]", function () { describe("Options.ILineBounds.calculate", function () { it("works", function () { var spec1 = { measureNumbering: { data: "system" }, partNameDisplay: null, newSystem: null, newPage: null, blankPage: null, measureLayout: null, partAbbreviationDisplay: null, staffSpacing: null, staffLayouts: null, pageNumber: "1", systemLayout: { systemMargins: { leftMargin: 0, rightMargin: 0 } }, pageLayout: { pageHeight: 1000, pageWidth: 1000, pageMargins: [ { bottomMargin: 10, leftMargin: 11, rightMargin: 12, topMargin: 13, type: musicxml_interfaces_1.OddEvenBoth.Odd }, { bottomMargin: 10, leftMargin: 21, rightMargin: 22, topMargin: 13, type: musicxml_interfaces_1.OddEvenBoth.Even } ] } }; chai_1.expect(private_lineBounds_1.calculateLineBounds(spec1, 1, { millimeters: 10, tenths: 40 })).to.deep.equal({ left: 11, right: 1000 - 12, systemLayout: { systemMargins: { leftMargin: 0, rightMargin: 0 } } }); chai_1.expect(private_lineBounds_1.calculateLineBounds(spec1, 2, { millimeters: 10, tenths: 40 })).to.deep.equal({ left: 21, right: 1000 - 22, systemLayout: { systemMargins: { leftMargin: 0, rightMargin: 0 } } }); }); }); describe("validate", function () { it("creates attributes and barline if missing", function () { var calledCount = 0; var createAttributesChordFactory = { create: function (modelType) { ++calledCount; return { divCount: 0, staffIdx: 1, refresh: function (cursor) { }, getLayout: function (cursor) { throw "not reached"; }, calcWidth: function () { return 0; }, }; }, modelHasType: function (model) { var modelTypes = []; for (var _i = 1; _i < arguments.length; _i++) { modelTypes[_i - 1] = arguments[_i]; } var modelType = modelTypes[0]; if (model.divCount === 0) { return modelType === document_1.Type.Attributes; } else if ("length" in model) { return modelType === document_1.Type.Chord; } return modelType === document_1.Type.Spacer; }, search: function (models, idx, modelType) { var model = models[idx]; if (model.divCount === 0) { if (modelType === document_1.Type.Attributes) { return [model]; } else { return []; } } if (modelType === document_1.Type.Chord) { return [model]; } else { return []; } }, fromSpec: function (model) { return createAttributesChordFactory.create(document_1.Type[model._class]); } }; var padding = 20; var segments = [{ staves: [null, etestutil_1.createFakeStaffSegment(4, 4, 1)], voices: [ null, etestutil_1.createFakeVoiceSegment(2, 6, 1), etestutil_1.createFakeVoiceSegment(1, 7, 2) ] }]; var contextOptions = { document: { modelHasType: createAttributesChordFactory.modelHasType, __fakeDocument: true }, preview: false, fixup: null, lineCount: 0, lineIndex: 0, singleLineMode: false, attributes: null, measures: lodash_1.map(segments, function (segment, idx) { return { idx: idx, uuid: 91015 + idx, number: String(idx + 1), version: 0, parts: { "P1": { voices: segment.voices, staves: segment.staves } } }; }), header: null, print: { measureNumbering: null, blankPage: null, partNameDisplay: null, newSystem: null, newPage: null, measureLayout: null, partAbbreviationDisplay: null, pageNumber: null, staffLayouts: null, staffSpacing: null, systemLayout: null, pageLayout: { pageHeight: 1000, pageWidth: 1000, pageMargins: [{ leftMargin: padding, rightMargin: padding, bottomMargin: padding, topMargin: padding, type: musicxml_interfaces_1.OddEvenBoth.Both }] } }, modelFactory: createAttributesChordFactory, preprocessors: [], postprocessors: [] }; contextOptions.document.measures = contextOptions.measures; engine_processors_validate_1.default(contextOptions); chai_1.expect(calledCount).to.equal(2); }); }); });