<commit_before>/* globals assert */

const temp = require('temp').track()
const season = require('season')
const dedent = require('dedent')
const electron = require('electron')
const fs = require('fs-plus')
const path = require('path')
const AtomApplication = require('../../src/main-process/atom-application')
const parseCommandLine = require('../../src/main-process/parse-command-line')
const {emitterEventPromise} = require('../async-spec-helpers')

describe('AtomApplication', function () {
  this.timeout(60 * 1000)
  let scenario

  beforeEach(async function () {
    scenario = await LaunchScenario.create()
  })

  afterEach(async function () {
    await scenario.destroy()
  })

  describe('command-line interface behavior', function () {
    describe('with no open windows', function () {
      it('opens a file', async function () {
        await scenario.launch(parseCommandLine(['a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory', async function () {
        await scenario.launch(parseCommandLine(['a']))
        await scenario.assert('[a _]')
      })

      it('opens a file with --add', async function () {
        await scenario.launch(parseCommandLine(['--add', 'a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory with --add', async function () {
        await scenario.launch(parseCommandLine(['--add', 'a']))
        await scenario.assert('[a _]')
      })

      it('opens a file with --new-window', async function () {
        await scenario.launch(parseCommandLine(['--new-window', 'a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory with --new-window', async function () {
        await scenario.launch(parseCommandLine(['--new-window', 'a']))
        await scenario.assert('[a _]')
      })

      it('opens a directory with --new-window', async function () {
        await scenario.launch(parseCommandLine(['--new-window', 'a']))
      })
    })
  })
})

let channelIdCounter = 0

class LaunchScenario {
  static async create () {
    const scenario = new this()
    await scenario.init()
    return scenario
  }

  constructor () {
    this.applications = new Set()
    this.windows = new Set()
    this.root = null
    this.atomHome = null
    this.projectRootPool = new Map()<commit_msg>Tests for the remaining command-line cases<commit_after>/* globals assert */

const temp = require('temp').track()
const season = require('season')
const dedent = require('dedent')
const electron = require('electron')
const fs = require('fs-plus')
const path = require('path')
const AtomApplication = require('../../src/main-process/atom-application')
const parseCommandLine = require('../../src/main-process/parse-command-line')
const {emitterEventPromise} = require('../async-spec-helpers')

describe('AtomApplication', function () {
  this.timeout(60 * 1000)
  let scenario

  beforeEach(async function () {
    scenario = await LaunchScenario.create()
  })

  afterEach(async function () {
    await scenario.destroy()
  })

  describe('command-line interface behavior', function () {
    describe('with no open windows', function () {
      it('opens a file', async function () {
        await scenario.open(parseCommandLine(['a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory', async function () {
        await scenario.open(parseCommandLine(['a']))
        await scenario.assert('[a _]')
      })

      it('opens a file with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a']))
        await scenario.assert('[a _]')
      })

      it('opens a file with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a']))
        await scenario.assert('[a _]')
      })
    })

    describe('with one empty window', function () {
      beforeEach(async function () {
        await scenario.preconditions('[_ _]')
      })

      it('opens a file', async function () {
        await scenario.open(parseCommandLine(['a/1.md']))
        // await scenario.assert('[_ 1.md]') // FIXME
        await scenario.assert('[_ _] [_ 1.md]')
      })

      it('opens a directory', async function () {
        await scenario.open(parseCommandLine(['a']))
        // await scenario.assert('[a _]') // FIXME
        await scenario.assert('[_ _] [a _]')
      })

      it('opens a file with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a/1.md']))
        await scenario.assert('[_ 1.md]')
      })

      it('opens a directory with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a']))
        await scenario.assert('[a _]')
      })

      it('opens a file with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a/1.md']))
        await scenario.assert('[_ _] [_ 1.md]')
      })

      it('opens a directory with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a']))
        await scenario.assert('[_ _] [a _]')
      })
    })

    describe('with one window that has a project root', function () {
      beforeEach(async function () {
        await scenario.preconditions('[a _]')
      })

      it('opens a file within the project root', async function () {
        await scenario.open(parseCommandLine(['a/1.md']))
        await scenario.assert('[a 1.md]')
      })

      it('opens a directory that matches the project root', async function () {
        await scenario.open(parseCommandLine(['a']))
        await scenario.assert('[a _]')
      })

      it('opens a file outside the project root', async function () {
        await scenario.open(parseCommandLine(['b/2.md']))
        // await scenario.assert('[a 2.md]') // FIXME
        await scenario.assert('[a _] [_ 2.md]')
      })

      it('opens a directory other than the project root', async function () {
        await scenario.open(parseCommandLine(['b']))
        await scenario.assert('[a _] [b _]')
      })

      it('opens a file within the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a/1.md']))
        await scenario.assert('[a 1.md]')
      })

      it('opens a directory that matches the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a']))
        await scenario.assert('[a _]')
      })

      it('opens a file outside the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'b/2.md']))
        await scenario.assert('[a 2.md]')
      })

      it('opens a directory other than the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'b']))
        await scenario.assert('[a,b _]')
      })

      it('opens a file within the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a/1.md']))
        await scenario.assert('[a _] [_ 1.md]')
      })

      it('opens a directory that matches the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a']))
        await scenario.assert('[a _] [a _]')
      })

      it('opens a file outside the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'b/2.md']))
        await scenario.assert('[a _] [_ 2.md]')
      })

      it('opens a directory other than the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'b']))
        await scenario.assert('[a _] [b _]')
      })
    })

    describe('with two windows, open with a project root and one empty', function () {
      beforeEach(async function () {
        await scenario.preconditions('[a _] [_ _]')
      })

      it('opens a file within the project root', async function () {
        await scenario.open(parseCommandLine(['a/1.md']))
        await scenario.assert('[a 1.md] [_ _]')
      })

      it('opens a directory that matches the project root', async function () {
        await scenario.open(parseCommandLine(['a']))
        await scenario.assert('[a _] [_ _]')
      })

      it('opens a file outside the project root', async function () {
        await scenario.open(parseCommandLine(['b/2.md']))
        // await scenario.assert('[a _] [_ 2.md]') // FIXME
        await scenario.assert('[a _] [_ _] [_ 2.md]')
      })

      it('opens a directory other than the project root', async function () {
        await scenario.open(parseCommandLine(['b']))
        // await scenario.assert('[a _] [b _]') // FIXME
        await scenario.assert('[a _] [_ _] [b _]')
      })

      it('opens a file within the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a/1.md']))
        await scenario.assert('[a 1.md] [_ _]')
      })

      it('opens a directory that matches the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a']))
        await scenario.assert('[a _] [_ _]')
      })

      it('opens a file outside the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'b/2.md']))
        await scenario.assert('[a _] [_ 2.md]')
      })

      it('opens a directory other than the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'b']))
        await scenario.assert('[a _] [b _]')
      })

      it('opens a file within the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a/1.md']))
        await scenario.assert('[a _] [_ _] [_ 1.md]')
      })

      it('opens a directory that matches the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a']))
        await scenario.assert('[a _] [_ _] [a _]')
      })

      it('opens a file outside the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'b/2.md']))
        await scenario.assert('[a _] [_ _] [_ 2.md]')
      })

      it('opens a directory other than the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'b']))
        await scenario.assert('[a _] [_ _] [b _]')
      })
    })

    describe('with two windows, open empty and one with a project root', function () {
      beforeEach(async function () {
        await scenario.preconditions('[_ _] [a _]')
      })

      it('opens a file within the project root', async function () {
        await scenario.open(parseCommandLine(['a/1.md']))
        await scenario.assert('[_ _] [a 1.md]')
      })

      it('opens a directory that matches the project root', async function () {
        await scenario.open(parseCommandLine(['a']))
        await scenario.assert('[_ _] [a _]')
      })

      it('opens a file outside the project root', async function () {
        await scenario.open(parseCommandLine(['b/2.md']))
        // await scenario.assert('[_ _] [a 2.md]') // FIXME
        await scenario.assert('[_ _] [a _] [_ 2.md]')
      })

      it('opens a directory other than the project root', async function () {
        await scenario.open(parseCommandLine(['b']))
        // await scenario.assert('[b _] [a _]') // FIXME
        await scenario.assert('[_ _] [a _] [b _]')
      })

      it('opens a file within the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a/1.md']))
        await scenario.assert('[_ _] [a 1.md]')
      })

      it('opens a directory that matches the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'a']))
        await scenario.assert('[_ _] [a _]')
      })

      it('opens a file outside the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'b/2.md']))
        await scenario.assert('[_ _] [a 2.md]')
      })

      it('opens a directory other than the project root with --add', async function () {
        await scenario.open(parseCommandLine(['--add', 'b']))
        await scenario.assert('[_ _] [a,b _]')
      })

      it('opens a file within the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a/1.md']))
        await scenario.assert('[_ _] [a _] [_ 1.md]')
      })

      it('opens a directory that matches the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'a']))
        await scenario.assert('[_ _] [a _] [a _]')
      })

      it('opens a file outside the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'b/2.md']))
        await scenario.assert('[_ _] [a _] [_ 2.md]')
      })

      it('opens a directory other than the project root with --new-window', async function () {
        await scenario.open(parseCommandLine(['--new-window', 'b']))
        await scenario.assert('[_ _] [a _] [b _]')
      })
    })
  })
})

let channelIdCounter = 0

class LaunchScenario {
  static async create () {
    const scenario = new this()
    await scenario.init()
    return scenario
  }

  constructor () {
    this.applications = new Set()
    this.windows = new Set()
    this.root = null
    this.atomHome = null
    this.projectRootPool = new Map()
{'fraction_non_alphanumeric': 0.1671751933584049, 'fraction_numerical': 0.005108919321649046, 'mean_word_length': 2.634347601856627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5387420', 'n_tokens_mistral': 4096, 'n_tokens_neox': 4074, 'n_words': 1072}