<commit_before>define(
  'ephox.robin.parent.Breaker',

  [
    'ephox.compass.Arr',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option',
    'ephox.scullion.Struct'
  ],

  function (Arr, Fun, Option, Struct) {
    var bisect = function (universe, parent, child) {
      var children = universe.property().children(parent);
      var index = Arr.findIndex(children, Fun.curry(universe.eq, child));
      return index > -1 ? Option.some({
        before: Fun.constant(children.slice(0, index)),
        after: Fun.constant(children.slice(index + 1))
      }) : Option.none();
    };

    var unsafeBreakAt = function (universe, parent, parts) {
      var second = universe.create().clone(parent);
      universe.insert().appendAll(second, parts.after());
      universe.insert().after(parent, second);
      return second;
    };

    /**
     * Move everything after child in the parent element into a clone of the parent (placed after parent).
     */
    var breakAt = function (universe, parent, child) {
      var parts = bisect(universe, parent, child);
      return parts.map(function (ps) {
        return unsafeBreakAt(universe, parent, ps);
      });
    };


    /*
     * Using the breaker, break from the child up to the top element defined by the predicate
     */
    var breakPath  = function (universe, item, isTop, breaker) {
      var result = Struct.immutable('first', 'second', 'splits');

      var next = function (child, group, splits) {
        var fallback = result(child, Option.none(), splits);
        if (isTop(child)) return result(child, group, splits);
        else {
          return universe.property().parent(child).fold(function () {
            return fallback;
          }, function (parent) {
            var second = breaker(universe, parent, child);
            var extra = second.fold(Fun.constant([]), function (sec) {
              return [{
                first: parent.dom(),
                second: sec.dom()
              }];
            });
            return next(parent, second, splits.concat(extra));
          });
        }<commit_msg>TBIO-842: getting test working with splits<commit_after>define(
  'ephox.robin.parent.Breaker',

  [
    'ephox.compass.Arr',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option',
    'ephox.scullion.Struct'
  ],

  function (Arr, Fun, Option, Struct) {
    var bisect = function (universe, parent, child) {
      var children = universe.property().children(parent);
      var index = Arr.findIndex(children, Fun.curry(universe.eq, child));
      return index > -1 ? Option.some({
        before: Fun.constant(children.slice(0, index)),
        after: Fun.constant(children.slice(index + 1))
      }) : Option.none();
    };

    var unsafeBreakAt = function (universe, parent, parts) {
      var second = universe.create().clone(parent);
      universe.insert().appendAll(second, parts.after());
      universe.insert().after(parent, second);
      return second;
    };

    /**
     * Move everything after child in the parent element into a clone of the parent (placed after parent).
     */
    var breakAt = function (universe, parent, child) {
      var parts = bisect(universe, parent, child);
      return parts.map(function (ps) {
        return unsafeBreakAt(universe, parent, ps);
      });
    };


    /*
     * Using the breaker, break from the child up to the top element defined by the predicate
     */
    var breakPath  = function (universe, item, isTop, breaker) {
      var result = Struct.immutable('first', 'second', 'splits');

      var next = function (child, group, splits) {
        var fallback = result(child, Option.none(), splits);
        if (isTop(child)) return result(child, group, splits);
        else {
          return universe.property().parent(child).fold(function () {
            return fallback;
          }, function (parent) {
            var second = breaker(universe, parent, child);

            // Store the splits up the path break.
            var extra = second.fold(Fun.constant([]), function (sec) {
              return [{ first: parent.dom(), second: sec.dom() }];
            });
            return next(parent, second, splits.concat(extra));
          });
        }
{'fraction_non_alphanumeric': 0.13505815333491575, 'fraction_numerical': 0.002136244956088298, 'mean_word_length': 2.4288039056143207, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2260885', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1193, 'n_words': 326}