<commit_before>/** @babel */

import path from 'path';

import Conflict from '../../../lib/models/conflicts/conflict';
import {TOP, MIDDLE, BOTTOM} from '../../../lib/models/conflicts/position';


describe('Conflict', () => {
  let atomEnv;

  beforeEach(() => { atomEnv = global.buildAtomEnvironment(); });
  afterEach(() => { atomEnv.destroy(); });

  const editorOnFixture = name => {
    const fullPath = path.join(path.dirname(__filename), '..', '..', 'fixtures', 'conflict-marker-examples', name);
    return atomEnv.workspace.open(fullPath);
  };

  const assertConflictOnRows = (conflict, description, message) => {
    const isRangeOnRows = (range, startRow, endRow, rangeName) => {
      assert(
        range.start.row === startRow && range.start.column === 0 && range.end.row === endRow && range.end.column === 0,
        `expected conflict's ${rangeName} range to cover rows ${startRow} to ${endRow}, but it was ${range}`,
      );
    };

    const isRangeOnRow = (range, row, rangeName) => isRangeOnRows(range, row, row + 1, rangeName);

    const ourBannerRange = conflict.ours.banner.marker.getBufferRange();
    isRangeOnRow(ourBannerRange, description.ourBannerRow, '"ours" banner');

    const ourSideRange = conflict.ours.marker.getBufferRange();
    isRangeOnRows(ourSideRange, description.ourSideRows[0], description.ourSideRows[1], '"ours"');
    assert.strictEqual(conflict.ours.position, description.ourPosition || TOP, '"ours" in expected position');

    const theirBannerRange = conflict.theirs.banner.marker.getBufferRange();
    isRangeOnRow(theirBannerRange, description.theirBannerRow, '"theirs" banner');

    const theirSideRange = conflict.theirs.marker.getBufferRange();
    isRangeOnRows(theirSideRange, description.theirSideRows[0], description.theirSideRows[1], '"theirs"');
    assert.strictEqual(conflict.theirs.position, description.theirPosition || BOTTOM, '"theirs" in expected position');

    if (description.baseBannerRow || description.baseSideRows) {
      assert.isNotNull(conflict.base, "expected conflict's base side to be non-null");

      const baseBannerRange = conflict.base.banner.marker.getBufferRange();
      isRangeOnRow(baseBannerRange, description.baseBannerRow, '"base" banner');

      const baseSideRange = conflict.base.marker.getBufferRange();
      isRangeOnRows(baseSideRange, description.baseSideRows[0], description.baseSideRows[1], '"base"');
      assert.strictEqual(conflict.base.position, MIDDLE, '"base" in MIDDLE position');
    } else {
      assert.isNull(conflict.base, "expected conflict's base side to be null");
    }

    const separatorRange = conflict.separator.marker.getBufferRange();
    isRangeOnRow(separatorRange, description.separatorRow, 'separator');
  };

  it('parses 2-way diff markings', async () => {
    const editor = await editorOnFixture('single-2way-diff.txt');
    const conflicts = Conflict.all(editor, false);

    assert.equal(conflicts.length, 1);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 2,
      ourSideRows: [3, 4],
      separatorRow: 4,
      theirSideRows: [5, 6],
      theirBannerRow: 6,
    });
  });

  it('parses multiple 2-way diff markings', async () => {
    const editor = await editorOnFixture('multi-2way-diff.txt');
    const conflicts = Conflict.all(editor, false);

    assert.equal(conflicts.length, 2);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 4,
      ourSideRows: [5, 7],
      separatorRow: 7,
      theirSideRows: [8, 9],
      theirBannerRow: 9,
    });
    assertConflictOnRows(conflicts[1], {
      ourBannerRow: 13,
      ourSideRows: [14, 15],
      separatorRow: 15,
      theirSideRows: [16, 17],
      theirBannerRow: 17,
    });
  });

  it('parses 3-way diff markings', async () => {
    const editor = await editorOnFixture('single-3way-diff.txt');
    const conflicts = Conflict.all(editor, false);
    assert.equal(conflicts.length, 1);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 0,
      ourSideRows: [1, 2],
      baseBannerRow: 2,
      baseSideRows: [3, 4],
      separatorRow: 4,
      theirSideRows: [5, 6],
      theirBannerRow: 6,
    });
  });

  it('parses recursive 3-way diff markings');

  it('flips "ours" and "theirs" sides when rebasing');

  it('is resilient to malformed 2-way diff markings');

  it('is resilient to malformed 3-way diff markings');
});
<commit_msg>Test case for recursive 3-way diff parsing<commit_after>/** @babel */

import path from 'path';

import Conflict from '../../../lib/models/conflicts/conflict';
import {TOP, MIDDLE, BOTTOM} from '../../../lib/models/conflicts/position';


