2013-09-24 02:46:57 +04:00
|
|
|
temp = require 'temp'
|
|
|
|
fstream = require 'fstream'
|
2013-09-18 05:58:41 +04:00
|
|
|
Project = require '../src/project'
|
2014-02-24 05:09:05 +04:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
fs = require 'fs-plus'
|
2013-06-13 02:26:09 +04:00
|
|
|
path = require 'path'
|
2013-10-12 01:09:17 +04:00
|
|
|
platform = require './spec-helper-platform'
|
2013-09-18 05:58:41 +04:00
|
|
|
BufferedProcess = require '../src/buffered-process'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "Project", ->
|
|
|
|
beforeEach ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([atom.project.resolve('dir')])
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-08-29 05:37:40 +04:00
|
|
|
describe "serialization", ->
|
2013-08-30 05:24:51 +04:00
|
|
|
deserializedProject = null
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
deserializedProject?.destroy()
|
|
|
|
|
2014-01-04 03:23:23 +04:00
|
|
|
it "does not include unretained buffers in the serialized state", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.bufferForPath('a')
|
2013-11-21 04:45:26 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
|
|
|
deserializedProject = atom.project.testSerialization()
|
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
2013-08-29 05:37:40 +04:00
|
|
|
|
2013-11-19 21:08:24 +04:00
|
|
|
it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('a')
|
2013-11-19 21:08:24 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
runs ->
|
|
|
|
expect(atom.project.getBuffers().length).toBe 1
|
|
|
|
deserializedProject = atom.project.testSerialization()
|
|
|
|
|
|
|
|
expect(deserializedProject.getBuffers().length).toBe 1
|
|
|
|
deserializedProject.getBuffers()[0].destroy()
|
|
|
|
expect(deserializedProject.getBuffers().length).toBe 0
|
2013-11-19 21:08:24 +04:00
|
|
|
|
2014-04-08 21:52:19 +04:00
|
|
|
describe "when an editor is saved and the project has no path", ->
|
2013-02-28 03:21:42 +04:00
|
|
|
it "sets the project's path to the saved file's parent directory", ->
|
2013-10-04 00:22:05 +04:00
|
|
|
tempFile = temp.openSync().path
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
|
|
|
expect(atom.project.getPaths()[0]).toBeUndefined()
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2013-02-28 03:21:42 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open().then (o) -> editor = o
|
2014-02-13 04:56:00 +04:00
|
|
|
|
2014-04-24 03:50:25 +04:00
|
|
|
runs ->
|
|
|
|
editor.saveAs(tempFile)
|
2014-10-01 20:37:27 +04:00
|
|
|
expect(atom.project.getPaths()[0]).toBe path.dirname(tempFile)
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe ".open(path)", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
[absolutePath, newBufferHandler] = []
|
2014-02-13 04:56:00 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
absolutePath = require.resolve('./fixtures/dir/a')
|
|
|
|
newBufferHandler = jasmine.createSpy('newBufferHandler')
|
|
|
|
atom.project.on 'buffer-created', newBufferHandler
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when given an absolute path that isn't currently open", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session for the given path and emits 'buffer-created'", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(absolutePath).then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.buffer.getPath()).toBe absolutePath
|
|
|
|
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when given a relative path that isn't currently opened", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session for the given path (relative to the project root) and emits 'buffer-created'", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(absolutePath).then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.buffer.getPath()).toBe absolutePath
|
|
|
|
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when passed the path to a buffer that is currently opened", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session containing currently opened buffer", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
2014-04-24 03:50:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(absolutePath).then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2013-05-15 06:23:25 +04:00
|
|
|
newBufferHandler.reset()
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(absolutePath).then ({buffer}) ->
|
|
|
|
expect(buffer).toBe editor.buffer
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('a').then ({buffer}) ->
|
|
|
|
expect(buffer).toBe editor.buffer
|
|
|
|
expect(newBufferHandler).not.toHaveBeenCalled()
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2014-02-13 04:56:00 +04:00
|
|
|
describe "when not passed a path", ->
|
2014-04-08 21:52:19 +04:00
|
|
|
it "returns a new edit session and emits 'buffer-created'", ->
|
2014-02-13 04:56:00 +04:00
|
|
|
editor = null
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open().then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.buffer.getPath()).toBeUndefined()
|
|
|
|
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
|
2013-05-15 06:23:25 +04:00
|
|
|
|
2013-10-08 00:47:20 +04:00
|
|
|
it "returns number of read bytes as progress indicator", ->
|
2013-11-21 03:35:49 +04:00
|
|
|
filePath = atom.project.resolve 'a'
|
2013-10-08 00:47:20 +04:00
|
|
|
totalBytes = 0
|
2013-11-21 03:35:49 +04:00
|
|
|
promise = atom.project.open(filePath)
|
2013-10-08 00:47:20 +04:00
|
|
|
promise.progress (bytesRead) -> totalBytes = bytesRead
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
promise
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(totalBytes).toBe fs.statSync(filePath).size
|
|
|
|
|
2013-10-15 21:58:33 +04:00
|
|
|
describe ".bufferForPath(path)", ->
|
2013-10-03 03:17:49 +04:00
|
|
|
[buffer] = []
|
|
|
|
beforeEach ->
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("a").then (o) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
buffer = o
|
|
|
|
buffer.retain()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
buffer.release()
|
|
|
|
|
|
|
|
describe "when opening a previously opened path", ->
|
|
|
|
it "does not create a new buffer", ->
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("a").then (anotherBuffer) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
expect(anotherBuffer).toBe buffer
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("b").then (anotherBuffer) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
expect(anotherBuffer).not.toBe buffer
|
|
|
|
|
|
|
|
it "creates a new buffer if the previous buffer was destroyed", ->
|
|
|
|
buffer.release()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.bufferForPath("b").then (anotherBuffer) ->
|
2013-10-03 03:17:49 +04:00
|
|
|
expect(anotherBuffer).not.toBe buffer
|
|
|
|
|
2013-05-15 06:55:14 +04:00
|
|
|
describe ".resolve(uri)", ->
|
|
|
|
describe "when passed an absolute or relative path", ->
|
2013-11-21 03:35:49 +04:00
|
|
|
it "returns an absolute path based on the atom.project's root", ->
|
2013-09-18 03:09:32 +04:00
|
|
|
absolutePath = require.resolve('./fixtures/dir/a')
|
2013-11-21 04:45:26 +04:00
|
|
|
expect(atom.project.resolve('a')).toBe absolutePath
|
|
|
|
expect(atom.project.resolve(absolutePath + '/../a')).toBe absolutePath
|
|
|
|
expect(atom.project.resolve('a/../a')).toBe absolutePath
|
2014-06-03 02:39:43 +04:00
|
|
|
expect(atom.project.resolve()).toBeUndefined()
|
2013-05-15 06:55:14 +04:00
|
|
|
|
|
|
|
describe "when passed a uri with a scheme", ->
|
|
|
|
it "does not modify uris that begin with a scheme", ->
|
2013-11-21 04:45:26 +04:00
|
|
|
expect(atom.project.resolve('http://zombo.com')).toBe 'http://zombo.com'
|
2014-06-03 02:39:43 +04:00
|
|
|
|
|
|
|
describe "when the project has no path", ->
|
2014-06-03 02:45:47 +04:00
|
|
|
it "returns undefined for relative URIs", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
2014-06-03 02:39:43 +04:00
|
|
|
expect(atom.project.resolve('test.txt')).toBeUndefined()
|
2014-06-03 02:45:47 +04:00
|
|
|
expect(atom.project.resolve('http://github.com')).toBe 'http://github.com'
|
|
|
|
absolutePath = fs.absolute(__dirname)
|
|
|
|
expect(atom.project.resolve(absolutePath)).toBe absolutePath
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe ".setPath(path)", ->
|
|
|
|
describe "when path is a file", ->
|
|
|
|
it "sets its path to the files parent directory and updates the root directory", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([require.resolve('./fixtures/dir/a')])
|
|
|
|
expect(atom.project.getPaths()[0]).toEqual path.dirname(require.resolve('./fixtures/dir/a'))
|
2013-11-21 04:45:26 +04:00
|
|
|
expect(atom.project.getRootDirectory().path).toEqual path.dirname(require.resolve('./fixtures/dir/a'))
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when path is a directory", ->
|
|
|
|
it "sets its path to the directory and updates the root directory", ->
|
2013-09-18 05:58:41 +04:00
|
|
|
directory = fs.absolute(path.join(__dirname, 'fixtures', 'dir', 'a-dir'))
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([directory])
|
|
|
|
expect(atom.project.getPaths()[0]).toEqual directory
|
2013-11-21 04:45:26 +04:00
|
|
|
expect(atom.project.getRootDirectory().path).toEqual directory
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when path is null", ->
|
|
|
|
it "sets its path and root directory to null", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([])
|
|
|
|
expect(atom.project.getPaths()[0]?).toBeFalsy()
|
2013-11-21 04:45:26 +04:00
|
|
|
expect(atom.project.getRootDirectory()?).toBeFalsy()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2014-09-02 21:47:05 +04:00
|
|
|
it "normalizes the path to remove consecutive slashes, ., and .. segments", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths(["#{require.resolve('./fixtures/dir/a')}#{path.sep}b#{path.sep}#{path.sep}.."])
|
|
|
|
expect(atom.project.getPaths()[0]).toEqual path.dirname(require.resolve('./fixtures/dir/a'))
|
2014-09-02 21:47:05 +04:00
|
|
|
expect(atom.project.getRootDirectory().path).toEqual path.dirname(require.resolve('./fixtures/dir/a'))
|
|
|
|
|
2013-11-09 00:20:43 +04:00
|
|
|
describe ".replace()", ->
|
|
|
|
[filePath, commentFilePath, sampleContent, sampleCommentContent] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([atom.project.resolve('../')])
|
2013-11-09 00:20:43 +04:00
|
|
|
|
2013-11-21 03:35:49 +04:00
|
|
|
filePath = atom.project.resolve('sample.js')
|
|
|
|
commentFilePath = atom.project.resolve('sample-with-comments.js')
|
2013-11-09 00:20:43 +04:00
|
|
|
sampleContent = fs.readFileSync(filePath).toString()
|
|
|
|
sampleCommentContent = fs.readFileSync(commentFilePath).toString()
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
fs.writeFileSync(filePath, sampleContent)
|
|
|
|
fs.writeFileSync(commentFilePath, sampleCommentContent)
|
|
|
|
|
2014-07-01 21:32:30 +04:00
|
|
|
describe "when a file doesn't exist", ->
|
2014-07-01 02:38:35 +04:00
|
|
|
it "calls back with an error", ->
|
|
|
|
errors = []
|
2014-07-05 21:01:19 +04:00
|
|
|
missingPath = path.resolve('/not-a-file.js')
|
|
|
|
expect(fs.existsSync(missingPath)).toBeFalsy()
|
|
|
|
|
2014-07-01 02:38:35 +04:00
|
|
|
waitsForPromise ->
|
2014-07-05 21:01:19 +04:00
|
|
|
atom.project.replace /items/gi, 'items', [missingPath], (result, error) ->
|
2014-07-01 02:38:35 +04:00
|
|
|
errors.push(error)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(errors).toHaveLength 1
|
2014-07-05 21:01:19 +04:00
|
|
|
expect(errors[0].path).toBe missingPath
|
2014-07-01 02:38:35 +04:00
|
|
|
|
2013-11-09 00:20:43 +04:00
|
|
|
describe "when called with unopened files", ->
|
|
|
|
it "replaces properly", ->
|
|
|
|
results = []
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.replace /items/gi, 'items', [filePath], (result) ->
|
2013-11-09 00:20:43 +04:00
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe filePath
|
|
|
|
expect(results[0].replacements).toBe 6
|
|
|
|
|
|
|
|
describe "when a buffer is already open", ->
|
|
|
|
it "replaces properly and saves when not modified", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2013-11-09 00:20:43 +04:00
|
|
|
results = []
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('sample.js').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(editor.isModified()).toBeFalsy()
|
|
|
|
|
2013-11-09 00:20:43 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.replace /items/gi, 'items', [filePath], (result) ->
|
2013-11-09 00:20:43 +04:00
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe filePath
|
|
|
|
expect(results[0].replacements).toBe 6
|
|
|
|
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.isModified()).toBeFalsy()
|
2013-11-09 00:20:43 +04:00
|
|
|
|
2013-11-27 05:08:21 +04:00
|
|
|
it "does not replace when the path is not specified", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2013-11-27 05:08:21 +04:00
|
|
|
results = []
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('sample-with-comments.js').then (o) -> editor = o
|
|
|
|
|
2013-11-27 05:08:21 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.replace /items/gi, 'items', [commentFilePath], (result) ->
|
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe commentFilePath
|
|
|
|
|
2013-11-09 00:20:43 +04:00
|
|
|
it "does NOT save when modified", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2013-11-09 00:20:43 +04:00
|
|
|
results = []
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('sample.js').then (o) -> editor = o
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
editor.buffer.setTextInRange([[0,0],[0,0]], 'omg')
|
|
|
|
expect(editor.isModified()).toBeTruthy()
|
|
|
|
|
2013-11-09 00:20:43 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.replace /items/gi, 'okthen', [filePath], (result) ->
|
2013-11-09 00:20:43 +04:00
|
|
|
results.push(result)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 1
|
|
|
|
expect(results[0].filePath).toBe filePath
|
|
|
|
expect(results[0].replacements).toBe 6
|
|
|
|
|
2013-11-20 03:22:47 +04:00
|
|
|
expect(editor.isModified()).toBeTruthy()
|
2013-11-09 00:20:43 +04:00
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe ".scan(options, callback)", ->
|
|
|
|
describe "when called with a regex", ->
|
2013-09-25 03:37:01 +04:00
|
|
|
it "calls the callback with all regex results in all files in the project", ->
|
|
|
|
results = []
|
2012-08-28 02:36:36 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /(a)+/, (result) ->
|
2013-09-25 03:37:01 +04:00
|
|
|
results.push(result)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-09-25 03:37:01 +04:00
|
|
|
expect(results).toHaveLength(3)
|
2013-11-21 03:35:49 +04:00
|
|
|
expect(results[0].filePath).toBe atom.project.resolve('a')
|
2013-09-25 03:37:01 +04:00
|
|
|
expect(results[0].matches).toHaveLength(3)
|
|
|
|
expect(results[0].matches[0]).toEqual
|
2013-09-26 02:03:50 +04:00
|
|
|
matchText: 'aaa'
|
|
|
|
lineText: 'aaa bbb'
|
|
|
|
lineTextOffset: 0
|
|
|
|
range: [[0, 0], [0, 3]]
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2012-10-30 03:02:06 +04:00
|
|
|
it "works with with escaped literals (like $ and ^)", ->
|
2013-09-25 03:37:01 +04:00
|
|
|
results = []
|
2012-10-30 03:02:06 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /\$\w+/, (result) -> results.push(result)
|
2012-10-30 03:02:06 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-09-25 03:37:01 +04:00
|
|
|
expect(results.length).toBe 1
|
2012-10-30 03:02:06 +04:00
|
|
|
|
2013-09-25 03:37:01 +04:00
|
|
|
{filePath, matches} = results[0]
|
2013-11-21 03:35:49 +04:00
|
|
|
expect(filePath).toBe atom.project.resolve('a')
|
2013-09-24 02:46:57 +04:00
|
|
|
expect(matches).toHaveLength 1
|
2012-10-30 03:02:06 +04:00
|
|
|
expect(matches[0]).toEqual
|
2013-09-17 04:13:33 +04:00
|
|
|
matchText: '$bill'
|
|
|
|
lineText: 'dollar$bill'
|
2013-09-25 03:37:01 +04:00
|
|
|
lineTextOffset: 0
|
2012-10-30 03:02:06 +04:00
|
|
|
range: [[2, 6], [2, 11]]
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
it "works on evil filenames", ->
|
2014-01-01 03:11:29 +04:00
|
|
|
platform.generateEvilFiles()
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([path.join(__dirname, 'fixtures', 'evil-files')])
|
2012-08-28 02:36:36 +04:00
|
|
|
paths = []
|
|
|
|
matches = []
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /evil/, (result) ->
|
2013-09-25 03:37:01 +04:00
|
|
|
paths.push(result.filePath)
|
2013-09-24 02:46:57 +04:00
|
|
|
matches = matches.concat(result.matches)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-10-12 01:09:17 +04:00
|
|
|
_.each(matches, (m) -> expect(m.matchText).toEqual 'evil')
|
|
|
|
|
|
|
|
if platform.isWindows()
|
|
|
|
expect(paths.length).toBe 3
|
|
|
|
expect(paths[0]).toMatch /a_file_with_utf8.txt$/
|
|
|
|
expect(paths[1]).toMatch /file with spaces.txt$/
|
|
|
|
expect(path.basename(paths[2])).toBe "utfa\u0306.md"
|
|
|
|
else
|
|
|
|
expect(paths.length).toBe 5
|
|
|
|
expect(paths[0]).toMatch /a_file_with_utf8.txt$/
|
|
|
|
expect(paths[1]).toMatch /file with spaces.txt$/
|
|
|
|
expect(paths[2]).toMatch /goddam\nnewlines$/m
|
|
|
|
expect(paths[3]).toMatch /quote".txt$/m
|
|
|
|
expect(path.basename(paths[4])).toBe "utfa\u0306.md"
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-09-19 01:41:38 +04:00
|
|
|
it "ignores case if the regex includes the `i` flag", ->
|
2013-09-24 02:46:57 +04:00
|
|
|
results = []
|
2013-09-19 01:41:38 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /DOLLAR/i, (result) -> results.push(result)
|
2013-09-19 01:41:38 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-09-24 02:46:57 +04:00
|
|
|
expect(results).toHaveLength 1
|
2013-01-09 03:24:14 +04:00
|
|
|
|
2013-04-05 19:45:00 +04:00
|
|
|
describe "when the core.excludeVcsIgnoredPaths config is truthy", ->
|
|
|
|
[projectPath, ignoredPath] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
2013-09-24 02:46:57 +04:00
|
|
|
sourceProjectPath = path.join(__dirname, 'fixtures', 'git', 'working-dir')
|
2013-11-21 04:45:26 +04:00
|
|
|
projectPath = path.join(temp.mkdirSync("atom"))
|
2013-09-24 02:46:57 +04:00
|
|
|
|
|
|
|
writerStream = fstream.Writer(projectPath)
|
|
|
|
fstream.Reader(sourceProjectPath).pipe(writerStream)
|
|
|
|
|
|
|
|
waitsFor (done) ->
|
|
|
|
writerStream.on 'close', done
|
|
|
|
writerStream.on 'error', done
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
fs.rename(path.join(projectPath, 'git.git'), path.join(projectPath, '.git'))
|
|
|
|
ignoredPath = path.join(projectPath, 'ignored.txt')
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(ignoredPath, 'this match should not be included')
|
2013-04-05 19:45:00 +04:00
|
|
|
|
|
|
|
afterEach ->
|
2013-11-01 00:43:44 +04:00
|
|
|
fs.removeSync(projectPath) if fs.existsSync(projectPath)
|
2013-04-05 19:45:00 +04:00
|
|
|
|
|
|
|
it "excludes ignored files", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([projectPath])
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set('core.excludeVcsIgnoredPaths', true)
|
2013-09-24 02:46:57 +04:00
|
|
|
resultHandler = jasmine.createSpy("result found")
|
2013-04-05 19:45:00 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /match/, (results) ->
|
2013-09-24 02:46:57 +04:00
|
|
|
resultHandler()
|
2013-04-05 19:45:00 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-09-24 02:46:57 +04:00
|
|
|
expect(resultHandler).not.toHaveBeenCalled()
|
2013-04-05 19:45:00 +04:00
|
|
|
|
2013-09-17 03:11:01 +04:00
|
|
|
it "includes only files when a directory filter is specified", ->
|
2013-11-21 04:45:26 +04:00
|
|
|
projectPath = path.join(path.join(__dirname, 'fixtures', 'dir'))
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([projectPath])
|
2013-09-17 03:11:01 +04:00
|
|
|
|
|
|
|
filePath = path.join(projectPath, 'a-dir', 'oh-git')
|
|
|
|
|
|
|
|
paths = []
|
|
|
|
matches = []
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /aaa/, paths: ["a-dir#{path.sep}"], (result) ->
|
2013-09-25 03:37:01 +04:00
|
|
|
paths.push(result.filePath)
|
2013-09-24 02:46:57 +04:00
|
|
|
matches = matches.concat(result.matches)
|
2013-09-17 03:11:01 +04:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(paths.length).toBe 1
|
|
|
|
expect(paths[0]).toBe filePath
|
|
|
|
expect(matches.length).toBe 1
|
|
|
|
|
2013-04-12 22:47:11 +04:00
|
|
|
it "includes files and folders that begin with a '.'", ->
|
2013-11-21 04:45:26 +04:00
|
|
|
projectPath = temp.mkdirSync()
|
2013-06-13 03:20:40 +04:00
|
|
|
filePath = path.join(projectPath, '.text')
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(filePath, 'match this')
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([projectPath])
|
2013-04-12 22:47:11 +04:00
|
|
|
paths = []
|
|
|
|
matches = []
|
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /match this/, (result) ->
|
2013-09-25 03:37:01 +04:00
|
|
|
paths.push(result.filePath)
|
2013-09-24 02:46:57 +04:00
|
|
|
matches = matches.concat(result.matches)
|
2013-04-12 22:47:11 +04:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(paths.length).toBe 1
|
|
|
|
expect(paths[0]).toBe filePath
|
|
|
|
expect(matches.length).toBe 1
|
2013-04-05 19:45:00 +04:00
|
|
|
|
2013-09-25 00:36:52 +04:00
|
|
|
it "excludes values in core.ignoredNames", ->
|
2013-11-21 04:45:26 +04:00
|
|
|
projectPath = path.join(__dirname, 'fixtures', 'git', 'working-dir')
|
2013-11-11 21:16:44 +04:00
|
|
|
ignoredNames = atom.config.get("core.ignoredNames")
|
2013-09-25 00:36:52 +04:00
|
|
|
ignoredNames.push("a")
|
2013-11-11 21:16:44 +04:00
|
|
|
atom.config.set("core.ignoredNames", ignoredNames)
|
2013-09-25 00:36:52 +04:00
|
|
|
|
|
|
|
resultHandler = jasmine.createSpy("result found")
|
2013-05-22 05:46:03 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /dollar/, (results) ->
|
2013-09-25 00:36:52 +04:00
|
|
|
resultHandler()
|
2013-05-22 05:46:03 +04:00
|
|
|
|
|
|
|
runs ->
|
2013-09-25 00:36:52 +04:00
|
|
|
expect(resultHandler).not.toHaveBeenCalled()
|
2013-10-25 02:32:32 +04:00
|
|
|
|
|
|
|
it "scans buffer contents if the buffer is modified", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2013-10-25 02:32:32 +04:00
|
|
|
results = []
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open('a').then (o) ->
|
|
|
|
editor = o
|
|
|
|
editor.setText("Elephant")
|
|
|
|
|
2013-10-25 02:32:32 +04:00
|
|
|
waitsForPromise ->
|
2013-11-21 03:35:49 +04:00
|
|
|
atom.project.scan /a|Elephant/, (result) -> results.push result
|
2013-10-25 02:32:32 +04:00
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 3
|
|
|
|
resultForA = _.find results, ({filePath}) -> path.basename(filePath) == 'a'
|
|
|
|
expect(resultForA.matches).toHaveLength 1
|
|
|
|
expect(resultForA.matches[0].matchText).toBe 'Elephant'
|
2013-11-27 02:24:48 +04:00
|
|
|
|
2014-02-28 02:41:15 +04:00
|
|
|
it "ignores buffers outside the project", ->
|
2014-04-24 03:50:25 +04:00
|
|
|
editor = null
|
2014-02-28 02:41:15 +04:00
|
|
|
results = []
|
2014-04-24 03:50:25 +04:00
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.open(temp.openSync().path).then (o) ->
|
|
|
|
editor = o
|
|
|
|
editor.setText("Elephant")
|
|
|
|
|
2014-02-28 02:41:15 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.project.scan /Elephant/, (result) -> results.push result
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(results).toHaveLength 0
|
|
|
|
|
2013-11-27 02:24:48 +04:00
|
|
|
describe ".eachBuffer(callback)", ->
|
|
|
|
beforeEach ->
|
|
|
|
atom.project.bufferForPathSync('a')
|
|
|
|
|
|
|
|
it "invokes the callback for existing buffer", ->
|
|
|
|
count = 0
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
callback = (buffer) ->
|
|
|
|
callbackBuffer = buffer
|
|
|
|
count++
|
|
|
|
atom.project.eachBuffer(callback)
|
|
|
|
expect(count).toBe 1
|
|
|
|
expect(callbackBuffer).toBe atom.project.getBuffers()[0]
|
|
|
|
|
|
|
|
it "invokes the callback for new buffers", ->
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
callback = (buffer) ->
|
|
|
|
callbackBuffer = buffer
|
|
|
|
count++
|
|
|
|
|
|
|
|
atom.project.eachBuffer(callback)
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
atom.project.bufferForPathSync(require.resolve('./fixtures/sample.txt'))
|
|
|
|
expect(count).toBe 1
|
|
|
|
expect(callbackBuffer).toBe atom.project.getBuffers()[1]
|