<commit_before>'use strict';

var parser = require('../../lib/iodef')
  , ltx    = require('ltx')

parser.setLogger({
    log: function() {},
    info: function() {},
    warn: function() {},
    error: function() {}
})

describe('Parsing \'IODEF\'', function() {

    var IODEF_DOC_START = '<IODEF-Document version="' + parser.VERSION_IODEF + '" xmlns="' + parser.NS_IODEF + '">'
    var IODEF_DOC_END = '</IODEF-Document>'
    var IODEF_INCIDENT_START = '<Incident purpose="reporting">'
    var IODEF_INCIDENT_END = '</Incident>'

    it('Shouldn\'t act if no IODEF namespace', function() {
        var entity = { not: 'empty' }
        var item   = ltx.parse('<IODEF-Document/>')
        parser.parse(item, entity)
        entity.should.eql({ not: 'empty' })
    })

    it('Shouldn\'t act if incorrect IODEF version', function() {
        var entity = { not: 'empty' }
        var item   = ltx.parse('<IODEF-Document version="0.00" xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity.should.eql({ not: 'empty' })
    })

    it('Adds version attribute to IODEF-Document', function() {
        var entity = {}
        var item   = ltx.parse('<IODEF-Document ' +
                                    'version="' + parser.VERSION_IODEF + '" ' +
                                    'xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({ version : parser.VERSION_IODEF})
    })

    it('Adds lang attribute to IODEF-Document', function() {
        var entity = {}
        var item   = ltx.parse('<IODEF-Document  ' +
                                    'version="' + parser.VERSION_IODEF + '"  ' +
                                    'lang="en"  ' +
                                    'xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({ version : parser.VERSION_IODEF, lang : 'en'})
    })

    it('Adds formatid attribute to IODEF-Document', function() {
        var entity = {}
        var item   = ltx.parse('<IODEF-Document  ' +
                                    'version="' + parser.VERSION_IODEF + '"  ' +
                                    'formatid="simulation"  ' +
                                    'xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({ version : parser.VERSION_IODEF, formatid : 'simulation'})
    })

    describe('Parsing Incident within \'IODEF\'', function() {

        it('Adds Incident', function() {
            var entity = {}
            var item = ltx.parse(
                IODEF_DOC_START +
                  '<Incident/>' +
                IODEF_DOC_END
            )
            parser.parse(item, entity)
            entity['IODEF-Document'].should.eql({version : parser.VERSION_IODEF, Incidents : [{}]})
        })

        it('Adds multiple Incidents', function() {
            var entity = {}
            var item = ltx.parse(
                IODEF_DOC_START +
                  '<Incident/>' +
                  '<Incident/>' +
                IODEF_DOC_END
            )
            parser.parse(item, entity)<commit_msg>Added a test for parsing IODEF wrapped in another element<commit_after>'use strict';

var parser = require('../../lib/iodef')
  , ltx    = require('ltx')

parser.setLogger({
    log: function() {},
    info: function() {},
    warn: function() {},
    error: function() {}
})

describe('Parsing \'IODEF\'', function() {

    var IODEF_DOC_START = '<IODEF-Document version="' + parser.VERSION_IODEF + '" xmlns="' + parser.NS_IODEF + '">'
    var IODEF_DOC_END = '</IODEF-Document>'
    var IODEF_INCIDENT_START = '<Incident purpose="reporting">'
    var IODEF_INCIDENT_END = '</Incident>'

    it('Shouldn\'t act if no IODEF namespace', function() {
        var entity = { not: 'empty' }
        var item   = ltx.parse('<IODEF-Document/>')
        parser.parse(item, entity)
        entity.should.eql({ not: 'empty' })
    })

    it('Shouldn\'t act if incorrect IODEF version', function() {
        var entity = { not: 'empty' }
        var item   = ltx.parse('<IODEF-Document version="0.00" xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity.should.eql({ not: 'empty' })
    })

    it('Adds version attribute to IODEF-Document', function() {
        var entity = {}
        var item   = ltx.parse('<IODEF-Document ' +
                                    'version="' + parser.VERSION_IODEF + '" ' +
                                    'xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({ version : parser.VERSION_IODEF})
    })

    it('Adds lang attribute to IODEF-Document', function() {
        var entity = {}
        var item   = ltx.parse('<IODEF-Document  ' +
                                    'version="' + parser.VERSION_IODEF + '"  ' +
                                    'lang="en"  ' +
                                    'xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({ version : parser.VERSION_IODEF, lang : 'en'})
    })

    it('Adds formatid attribute to IODEF-Document', function() {
        var entity = {}
        var item   = ltx.parse('<IODEF-Document  ' +
                                    'version="' + parser.VERSION_IODEF + '"  ' +
                                    'formatid="simulation"  ' +
                                    'xmlns="' + parser.NS_IODEF + '"/>')
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({ version : parser.VERSION_IODEF, formatid : 'simulation'})
    })

    it('Should parse IODEF if wrapped in another element', function() {
        var entity = {}
        var item = ltx.parse(
            '<item>' +
                IODEF_DOC_START +
                IODEF_DOC_END +
            '</item>'
        )
        parser.parse(item, entity)
        entity['IODEF-Document'].should.eql({version : parser.VERSION_IODEF})
    })

    describe('Parsing Incident within \'IODEF\'', function() {

        it('Adds Incident', function() {
            var entity = {}
            var item = ltx.parse(
                IODEF_DOC_START +
                  '<Incident/>' +
                IODEF_DOC_END
            )
            parser.parse(item, entity)
            entity['IODEF-Document'].should.eql({version : parser.VERSION_IODEF, Incidents : [{}]})
        })

        it('Adds multiple Incidents', function() {
            var entity = {}
            var item = ltx.parse(
                IODEF_DOC_START +
                  '<Incident/>' +
                  '<Incident/>' +
                IODEF_DOC_END
            )
            parser.parse(item, entity)
{'fraction_non_alphanumeric': 0.1511013215859031, 'fraction_numerical': 0.000881057268722467, 'mean_word_length': 1.7244, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4466690', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1942, 'n_words': 388}