<commit_before>'use strict';

module.exports = (should, M) => () => {
  const Person = require('./fixtures/Person')(M);
  const PartOfDay = require('./fixtures/PartOfDay')(M);
  const Sex = require('./fixtures/Sex')(M);
  const Animal = require('./fixtures/Animal')(M);

  const Modelico = M.Modelico;
  const ModelicoDate = M.Date;

  const authorJson = '{"givenName":"Javier","familyName":"Cejudo","birthday":"1988-04-16T00:00:00.000Z","favouritePartOfDay":"EVENING","sex":"MALE"}';
  const author2Json = '{"givenName":"Javier","familyName":"Cejudo","birthday":"1988-04-16T00:00:00.000Z","favouritePartOfDay":null,"sex":"MALE"}';

  describe('setting', () => {
    it('should set fields returning a new object', () => {
      const author = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z')),
        favouritePartOfDay: PartOfDay.EVENING(),
        sex: Sex.MALE()
      });

      // sanity check
      JSON.stringify(author)
        .should.be.exactly(authorJson);

      author.givenName().should.be.exactly('Javier');

      // field setting
      const authorAlt = author.set('givenName', 'Javi');

      // repeat sanity check
      author.givenName().should.be.exactly('Javier');

      JSON.stringify(author)
        .should.be.exactly(authorJson);

      // new object checks
      (authorAlt === author).should.be.exactly(false);
      authorAlt.givenName().should.be.exactly('Javi');
      authorAlt.equals(author).should.be.exactly(false, 'Oops, they are equal');
    });
  });

  describe('stringifying', () => {
    it('should stringify types correctly', () => {
      const author = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z')),
        favouritePartOfDay: PartOfDay.EVENING(),
        sex: Sex.MALE()
      });

      JSON.stringify(author)
        .should.be.exactly(authorJson);
    });

    it('should support null in Enum', () => {
      const author2 = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z')),
        favouritePartOfDay: null,
        sex: Sex.MALE()
      });

      JSON.stringify(author2)
        .should.be.exactly(author2Json);
    });
  });

  describe('parsing', () => {
    it('should parse types correctly', () => {
      const author = Modelico.fromJSON(Person, authorJson);
      const authorAlt = JSON.parse(authorJson, Modelico.buildReviver(Person));

      '<NAME>'
        .should.be.exactly(author.fullName())
        .and.exactly(authorAlt.fullName());

      should(1988)
        .be.exactly(author.birthday().date().getFullYear())
        .and.exactly(authorAlt.birthday().date().getFullYear());

      should(PartOfDay.EVENING().minTime)
        .be.exactly(author.favouritePartOfDay().minTime)
        .and.exactly(authorAlt.favouritePartOfDay().minTime);

      (Sex.MALE().code)
        .should.be.exactly(author.sex().code)
        .and.exactly(authorAlt.sex().code);
    });

    it('should support null in Enum', () => {
      const author2 = Modelico.fromJSON(Person, author2Json);

      (author2.favouritePartOfDay() === null).should.be.exactly(true);
    });

    it('should work with plain classes extending Modelico', () => {
      const animal = JSON.parse('{}', Modelico.buildReviver(Animal));

      animal.speak().should.be.exactly('hello');
    });
  });

  describe('cloning', () => {
    it('should support cloning', () => {
      const author = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z'))
        // equivalent but perhaps more convenient:
        // birthday: ModelicoDate.reviver('', '1988-04-16T00:00:00.000Z')
      });

      const authorClone = author.clone();
      const birthdayClone = author.birthday().clone();

      'Javier'
        .should.be.exactly(author.givenName())
        .and.exactly(authorClone.givenName());

      author.should.not.be.exactly(authorClone);

      should(1988)
        .be.exactly(author.birthday().date().getFullYear())
        .and.exactly(birthdayClone.date().getFullYear());

      author.birthday()
        .should.not.be.exactly(birthdayClone);
    });<commit_msg>test: cover case where subtypes is not present<commit_after>'use strict';

