<commit_before>var vows = require('vows'),
    assert = require('assert'); 

vows.describe('Pattern').addBatch({
    'Pattern provides': {
        topic: require('__internal/pattern'),
        'the parse method': function (topic) {
          assert.isFunction(topic.parse);
        }
    },
    'Pattern can parse': {
        topic: require('__internal/pattern'),
        'a single byte pattern': function (topic) {
            var field = topic.parse('n8');
            assert.deepEqual(field, [
                { signed: false
                , bits: 8
                , endianness: 'b'
                , bytes: 1
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single signed byte pattern': function (topic) {
            var field = topic.parse('-n8');
            assert.deepEqual(field, [
                { signed: true
                , bits: 8
                , endianness: 'b'
                , bytes: 1
                , type: 'n'
                , arrayed: true
                }
            ]);
        },
        'a single 16 bit number pattern': function (topic) {
            var field = topic.parse('n16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'b'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single signed 16 bit number pattern': function (topic) {
            var field = topic.parse('-n16');
            assert.deepEqual(field, [
                { signed: true
                , bits: 16
                , endianness: 'b'
                , bytes: 2
                , type: 'n'
                , arrayed: true
                }
            ]);
        },
        'a single big-endian 16 bit number pattern': function (topic) {
            var field = topic.parse('b16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'b'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single little-endian 16 bit number pattern': function (topic) {
            var field = topic.parse('l16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'l'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single signed little-endian 16 bit number pattern': function (topic) {
            var field = topic.parse('-l16');
            assert.deepEqual(field, [
              { signed: true
              , bits: 16
              , endianness: 'l'
              , bytes: 2
              , type: 'n'
              , arrayed: true
              }
            ]);
        },
        'a single 16 bit skip pattern': function (topic) {
            var field = topic.parse('s16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 's'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a signed little-endian 16 bit number followed by a byte pattern': function (topic) {
            var field = topic.parse('-l16n8');
            assert.deepEqual(field,
            [
                { signed: true
                , bits: 16
                , endianness: 'l'
                , bytes: 2
                , type: 'n'
                , arrayed: true
                }
            , 
                { signed: false
                , bits: 8
                , endianness: 'b'
                , bytes: 1
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a 16 bit hex string.': function (topic) {
            var field = topic.parse('l16h');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'l'
                , bytes: 2
                , type: 'h'
                , arrayed: true
                }
            ]);
        },
        'a single 32 bit float pattern.': function (topic) {
            var field = topic.parse('b32f');
            assert.deepEqual(field, [
                { signed: true
                , bits: 32
                , endianness: 'b'
                , bytes: 4
                , type: 'f'
                , arrayed: true
                }
            ]);
        },
        'a single 64 bit float pattern.': function (topic) {
            var field = topic.parse('b64f');
            assert.deepEqual(field, [
                { signed: true
                , bits: 64
                , endianness: 'b'
                , bytes: 8
                , type: 'f'
                , arrayed: true
                }
            ]);
        }
    },
    'Pattern cannot parse': {
        topic: require('__internal/pattern'),
        'a 7 bit pattern.': function (topic) {
            assert.throws(function () {
                topic.parse("b7");   
            }, Error);
        },
        'a float pattern other than 32 or 64 bits.': function (topic) {
            assert.throws(function () {
                topic.parse('b16f');
            }, Error);
        }
    }
}).export(module);

/* vim: set ts=2 sw=2 et tw=0: */<commit_msg>Two new parse failure tests.<commit_after>var vows = require('vows'),
    assert = require('assert'); 

vows.describe('Pattern').addBatch({
    'Pattern provides': {
        topic: require('__internal/pattern'),
        'the parse method': function (topic) {
          assert.isFunction(topic.parse);
        }
    },
    'Pattern can parse': {
        topic: require('__internal/pattern'),
        'a single byte pattern': function (topic) {
            var field = topic.parse('n8');
            assert.deepEqual(field, [
                { signed: false
                , bits: 8
                , endianness: 'b'
                , bytes: 1
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single signed byte pattern': function (topic) {
            var field = topic.parse('-n8');
            assert.deepEqual(field, [
                { signed: true
                , bits: 8
                , endianness: 'b'
                , bytes: 1
                , type: 'n'
                , arrayed: true
                }
            ]);
        },
        'a single 16 bit number pattern': function (topic) {
            var field = topic.parse('n16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'b'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single signed 16 bit number pattern': function (topic) {
            var field = topic.parse('-n16');
            assert.deepEqual(field, [
                { signed: true
                , bits: 16
                , endianness: 'b'
                , bytes: 2
                , type: 'n'
                , arrayed: true
                }
            ]);
        },
        'a single big-endian 16 bit number pattern': function (topic) {
            var field = topic.parse('b16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'b'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single little-endian 16 bit number pattern': function (topic) {
            var field = topic.parse('l16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'l'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a single signed little-endian 16 bit number pattern': function (topic) {
            var field = topic.parse('-l16');
            assert.deepEqual(field, [
              { signed: true
              , bits: 16
              , endianness: 'l'
              , bytes: 2
              , type: 'n'
              , arrayed: true
              }
            ]);
        },
        'a single 16 bit skip pattern': function (topic) {
            var field = topic.parse('s16');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 's'
                , bytes: 2
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a signed little-endian 16 bit number followed by a byte pattern': function (topic) {
            var field = topic.parse('-l16n8');
            assert.deepEqual(field,
            [
                { signed: true
                , bits: 16
                , endianness: 'l'
                , bytes: 2
                , type: 'n'
                , arrayed: true
                }
            , 
                { signed: false
                , bits: 8
                , endianness: 'b'
                , bytes: 1
                , type: 'n'
                , arrayed: false
                }
            ]);
        },
        'a 16 bit hex string.': function (topic) {
            var field = topic.parse('l16h');
            assert.deepEqual(field, [
                { signed: false
                , bits: 16
                , endianness: 'l'
                , bytes: 2
                , type: 'h'
                , arrayed: true
                }
            ]);
        },
        'a single 32 bit float pattern.': function (topic) {
            var field = topic.parse('b32f');
            assert.deepEqual(field, [
                { signed: true
                , bits: 32
                , endianness: 'b'
                , bytes: 4
                , type: 'f'
                , arrayed: true
                }
            ]);
        },
        'a single 64 bit float pattern.': function (topic) {
            var field = topic.parse('b64f');
            assert.deepEqual(field, [
                { signed: true
                , bits: 64
                , endianness: 'b'
                , bytes: 8
                , type: 'f'
                , arrayed: true
                }
            ]);
        }
    },
    'Pattern cannot parse': {
        topic: require('__internal/pattern'),
        'utter nonsense.': function (topic) {
            assert.throws(function () {
                topic.parse("blurdy");   
            }, Error);
        },
        'a 7 bit pattern.': function (topic) {
            assert.throws(function () {
                topic.parse("b7");   
            }, Error);
        },
        'a 0 bit pattern.': function (topic) {
            assert.throws(function () {
                topic.parse("b0");   
            }, Error);
        },
        'a float pattern other than 32 or 64 bits.': function (topic) {
            assert.throws(function () {
                topic.parse('b16f');
            }, Error);
        }
    }
}).export(module);

/* vim: set ts=2 sw=2 et tw=0: */
{'fraction_non_alphanumeric': 0.1145979020979021, 'fraction_numerical': 0.015909090909090907, 'mean_word_length': 0.9384954252795662, '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': '1418330', 'n_tokens_mistral': 3189, 'n_tokens_neox': 2862, 'n_words': 746}