describe('Conflict', () => {
  let atomEnv;

  beforeEach(() => { atomEnv = global.buildAtomEnvironment(); });
  afterEach(() => { atomEnv.destroy(); });

  const editorOnFixture = name => {
    const fullPath = path.join(path.dirname(__filename), '..', '..', 'fixtures', 'conflict-marker-examples', name);
    return atomEnv.workspace.open(fullPath);
  };

  const assertConflictOnRows = (conflict, description, message) => {
    const isRangeOnRows = (range, startRow, endRow, rangeName) => {
      assert(
        range.start.row === startRow && range.start.column === 0 && range.end.row === endRow && range.end.column === 0,
        `expected conflict's ${rangeName} range to cover rows ${startRow} to ${endRow}, but it was ${range}`,
      );
    };

    const isRangeOnRow = (range, row, rangeName) => isRangeOnRows(range, row, row + 1, rangeName);

    const ourBannerRange = conflict.ours.banner.marker.getBufferRange();
    isRangeOnRow(ourBannerRange, description.ourBannerRow, '"ours" banner');

    const ourSideRange = conflict.ours.marker.getBufferRange();
    isRangeOnRows(ourSideRange, description.ourSideRows[0], description.ourSideRows[1], '"ours"');
    assert.strictEqual(conflict.ours.position, description.ourPosition || TOP, '"ours" in expected position');

    const theirBannerRange = conflict.theirs.banner.marker.getBufferRange();
    isRangeOnRow(theirBannerRange, description.theirBannerRow, '"theirs" banner');

    const theirSideRange = conflict.theirs.marker.getBufferRange();
    isRangeOnRows(theirSideRange, description.theirSideRows[0], description.theirSideRows[1], '"theirs"');
    assert.strictEqual(conflict.theirs.position, description.theirPosition || BOTTOM, '"theirs" in expected position');

    if (description.baseBannerRow || description.baseSideRows) {
      assert.isNotNull(conflict.base, "expected conflict's base side to be non-null");

      const baseBannerRange = conflict.base.banner.marker.getBufferRange();
      isRangeOnRow(baseBannerRange, description.baseBannerRow, '"base" banner');

      const baseSideRange = conflict.base.marker.getBufferRange();
      isRangeOnRows(baseSideRange, description.baseSideRows[0], description.baseSideRows[1], '"base"');
      assert.strictEqual(conflict.base.position, MIDDLE, '"base" in MIDDLE position');
    } else {
      assert.isNull(conflict.base, "expected conflict's base side to be null");
    }

    const separatorRange = conflict.separator.marker.getBufferRange();
    isRangeOnRow(separatorRange, description.separatorRow, 'separator');
  };

  it('parses 2-way diff markings', async () => {
    const editor = await editorOnFixture('single-2way-diff.txt');
    const conflicts = Conflict.all(editor, false);

    assert.equal(conflicts.length, 1);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 2,
      ourSideRows: [3, 4],
      separatorRow: 4,
      theirSideRows: [5, 6],
      theirBannerRow: 6,
    });
  });

  it('parses multiple 2-way diff markings', async () => {
    const editor = await editorOnFixture('multi-2way-diff.txt');
    const conflicts = Conflict.all(editor, false);

    assert.equal(conflicts.length, 2);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 4,
      ourSideRows: [5, 7],
      separatorRow: 7,
      theirSideRows: [8, 9],
      theirBannerRow: 9,
    });
    assertConflictOnRows(conflicts[1], {
      ourBannerRow: 13,
      ourSideRows: [14, 15],
      separatorRow: 15,
      theirSideRows: [16, 17],
      theirBannerRow: 17,
    });
  });

  it('parses 3-way diff markings', async () => {
    const editor = await editorOnFixture('single-3way-diff.txt');
    const conflicts = Conflict.all(editor, false);
    assert.equal(conflicts.length, 1);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 0,
      ourSideRows: [1, 2],
      baseBannerRow: 2,
      baseSideRows: [3, 4],
      separatorRow: 4,
      theirSideRows: [5, 6],
      theirBannerRow: 6,
    });
  });

  it('parses recursive 3-way diff markings', async () => {
    const editor = await editorOnFixture('single-3way-diff-complex.txt');
    const conflicts = Conflict.all(editor, false);
    assert.equal(conflicts.length, 1);
    assertConflictOnRows(conflicts[0], {
      ourBannerRow: 0,
      ourSideRows: [1, 2],
      baseBannerRow: 2,
      baseSideRows: [3, 18],
      separatorRow: 18,
      theirSideRows: [19, 20],
      theirBannerRow: 20,
    });
  });

  it('flips "ours" and "theirs" sides when rebasing');

  it('is resilient to malformed 2-way diff markings');

  it('is resilient to malformed 3-way diff markings');
});

{'fraction_non_alphanumeric': 0.14675620058485866, 'fraction_numerical': 0.015704538069966426, 'mean_word_length': 3.794392523364486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '1674370', 'n_tokens_mistral': 3076, 'n_tokens_neox': 2816, 'n_words': 627}