module.exports = (should, M) => () => {
  const Person = require('./fixtures/Person')(M);
  const PartOfDay = require('./fixtures/PartOfDay')(M);
  const Sex = require('./fixtures/Sex')(M);
  const Animal = require('./fixtures/Animal')(M);

  const Modelico = M.Modelico;
  const ModelicoDate = M.Date;

  const authorJson = '{"givenName":"Javier","familyName":"Cejudo","birthday":"1988-04-16T00:00:00.000Z","favouritePartOfDay":"EVENING","sex":"MALE"}';
  const author2Json = '{"givenName":"Javier","familyName":"Cejudo","birthday":"1988-04-16T00:00:00.000Z","favouritePartOfDay":null,"sex":"MALE"}';

  describe('setting', () => {
    it('should set fields returning a new object', () => {
      const author = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z')),
        favouritePartOfDay: PartOfDay.EVENING(),
        sex: Sex.MALE()
      });

      // sanity check
      JSON.stringify(author)
        .should.be.exactly(authorJson);

      author.givenName().should.be.exactly('Javier');

      // field setting
      const authorAlt = author.set('givenName', 'Javi');

      // repeat sanity check
      author.givenName().should.be.exactly('Javier');

      JSON.stringify(author)
        .should.be.exactly(authorJson);

      // new object checks
      (authorAlt === author).should.be.exactly(false);
      authorAlt.givenName().should.be.exactly('Javi');
      authorAlt.equals(author).should.be.exactly(false, 'Oops, they are equal');
    });
  });

  describe('stringifying', () => {
    it('should stringify types correctly', () => {
      const author = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z')),
        favouritePartOfDay: PartOfDay.EVENING(),
        sex: Sex.MALE()
      });

      JSON.stringify(author)
        .should.be.exactly(authorJson);
    });

    it('should support null in Enum', () => {
      const author2 = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z')),
        favouritePartOfDay: null,
        sex: Sex.MALE()
      });

      JSON.stringify(author2)
        .should.be.exactly(author2Json);
    });
  });

  describe('parsing', () => {
    it('should parse types correctly', () => {
      const author = Modelico.fromJSON(Person, authorJson);
      const authorAlt = JSON.parse(authorJson, Modelico.buildReviver(Person));

      '<NAME>'
        .should.be.exactly(author.fullName())
        .and.exactly(authorAlt.fullName());

      should(1988)
        .be.exactly(author.birthday().date().getFullYear())
        .and.exactly(authorAlt.birthday().date().getFullYear());

      should(PartOfDay.EVENING().minTime)
        .be.exactly(author.favouritePartOfDay().minTime)
        .and.exactly(authorAlt.favouritePartOfDay().minTime);

      (Sex.MALE().code)
        .should.be.exactly(author.sex().code)
        .and.exactly(authorAlt.sex().code);
    });

    it('should support null in Enum', () => {
      const author2 = Modelico.fromJSON(Person, author2Json);

      (author2.favouritePartOfDay() === null).should.be.exactly(true);
    });

    it('should work with plain classes extending Modelico', () => {
      const animal = JSON.parse('{"name": "Sam"}', Modelico.buildReviver(Animal));

      animal.speak().should.be.exactly('hello');
      animal.name().should.be.exactly('Sam');
    });
  });

  describe('cloning', () => {
    it('should support cloning', () => {
      const author = new Person({
        givenName: 'Javier',
        familyName: 'Cejudo',
        birthday: new ModelicoDate(new Date('1988-04-16T00:00:00.000Z'))
        // equivalent but perhaps more convenient:
        // birthday: ModelicoDate.reviver('', '1988-04-16T00:00:00.000Z')
      });

      const authorClone = author.clone();
      const birthdayClone = author.birthday().clone();

      'Javier'
        .should.be.exactly(author.givenName())
        .and.exactly(authorClone.givenName());

      author.should.not.be.exactly(authorClone);

      should(1988)
        .be.exactly(author.birthday().date().getFullYear())
        .and.exactly(birthdayClone.date().getFullYear());

      author.birthday()
        .should.not.be.exactly(birthdayClone);
    });
{'fraction_non_alphanumeric': 0.17492085029398463, 'fraction_numerical': 0.030303030303030304, 'mean_word_length': 2.9806480648064806, 'pattern_counts': {'":': 21, '<': 5, '<?xml version=': 0, '>': 31, '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': '7354786', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2808, 'n_words': 437}