<commit_before>/*jshint node:true, esnext:true, mocha:true */

'use strict';

const should = require('should');
const fs = require('fs');
const Modelico = require('../').Modelico;
const Person = require('./fixtures/Person');
const SerialisableDate = require('./fixtures/SerialisableDate');
const PartOfDay = require('./fixtures/PartOfDay');
const Sex = require('./fixtures/Sex');

const authorJson = fs.readFileSync(__dirname + '/fixtures/author.json').toString();
const author2Json = fs.readFileSync(__dirname + '/fixtures/author2.json').toString();

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

    JSON.stringify(author).concat("\n")
      .should.be.exactly(authorJson);
  });

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

    JSON.stringify(author2).concat("\n")
      .should.be.exactly(author2Json);
  });
});

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

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

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

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

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

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

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

describe('cloning', function() {
  it('should support cloning', function() {
    const author = new Person({
      givenName: 'Javier',
      familyName: 'Cejudo',
      birthday: new SerialisableDate({date: new Date('1988-04-16T00:00:00.000Z')}),
      // equivalent but perhaps more convenient:
      // birthday: SerialisableDate.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);<commit_msg>style: remove trailing comma<commit_after>/*jshint node:true, esnext:true, mocha:true */

'use strict';

const should = require('should');
const fs = require('fs');
const Modelico = require('../').Modelico;
const Person = require('./fixtures/Person');
const SerialisableDate = require('./fixtures/SerialisableDate');
const PartOfDay = require('./fixtures/PartOfDay');
const Sex = require('./fixtures/Sex');

const authorJson = fs.readFileSync(__dirname + '/fixtures/author.json').toString();
const author2Json = fs.readFileSync(__dirname + '/fixtures/author2.json').toString();

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

    JSON.stringify(author).concat("\n")
      .should.be.exactly(authorJson);
  });

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

    JSON.stringify(author2).concat("\n")
      .should.be.exactly(author2Json);
  });
});

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

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

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

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

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

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

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

describe('cloning', function() {
  it('should support cloning', function() {
    const author = new Person({
      givenName: 'Javier',
      familyName: 'Cejudo',
      birthday: new SerialisableDate({date: new Date('1988-04-16T00:00:00.000Z')})
      // equivalent but perhaps more convenient:
      // birthday: SerialisableDate.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);
{'fraction_non_alphanumeric': 0.1604895104895105, 'fraction_numerical': 0.027972027972027972, 'mean_word_length': 3.791457286432161, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5164195', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1851, 'n_words': 324}