all files / dist/ StateTestRunnerGenerator.js

100% Statements 27/27
100% Branches 4/4
100% Functions 9/9
100% Lines 27/27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74                          10× 10×                   13× 13×   13× 13×       10×           10×           10×           10× 10×            
"use strict";
var typeInfo = require("ts-type-info");
var StateTestRunnerGenerator = (function () {
    /* istanbul ignore next */ function StateTestRunnerGenerator() {
    }
    StateTestRunnerGenerator.prototype.fillTestFile = function (testFile, structures) {
        var stateTestRunner = testFile.addClass({
            name: "StateTestRunner",
            isExported: true,
            constructorDef: {
                parameters: [{
                        name: "factory",
                        type: "TestRunnerFactory",
                        isReadonly: true,
                        scope: typeInfo.ClassConstructorParameterScope.Private
                    }]
            }
        });
        var _loop_1 = function (structure) {
            var typeParameters = structure.getTypeParameters();
            var method = stateTestRunner.addMethod({
                name: "run" + structure.getName() + "Test",
                parameters: [{
                        name: "actual",
                        type: structure.getNameWithTypeParameters()
                    }, {
                        name: "expected",
                        type: structure.getTestStructureNameWithTypeParameters()
                    }],
                onWriteFunctionBody: function (methodWriter) {
                    methodWriter.write("const testRunner = this.factory.get" + structure.getName() + "TestRunner(");
                    typeParameters.forEach(function (typeParam, i) {
                        methodWriter.conditionalWrite(i !== 0, ", ");
                        methodWriter.write(typeParam.getName() + "TestRunner");
                    });
                    methodWriter.write(");").newLine();
                    methodWriter.writeLine("testRunner.runTest(actual, expected);");
                }
            });
            // add type parameters for actual
            typeParameters.forEach(function (typeParam) {
                var constraintType = typeParam.getConstraintType();
                method.addTypeParameter({
                    name: typeParam.getName(),
                    constraintType: constraintType == null ? undefined : constraintType.getText()
                });
            });
            // add type parameters for expected
            typeParameters.forEach(function (typeParam) {
                var constraintType = typeParam.getConstraintType();
                method.addTypeParameter({
                    name: typeParam.getTestStructureName(),
                    constraintType: constraintType == null ? undefined : constraintType.getTestStructureName()
                });
            });
            // add type parameters to method
            typeParameters.forEach(function (typeParam) {
                method.addParameter({
                    name: typeParam.getName() + "TestRunner",
                    type: "TestRunner<" + typeParam.getName() + ", " + typeParam.getTestStructureName() + ">"
                });
            });
        };
        for (var _i = 0, structures_1 = structures; _i < structures_1.length; _i++) {
            var structure = structures_1[_i];
            _loop_1(structure);
        }
    };
    return StateTestRunnerGenerator;
}());
exports.StateTestRunnerGenerator = StateTestRunnerGenerator;
 
//# sourceMappingURL=StateTestRunnerGenerator.js.map