<commit_before>"use strict";

var Path = require('path');

var fs = require("fs-promise");
//var semver = require('semver');
var BasicInterfaces = require("..");
var assert = require('self-explain').assert;
var assertCatch = require('self-explain').assertCatch;
var assertEql = function(a,b) {
    // el eval() es para que muestre los errores!
    eval(assert(! assert.allDifferences(a,b)));
}

describe("basic-interfaces", function(){
    var basicInterfaces = new BasicInterfaces({verbose:false});
    describe('typed', function(){
        it("accepts boolean values", function(){
            assert(basicInterfaces.boolean.control(true));
            assert(basicInterfaces.boolean.control(false));
            assert(basicInterfaces.boolean.nullable.control(null));
        });
        it("detect non boolean",function(){
            assertCatch(function(){
                basicInterfaces.boolean.control("ufs");
            },/BasicInterfaces non boolean value/);
        })
        it("detect non nullable",function(){
            assertCatch(function(){
                basicInterfaces.boolean.control(null);
            },/BasicInterfaces null value detected in boolean/);
        })
    });
    describe('plain', function(){
        it("accept ok", function(){
            assert(
                basicInterfaces.plain({
                    name:basicInterfaces.string,
                    age:basicInterfaces.number,
                    isChief:basicInterfaces.boolean.nullable,
                }).control({name:'Bob', age:42, isChief:false})
            );
        });
        it("detect bad attr type", function(){
            var plain=basicInterfaces.plain({
                    name:basicInterfaces.string,
                    age:basicInterfaces.number,
                    isChief:basicInterfaces.boolean.nullable,
                });
            assertCatch(function(){
                plain.control({name:'Bob', age:'42', isChief:false})
            },/BasicInterfaces has 1 error/);
            assertEql(plain.discrepances,[ 'string value detected in number in property \'age\'' ]);
        });
        it.skip("detect lack mandatory attr type", function(){
            assertCatch(function(){
                basicInterfaces.plain({
                    name:basicInterfaces.string,
                    age:basicInterfaces.number.nullable,
                    isChief:basicInterfaces.boolean.nullable,
                }).control({name:'Bob', age:12})
            },/BasicInterfaces lack of mandatory property 'isChief'/);
        });
        it.skip("detect extra attr", function(){
            assertCatch(function(){
                basicInterfaces.plain({
                    name:basicInterfaces.string,
                    age:basicInterfaces.number,
                    isChief:basicInterfaces.boolean.nullable,
                }).control({name:'Bob', age:42, ischief:true})
            },/BasicInterfaces unexpected property 'ischief'/);
        });
    });
});
<commit_msg>"detect lack mandatory attr type" rehabilitado<commit_after>"use strict";

var Path = require('path');

var fs = require("fs-promise");
//var semver = require('semver');
var BasicInterfaces = require("..");
var assert = require('self-explain').assert;
var assertCatch = require('self-explain').assertCatch;
var assertEql = function(a,b) {
    // el eval() es para que muestre los errores!
    eval(assert(! assert.allDifferences(a,b)));
}

describe("basic-interfaces", function(){
    var basicInterfaces = new BasicInterfaces({verbose:false});
    describe('typed', function(){
        it("accepts boolean values", function(){
            assert(basicInterfaces.boolean.control(true));
            assert(basicInterfaces.boolean.control(false));
            assert(basicInterfaces.boolean.nullable.control(null));
        });
        it("detect non boolean",function(){
            assertCatch(function(){
                basicInterfaces.boolean.control("ufs");
            },/BasicInterfaces non boolean value/);
        })
        it("detect non nullable",function(){
            assertCatch(function(){
                basicInterfaces.boolean.control(null);
            },/BasicInterfaces null value detected in boolean/);
        })
    });
    describe('plain', function(){
        var plain;
        it("accept ok", function(){
            assert(
                basicInterfaces.plain({
                    name:basicInterfaces.string,
                    age:basicInterfaces.number,
                    isChief:basicInterfaces.boolean.nullable,
                }).control({name:'Bob', age:42, isChief:false})
            );
        });
        it("detect bad attr type", function(){
            plain=basicInterfaces.plain({
                name:basicInterfaces.string,
                age:basicInterfaces.number,
                isChief:basicInterfaces.boolean.nullable,
            });
            assertCatch(function(){
                plain.control({name:'Bob', age:'42', isChief:false})
            },/BasicInterfaces has 1 error/);
            assertEql(plain.discrepances,[ 'string value detected in number in property \'age\'' ]);
        });
        it("detect lack mandatory attr type", function(){
            plain=basicInterfaces.plain({
                name:basicInterfaces.string,
                age:basicInterfaces.number.nullable,
                isChief:basicInterfaces.boolean.nullable,
            })
            assertCatch(function(){
                plain.control({name:'Bob', age:12})
            },/BasicInterfaces has 1 error/);
            assertEql(plain.discrepances,[ "lack of mandatory property 'isChief'" ]);
        });
        it.skip("detect extra attr", function(){
            assertCatch(function(){
                basicInterfaces.plain({
                    name:basicInterfaces.string,
                    age:basicInterfaces.number,
                    isChief:basicInterfaces.boolean.nullable,
                }).control({name:'Bob', age:42, ischief:true})
            },/BasicInterfaces unexpected property 'ischief'/);
        });
    });
});

{'fraction_non_alphanumeric': 0.13143231727302523, 'fraction_numerical': 0.0031137332022287776, 'mean_word_length': 2.0995429151853733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2039788', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1516, 'n_words': 296}