<commit_before>var examplesParser = require('../lib/parseXMLExamples');
var Example = require('docpack/lib/data/Example');
var ExampleFile = require('docpack/lib/data/ExampleFile');

function parse(input) {
  return examplesParser(input)[0];
}

function parseAndGetFirstFile(input) {
  return examplesParser(input)[0].files[0];
}

describe('xmlExampleParser', () => {

  it('should return empty array if no examples found', () => {
    var input = ['\n', '\n', '   ', '\n', '  \n'].join('');
    examplesParser(input).should.be.a('array').and.be.empty;

    input = 'var a = 123; <file></file>';
    examplesParser(input).should.be.a('array').and.be.empty;
  });

  describe('<example>', () => {
    it('should NOT skip empty <example> tags', () => {
      var input = '<example></example>';
      parse(input).should.be.instanceOf(Example);
    });

    it('should copy all <example> tag attributes to Example attrs', () => {
      var example = parse('<example attr1="value1" attr2="true" foo="false"></example>');
      example.attrs.should.be.deep.equal({
        attr1: 'value1', attr2: 'true', foo: 'false'
      })
    });
  });

  describe('<file>', () => {
    it('should NOT skip empty <file> tags', () => {
      var example = parse('<example><file></file></example>');
      example.files.should.be.a('array').and.be.lengthOf(1);
      example.files[0].should.be.instanceOf(ExampleFile);
    });

    it('should copy all <file> tag attributes to ExampleFile attrs', () => {
      var file = parseAndGetFirstFile('<example><file type="js" name="index.js" foo="false">c</file></example>');
      file.should.be.instanceOf(ExampleFile);
      file.attrs.should.be.deep.equal({
        type: 'js', name: 'index.js', foo: 'false'
      })
    });

    it('should not modify file content (strip indents only)', () => {
      var file = parseAndGetFirstFile('<example><file>\n  var foo = "bar<tag></tag>";\n\n</file></example>');
      file.content.should.be.a('string').and.eql('\nvar foo = "bar<tag></tag>";\n\n');
    });

    it('should allow < signs inside <file> tags', () => {
      var file = parseAndGetFirstFile('<example><file>for (var i = 0; i < length; i++) {}</file></example>');
      file.content.should.be.a('string').and.eql('for (var i = 0; i < length; i++) {}');
    });

    it('should treat file type as "js" by default', () => {
      var file = parseAndGetFirstFile('<example><file>var a = 123;</file></example>');
      file.type.should.be.eql('js');
    });

    it('should detect file type by type attr', () => {
      var file = parseAndGetFirstFile('<example><file type="js" name="index.html">c</file></example>');
      file.type.should.be.eql('js');
    });
  });
});<commit_msg>Add some tests to check content property of Example<commit_after>var examplesParser = require('../lib/parseXMLExamples');
var Example = require('docpack/lib/data/Example');
var ExampleFile = require('docpack/lib/data/ExampleFile');

function parse(input) {
  return examplesParser(input)[0];
}

function parseAndGetFirstFile(input) {
  return examplesParser(input)[0].files[0];
}

describe('xmlExampleParser', () => {

  it('should return empty array if no examples found', () => {
    var input = ['\n', '\n', '   ', '\n', '  \n'].join('');
    examplesParser(input).should.be.a('array').and.be.empty;

    input = 'var a = 123; <file></file>';
    examplesParser(input).should.be.a('array').and.be.empty;
  });

  describe('<example>', () => {
    it('should NOT skip empty <example> tags', () => {
      var input = '<example></example>';
      var example = parse(input);
      example.should.be.instanceOf(Example);
      example.should.have.a.property('content').and.equal('');
    });

    it('should copy all <example> tag attributes to Example attrs', () => {
      var example = parse('<example attr1="value1" attr2="true" foo="false"></example>');
      example.should.have.a.property('content').and.equal('');
      example.attrs.should.be.deep.equal({
        attr1: 'value1', attr2: 'true', foo: 'false'
      })
    });
  });

  describe('<file>', () => {
    it('should NOT skip empty <file> tags', () => {
      var example = parse('<example><file></file></example>');
      example.should.have.a.property('content').and.equal('<file></file>');
      example.files.should.be.a('array').and.be.lengthOf(1);
      example.files[0].should.be.instanceOf(ExampleFile);
    });

    it('should copy all <file> tag attributes to ExampleFile attrs', () => {
      var file = parseAndGetFirstFile('<example><file type="js" name="index.js" foo="false">c</file></example>');
      file.should.be.instanceOf(ExampleFile);
      file.attrs.should.be.deep.equal({
        type: 'js', name: 'index.js', foo: 'false'
      })
    });

    it('should not modify file content (strip indents only)', () => {
      var file = parseAndGetFirstFile('<example><file>\n  var foo = "bar<tag></tag>";\n\n</file></example>');
      file.content.should.be.a('string').and.eql('\nvar foo = "bar<tag></tag>";\n\n');
    });

    it('should allow < signs inside <file> tags', () => {
      var file = parseAndGetFirstFile('<example><file>for (var i = 0; i < length; i++) {}</file></example>');
      file.content.should.be.a('string').and.eql('for (var i = 0; i < length; i++) {}');
    });

    it('should treat file type as "js" by default', () => {
      var file = parseAndGetFirstFile('<example><file>var a = 123;</file></example>');
      file.type.should.be.eql('js');
    });

    it('should detect file type by type attr', () => {
      var file = parseAndGetFirstFile('<example><file type="js" name="index.html">c</file></example>');
      file.type.should.be.eql('js');
    });
  });
});
{'fraction_non_alphanumeric': 0.2172310931742411, 'fraction_numerical': 0.006667836462537287, 'mean_word_length': 3.505928853754941, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6888058', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1806, 'n_words': 362}