"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
|