<commit_before>'use strict';

var expect = require('chai').expect;
var parser = require('../');

// var a = parser.parse('//top\n{// top a\n/* abc */"a":1,//right\n/* bcd */"b":{"a":1}}//bottom');
// // var a = parser.parse('{/*top*/"a":1,//right\n/*abc*/"b":{"a":1}}');
// console.log(a);

var cases = [
  {
    d: 'comment at the top',
    s: '//top\n{"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//^']).to.deep.equal(['//top']);
    }
  },
  {
    d: 'multiple comments at the top, both line and block',
    s: '//top\n/*abc*/{"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//^']).to.deep.equal(['//top', '/*abc*/']);
    }
  },
  {
    d: 'comment at the bottom',
    s: '{"a":1}\n//bot',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//$']).to.deep.equal(['//bot']);
    }
  },
  {
    d: 'multiple comments at the bottom, both line and block',
    s: '{"a":1}\n//top\n/*abc*/',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//$']).to.deep.equal(['//top', '/*abc*/']);
    }
  },
  {
    d: 'comment for properties',
    s: '{//a\n"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect('// a' in obj).to.equal(true);
      expect(obj['// a']).to.deep.equal([['//a']]);
    }
  },
  {
    d: 'comment for properties, multiple at the top',
    s: '{//a\n/*b*/"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect('// a' in obj).to.equal(true);
      expect(obj['// a']).to.deep.equal([['//a', '/*b*/']]);
    }
  },
  {
    d: 'comment for properties, both top and right',
    s: '{//a\n"a":1//b\n}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect('// a' in obj).to.equal(true);
      expect(obj['// a']).to.deep.equal([['//a'], ['//b']]);
    }
  }
]

describe("parse()", function(){
  cases.forEach(function (c) {
    it(c.d, function(){
      c.e(parser.parse(c.s));
    });
  });
});<commit_msg>adds test cases for error messages; fixes #1; actually comment-json already throw the same error messages as JSON.parse<commit_after>'use strict';

var expect = require('chai').expect;
var parser = require('../');

// var a = parser.parse('//top\n{// top a\n/* abc */"a":1,//right\n/* bcd */"b":{"a":1}}//bottom');
// // var a = parser.parse('{/*top*/"a":1,//right\n/*abc*/"b":{"a":1}}');
// console.log(a);

var cases = [
  {
    d: 'comment at the top',
    s: '//top\n{"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//^']).to.deep.equal(['//top']);
    }
  },
  {
    d: 'multiple comments at the top, both line and block',
    s: '//top\n/*abc*/{"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//^']).to.deep.equal(['//top', '/*abc*/']);
    }
  },
  {
    d: 'comment at the bottom',
    s: '{"a":1}\n//bot',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//$']).to.deep.equal(['//bot']);
    }
  },
  {
    d: 'multiple comments at the bottom, both line and block',
    s: '{"a":1}\n//top\n/*abc*/',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect(obj['//$']).to.deep.equal(['//top', '/*abc*/']);
    }
  },
  {
    d: 'comment for properties',
    s: '{//a\n"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect('// a' in obj).to.equal(true);
      expect(obj['// a']).to.deep.equal([['//a']]);
    }
  },
  {
    d: 'comment for properties, multiple at the top',
    s: '{//a\n/*b*/"a":1}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect('// a' in obj).to.equal(true);
      expect(obj['// a']).to.deep.equal([['//a', '/*b*/']]);
    }
  },
  {
    d: 'comment for properties, both top and right',
    s: '{//a\n"a":1//b\n}',
    e: function (obj) {
      expect(obj.a).to.equal(1);
      expect('// a' in obj).to.equal(true);
      expect(obj['// a']).to.deep.equal([['//a'], ['//b']]);
    }
  }
]

describe("parse()", function(){
  cases.forEach(function (c) {
    it(c.d, function(){
      c.e(parser.parse(c.s));
    });
  });
});

var invalid = [
  '{',
  '}',
  '[',
  '',
  '{a:1}',
  '{"a":a}',
  '{"a":undefined}'
];

// ECMA262 does not define the standard of error messages.
// However, we throw error messages the same as JSON.parse()
describe("error messages", function(){
  invalid.forEach(function (i) {
    it('error message:' + i, function(){
      var error;
      var err;

      try {
        parser.parse(i);
      } catch(e) {
        error = e;
      }

      try {
        JSON.parse(i);
      } catch(e) {
        err = e;
      }

      expect(!!(err && error)).to.equal(true);
      expect(error.message).to.equal(err.message);
    });
  });
});

{'fraction_non_alphanumeric': 0.27977315689981097, 'fraction_numerical': 0.008611636210880068, 'mean_word_length': 2.2460804362644855, 'pattern_counts': {'":': 28, '<': 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': '7107977', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1881, 'n_words': 362}