lex-model-validator
Version:
Validate lex-language-models with ease.
82 lines (81 loc) • 3.32 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var src_1 = require("../src");
var TestStatementMessagesValidator = /** @class */ (function (_super) {
__extends(TestStatementMessagesValidator, _super);
function TestStatementMessagesValidator() {
return _super !== null && _super.apply(this, arguments) || this;
}
TestStatementMessagesValidator.prototype.getConstraints = function () {
return {
messages: {
validate: src_1.VALIDATION_FUNCTION_STATEMENT_MESSAGES
}
};
};
return TestStatementMessagesValidator;
}(src_1.Validator));
// tslint:disable-next-line
var TestCheckDoublesValidator = /** @class */ (function (_super) {
__extends(TestCheckDoublesValidator, _super);
function TestCheckDoublesValidator() {
return _super !== null && _super.apply(this, arguments) || this;
}
TestCheckDoublesValidator.prototype.getConstraints = function () {
return {
stringValues: {
validate: src_1.VALIDATION_FUNCTION_CHECK_DUPLICATES
}
};
};
return TestCheckDoublesValidator;
}(src_1.Validator));
describe('test validation functions', function () {
describe('test statementMessage', function () {
var validator = new src_1.LexModelValidator([TestStatementMessagesValidator]);
test('test statementMessages succeeds', function () {
var json = {
messages: [{ contentType: 'test', content: 'testing' }]
};
expect(validator.validateJson(json)).toHaveLength(0);
});
test('test statementMessages fails', function () {
var json = {
messages: [
{ contentType: '', content: 'testing' },
{},
{ contentType: 'dasdas', content: '' }
]
};
expect(validator.validateJson(json)).not.toHaveLength(0);
});
});
describe('test checkDuplicates', function () {
var validator = new src_1.LexModelValidator([TestCheckDoublesValidator]);
test('test checkDuplicates succeeds', function () {
var json = {
stringValues: ['hello', 'test', 'should work']
};
expect(validator.validateJson(json)).toHaveLength(0);
});
test('test checkDuplicates fails', function () {
var json = {
stringValues: ['hello', 'test', 'should', 'not work', 'hello']
};
expect(validator.validateJson(json)).not.toHaveLength(0);
});
});
});