<commit_before>'use strict';

import {expect} from 'chai';
import YAWN from '../src/index.js';

describe('preserves comments and styling when', ()=> {

  describe('JSON is an array and', ()=> {
    // debugger
    it('transformed to an object', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      yawn.json = {val1: 1, val2: 2};

      expect(yawn.yaml).to.equal(`
        # leading comment
        val1: 1
        val2: 2
        # trailing comment`);
    });

    it('one item in array is changed', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json[0] = 'value0';
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
         # inline comment
        - value2
        - value0
        # trailing comment`);
    });

    xit('TODO: two items in array are changed', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json[0] = 'value0';
      json[1] = 'value3';
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
         # inline comment
        - value3
        - value0
        # trailing comment`);
    });

    it('one item is deleted', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json.shift();
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
         # inline comment
        - value2
        # trailing comment`);
    });

    it('one item is added', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json.push('value3');
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
        - value1 # inline comment<commit_msg>Add test for deleting item from middle of array.<commit_after>'use strict';

import {expect} from 'chai';
import YAWN from '../src/index.js';

describe('preserves comments and styling when', ()=> {

  describe('JSON is an array and', ()=> {
    // debugger
    it('transformed to an object', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      yawn.json = {val1: 1, val2: 2};

      expect(yawn.yaml).to.equal(`
        # leading comment
        val1: 1
        val2: 2
        # trailing comment`);
    });

    it('one item in array is changed', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json[0] = 'value0';
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
         # inline comment
        - value2
        - value0
        # trailing comment`);
    });

    xit('TODO: two items in array are changed', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json[0] = 'value0';
      json[1] = 'value3';
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
         # inline comment
        - value3
        - value0
        # trailing comment`);
    });

    it('one item is deleted', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json.shift();
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
         # inline comment
        - value2
        # trailing comment`);
    });

    xit('TODO: one item in middle is deleted', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        - value3
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json = json.slice(0, 1).concat(json.slice(2));
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
        - value1 # inline comment

        - value3
        # trailing comment`);
    });

    it('one item is added', ()=> {
      let str = `
        # leading comment
        - value1 # inline comment
        - value2
        # trailing comment`;

      let yawn = new YAWN(str);
      let json = yawn.json;
      json.push('value3');
      yawn.json = json;

      expect(yawn.yaml).to.equal(`
        # leading comment
        - value1 # inline comment
{'fraction_non_alphanumeric': 0.12580961727183512, 'fraction_numerical': 0.013738959764474975, 'mean_word_length': 1.5868020304568529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '7409935', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1541, 'n_words': 426}