<commit_before>var FieldVal = require('../fieldval');
var BasicVal = FieldVal.BasicVal;
var DateVal = FieldVal.DateVal;
var assert = require("assert")

describe('DateVal', function() {
    describe('date()', function() {
        it('should return a date string when a string of valid syntax is present', function() {
            var my_validator = new FieldVal({
                "my_date_1": "04/07/2014",
                "my_date_2": "1/2/34",
                "my_date_3": "1-2-34",
                "my_date_4": "29:2",
                "my_date_5": "2014 05 27",
                "my_date_6": "07/30/14",
                "my_date_7": "30/07/14",
                "my_date_8": "29/02/04",
                "my_date_9": "29/05/2014 15:45:12"
            })

            assert.equal("04/07/2014", my_validator.get("my_date_1", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal("1/2/34", my_validator.get("my_date_2", BasicVal.string(true), DateVal.date("d/M/yy")));
            assert.equal("1-2-34", my_validator.get("my_date_3", BasicVal.string(true), DateVal.date("d-M-yy")));
            assert.equal("29:2", my_validator.get("my_date_4", BasicVal.string(true), DateVal.date("d:M")));
            assert.equal("2014 05 27", my_validator.get("my_date_5", BasicVal.string(true), DateVal.date("yyyy MM dd")));
            assert.equal("07/30/14", my_validator.get("my_date_6", BasicVal.string(true), DateVal.date("MM/dd/yy")));
            assert.equal("30/07/14", my_validator.get("my_date_7", BasicVal.string(true), DateVal.date("dd/MM/yy")));
            assert.equal("29/02/04", my_validator.get("my_date_8", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal("29/05/2014 15:45:12", my_validator.get("my_date_9", BasicVal.string(true), DateVal.date("dd/MM/yyyy hh:mm:ss")));
            assert.equal(null, my_validator.end());
        }) 

        it('should return errors when strings of invalid syntax are present', function() {
            var my_validator = new FieldVal({
                "my_date_1": "04/",
                "my_date_2": "1/2/",
                "my_date_3": "1-",
                "my_date_4": "29::",
                "my_date_5": "2014  ",
                "my_date_6": "07",
                "my_date_7": "a",
                "my_date_8": "()",
                "my_date_9": "-:/ "
            })

            assert.equal(undefined, my_validator.get("my_date_1", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal(undefined, my_validator.get("my_date_2", BasicVal.string(true), DateVal.date("d/M/yy")));
            assert.equal(undefined, my_validator.get("my_date_3", BasicVal.string(true), DateVal.date("d-M-yy")));
            assert.equal(undefined, my_validator.get("my_date_4", BasicVal.string(true), DateVal.date("d:M")));
            assert.equal(undefined, my_validator.get("my_date_5", BasicVal.string(true), DateVal.date("yyyy MM dd")));
            assert.equal(undefined, my_validator.get("my_date_6", BasicVal.string(true), DateVal.date("MM/dd/yy")));
            assert.equal(undefined, my_validator.get("my_date_7", BasicVal.string(true), DateVal.date("dd/MM/yy")));
            assert.equal(undefined, my_validator.get("my_date_8", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal(undefined, my_validator.get("my_date_9", BasicVal.string(true), DateVal.date("dd/MM/yyyy hh:mm:ss")));
            assert.deepEqual({
                "invalid": {
                    "my_date_1": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_2": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_3": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_4": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_5": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_6": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_7": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_8": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_9": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    }
                },
                "error_message": "One or more errors.",
                "error": 5
            }, my_validator.end());
        }) 
    })

    describe('date_format()', function() {
        it('should return a date format array when a valid string is provided', function() {
            var my_validator = new FieldVal({
                "my_format": "yyyy-MM-dd"
            })
            assert.deepEqual(["yyyy","-","MM","-","dd"], my_validator.get("my_format", BasicVal.string(true), DateVal.date_format()));
            assert.equal(null, my_validator.end());
        })
    })

    describe('date_with_format_array()', function() {
        it('should return a string of the provided date formatted with the provided format array', function() {
            <commit_msg>Added DateVal test for day zero paddng bug<commit_after>var FieldVal = require('../fieldval');
var BasicVal = FieldVal.BasicVal;
var DateVal = FieldVal.DateVal;
var assert = require("assert")

describe('DateVal', function() {
    describe('date()', function() {
        it('should return a date string when a string of valid syntax is present', function() {
            var my_validator = new FieldVal({
                "my_date_1": "04/07/2014",
                "my_date_2": "1/2/34",
                "my_date_3": "1-2-34",
                "my_date_4": "29:2",
                "my_date_5": "2014 05 27",
                "my_date_6": "07/30/14",
                "my_date_7": "30/07/14",
                "my_date_8": "29/02/04",
                "my_date_9": "29/05/2014 15:45:12",
            })

            assert.equal("04/07/2014", my_validator.get("my_date_1", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal("1/2/34", my_validator.get("my_date_2", BasicVal.string(true), DateVal.date("d/M/yy")));
            assert.equal("1-2-34", my_validator.get("my_date_3", BasicVal.string(true), DateVal.date("d-M-yy")));
            assert.equal("29:2", my_validator.get("my_date_4", BasicVal.string(true), DateVal.date("d:M")));
            assert.equal("2014 05 27", my_validator.get("my_date_5", BasicVal.string(true), DateVal.date("yyyy MM dd")));
            assert.equal("07/30/14", my_validator.get("my_date_6", BasicVal.string(true), DateVal.date("MM/dd/yy")));
            assert.equal("30/07/14", my_validator.get("my_date_7", BasicVal.string(true), DateVal.date("dd/MM/yy")));
            assert.equal("29/02/04", my_validator.get("my_date_8", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal("29/05/2014 15:45:12", my_validator.get("my_date_9", BasicVal.string(true), DateVal.date("dd/MM/yyyy hh:mm:ss")));
            assert.equal(null, my_validator.end());
        }) 

        it('should return errors when strings of invalid syntax are present', function() {
            var my_validator = new FieldVal({
                "my_date_1": "04/",
                "my_date_2": "1/2/",
                "my_date_3": "1-",
                "my_date_4": "29::",
                "my_date_5": "2014  ",
                "my_date_6": "07",
                "my_date_7": "a",
                "my_date_8": "()",
                "my_date_9": "-:/ ",
                "my_date_10": "2012-12-2"
            })

            assert.equal(undefined, my_validator.get("my_date_1", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal(undefined, my_validator.get("my_date_2", BasicVal.string(true), DateVal.date("d/M/yy")));
            assert.equal(undefined, my_validator.get("my_date_3", BasicVal.string(true), DateVal.date("d-M-yy")));
            assert.equal(undefined, my_validator.get("my_date_4", BasicVal.string(true), DateVal.date("d:M")));
            assert.equal(undefined, my_validator.get("my_date_5", BasicVal.string(true), DateVal.date("yyyy MM dd")));
            assert.equal(undefined, my_validator.get("my_date_6", BasicVal.string(true), DateVal.date("MM/dd/yy")));
            assert.equal(undefined, my_validator.get("my_date_7", BasicVal.string(true), DateVal.date("dd/MM/yy")));
            assert.equal(undefined, my_validator.get("my_date_8", BasicVal.string(true), DateVal.date("dd/MM/yyyy")));
            assert.equal(undefined, my_validator.get("my_date_9", BasicVal.string(true), DateVal.date("dd/MM/yyyy hh:mm:ss")));
            assert.equal(undefined, my_validator.get("my_date_10", BasicVal.string(true), DateVal.date("yyyy-MM-dd")));
            assert.deepEqual({
                "invalid": {
                    "my_date_1": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_2": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_3": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_4": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_5": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_6": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_7": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_8": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_9": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    },
                    "my_date_10": {
                        "error": 111,
                        "error_message": "Invalid date format."
                    }
                },
                "error_message": "One or more errors.",
                "error": 5
            }, my_validator.end());
        }) 
    })

    describe('date_format()', function() {
        it('should return a date format array when a valid string is provided', function() {
            var my_validator = new FieldVal({
                "my_format": "yyyy-MM-dd"
            })
            assert.deepEqual(["yyyy","-","MM","-","dd"], my_validator.get("my_format", BasicVal.string(true), DateVal.date_format()));
            assert.equal(null, my_validator.end());
        })
    })

    describe('date_with_format_array()', function() {
        it('should return a string of the provided date formatted with the provided format array', function() {
            
{'fraction_non_alphanumeric': 0.15661528036591563, 'fraction_numerical': 0.035913942063357615, 'mean_word_length': 1.7130055147058822, 'pattern_counts': {'":': 102, '<': 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': '4379267', 'n_tokens_mistral': 3753, 'n_tokens_neox': 3457, 'n_words': 592}