2016-01-15 23:35:28 +03:00
|
|
|
DefaultDirectoryProvider = require '../src/default-directory-provider'
|
|
|
|
path = require 'path'
|
2015-05-14 20:39:07 +03:00
|
|
|
fs = require 'fs-plus'
|
2016-12-01 05:41:58 +03:00
|
|
|
temp = require('temp').track()
|
2015-02-13 02:47:09 +03:00
|
|
|
|
|
|
|
describe "DefaultDirectoryProvider", ->
|
2016-12-01 05:41:58 +03:00
|
|
|
tmp = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
tmp = temp.mkdirSync('atom-spec-default-dir-provider')
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
temp.cleanupSync()
|
|
|
|
|
2015-02-13 02:47:09 +03:00
|
|
|
describe ".directoryForURISync(uri)", ->
|
|
|
|
it "returns a Directory with a path that matches the uri", ->
|
|
|
|
provider = new DefaultDirectoryProvider()
|
|
|
|
|
|
|
|
directory = provider.directoryForURISync(tmp)
|
|
|
|
expect(directory.getPath()).toEqual tmp
|
|
|
|
|
2015-02-13 02:47:09 +03:00
|
|
|
it "normalizes its input before creating a Directory for it", ->
|
|
|
|
provider = new DefaultDirectoryProvider()
|
|
|
|
nonNormalizedPath = tmp + path.sep + ".." + path.sep + path.basename(tmp)
|
2015-03-24 07:06:03 +03:00
|
|
|
expect(tmp.includes("..")).toBe false
|
|
|
|
expect(nonNormalizedPath.includes("..")).toBe true
|
2015-02-13 02:47:09 +03:00
|
|
|
|
|
|
|
directory = provider.directoryForURISync(nonNormalizedPath)
|
|
|
|
expect(directory.getPath()).toEqual tmp
|
|
|
|
|
|
|
|
it "creates a Directory for its parent dir when passed a file", ->
|
|
|
|
provider = new DefaultDirectoryProvider()
|
2015-02-20 08:02:31 +03:00
|
|
|
file = path.join(tmp, "example.txt")
|
|
|
|
fs.writeFileSync(file, "data")
|
2015-02-13 02:47:09 +03:00
|
|
|
|
|
|
|
directory = provider.directoryForURISync(file)
|
|
|
|
expect(directory.getPath()).toEqual tmp
|
|
|
|
|
2015-05-27 21:18:15 +03:00
|
|
|
it "creates a Directory with a path as a uri when passed a uri", ->
|
|
|
|
provider = new DefaultDirectoryProvider()
|
|
|
|
uri = 'remote://server:6792/path/to/a/dir'
|
|
|
|
directory = provider.directoryForURISync(uri)
|
|
|
|
expect(directory.getPath()).toEqual uri
|
|
|
|
|
2015-02-13 02:47:09 +03:00
|
|
|
describe ".directoryForURI(uri)", ->
|
|
|
|
it "returns a Promise that resolves to a Directory with a path that matches the uri", ->
|
|
|
|
provider = new DefaultDirectoryProvider()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
provider.directoryForURI(tmp).then (directory) ->
|
|
|
|
expect(directory.getPath()).toEqual tmp
|