<commit_before>/*
 * Copyright 2017 <NAME> <<EMAIL>>
 *
 * This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
 */

import "jest";
jest.mock("./gui/Splitter");
jest.mock("./gui/Tab");
jest.mock("./gui/TabWidget");
import { Splitter } from "./gui/Splitter";
import { Tab } from "./gui/Tab";
import { TabWidget } from "./gui/TabWidget";

import { SplitLayout } from "./SplitLayout";

const SplitOrientation = {
  VERTICAL: 0,
  HORIZONTAL: 1
};

class FakeChildrenArray {

  _children = [];
  length = 0;

  constructor() {
    this._children = [];
    this.length = 0;
  }

  item(x) {
    return this._children[x];
  }  

  push(kid) {
    this._children.push(kid);
    this.length = this._children.length;
    this._updateIndex();
  }

  _remove(kid) {
    const currentLength = this._children.length;

    this._children = this._children.filter( c => c !== kid );
    this.length = this._children.length;

    for (let i=0; i<currentLength; i++) {
      delete this[i];
    }
    this._updateIndex();
  }

  _updateIndex() {
    const currentLength = this._children.length;
    for (let i=0; i<currentLength; i++) {
      this[i] = this._children[i];
    }
  }

  _insertAt(index, item) {
    this._children.splice(index, 0, item);
    this.length = this._children.length;
    this._updateIndex();
  }
}

class FakeElement {
  name = "";
  children = new FakeChildrenArray();
  parent = null;

  constructor(name) {
    this.name = name;
    this.parent = null;
  }

  appendChild(child) {
    if (child.parent != null) {
      child.parent.children._remove(child);
    }

    this.children.push(child);
    child.parent = this;
  }

  insertBefore(child, refChild) {
    if (child.parent != null) {
      child.parent.children._remove(child);
    }

    const index = this.children._children.indexOf(refChild);
    this.children._insertAt(index, child);
    child.parent = this;
  }

  removeChild(child) {
    this.children._remove(child);
    child.parent = null;
  }

  _toFlatObject() {
    return { orientation: SplitOrientation.HORIZONTAL, name: this.name, children: this.children._children.map( c => c._toFlatObject() ) };
  }
}

let splitterCounter = 0;
class FakeSplitter extends FakeElement {
  _orientation = SplitOrientation.VERTICAL;
  _dividerSize = 4;
  _width = 100;
  _height = 200;

  constructor() {
    super("Splitter " + splitterCounter);
    splitterCounter++;
  }

  getDividerSize() {
    return this._dividerSize;
  }

  setSplitOrientation(orientation) {
    this._orientation = orientation;
  }

  getPaneSizes() {
    const equalSize = ((this._orientation === SplitOrientation.VERTICAL ? this._width : this._height)
      - (this.children.length-1) * this._dividerSize) / this.children.length;

    let result = [];
    for (let i=0; i<this.children.length; i++) {
      result.push(equalSize);
    }
    return result;
  }

  _toFlatObject() {
    const flat = super._toFlatObject();
    flat.orientation = this._orientation;
    return flat;
  }

  getBoundingClientRect() {
    return {
      left: 100,
      right: 100 + this._width,
      width: this._width,
      top: 300,
      bottom: 300 + this._height,
      height:  + this._height
    };
  }<commit_msg>Fix failing test in SplitLayout.jest.ts<commit_after>/*
 * Copyright 2017 <NAME> <<EMAIL>>
 *
 * This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
 */

import "jest";
jest.mock("./gui/Splitter");
jest.mock("./gui/Tab");
jest.mock("./gui/TabWidget");
import { Splitter } from "./gui/Splitter";
import { Tab } from "./gui/Tab";
import { TabWidget } from "./gui/TabWidget";

import { SplitLayout } from "./SplitLayout";

const SplitOrientation = {
  VERTICAL: 0,
  HORIZONTAL: 1
};

class FakeChildrenArray {

  _children = [];
  length = 0;

  constructor() {
    this._children = [];
    this.length = 0;
  }

  item(x) {
    return this._children[x];
  }  

  push(kid) {
    this._children.push(kid);
    this.length = this._children.length;
    this._updateIndex();
  }

  _remove(kid) {
    const currentLength = this._children.length;

    this._children = this._children.filter( c => c !== kid );
    this.length = this._children.length;

    for (let i=0; i<currentLength; i++) {
      delete this[i];
    }
    this._updateIndex();
  }

  _updateIndex() {
    const currentLength = this._children.length;
    for (let i=0; i<currentLength; i++) {
      this[i] = this._children[i];
    }
  }

  _insertAt(index, item) {
    this._children.splice(index, 0, item);
    this.length = this._children.length;
    this._updateIndex();
  }
}

class FakeElement {
  name = "";
  children = new FakeChildrenArray();
  parent = null;

  constructor(name) {
    this.name = name;
    this.parent = null;
  }

  appendChild(child) {
    if (child.parent != null) {
      child.parent.children._remove(child);
    }

    this.children.push(child);
    child.parent = this;
  }

  insertBefore(child, refChild) {
    if (child.parent != null) {
      child.parent.children._remove(child);
    }

    const index = this.children._children.indexOf(refChild);
    this.children._insertAt(index, child);
    child.parent = this;
  }

  removeChild(child) {
    this.children._remove(child);
    child.parent = null;
  }

  _toFlatObject() {
    return { orientation: SplitOrientation.HORIZONTAL, name: this.name, children: this.children._children.map( c => c._toFlatObject() ) };
  }
}

let splitterCounter = 0;
class FakeSplitter extends FakeElement {
  _orientation = SplitOrientation.VERTICAL;
  _dividerSize = 4;
  _width = 100;
  _height = 200;

  constructor() {
    super("Splitter " + splitterCounter);
    splitterCounter++;
  }

  getDividerSize() {
    return this._dividerSize;
  }

  setSplitOrientation(orientation) {
    this._orientation = orientation;
  }

  getPaneSizes() {
    const equalSize = ((this._orientation === SplitOrientation.VERTICAL ? this._width : this._height)
      - (this.children.length-1) * this._dividerSize) / this.children.length;

    let result = [];
    for (let i=0; i<this.children.length; i++) {
      result.push(equalSize);
    }
    return result;
  }

  _toFlatObject() {
    const flat = super._toFlatObject();
    flat.orientation = this._orientation;
    return flat;
  }

  getBoundingClientRect() {
    return {
      left: 100,
      right: 100 + this._width,
      width: this._width,
      top: 300,
      bottom: 300 + this._height,
      height:  + this._height
    };
  }
  
  update() {

  }
{'fraction_non_alphanumeric': 0.1433603920967989, 'fraction_numerical': 0.010108745596569152, 'mean_word_length': 2.900836320191159, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '127594', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2124, 'n_words': 445}