.for_file(file)
raises an error if file is nil
assert.raises 'file', -> Project.for_file nil
returns nil by default
File.with_tmpfile (file) ->
assert.is_nil Project.for_file file
(when there is VC found for the file)
vc = root: 'foo_root', files: -> {}
before_each -> VC.register 'vc', find: -> vc
after_each -> VC.unregister 'vc'
returns a project instantiated with the vc and vc root
p = Project.for_file 'file'
assert.not_nil p
assert.equal p.root, vc.root
assert.equal p.vc, vc
adds the new root to .roots
Project.for_file 'file'
assert.same Project.roots, {vc.root}
adds a new entry for the root and project to .open
p = Project.for_file 'file'
assert.same Project.open, { [vc.root]: p }
(when there is a known root containing the file)
returns a new project for the root
with_tmpdir (dir) ->
Project.add_root dir
file = dir / 'test.moon'
p = Project.for_file file
assert.not_nil p
assert.equal p.root, dir
automatically sets the matching VC if possible
with_tmpdir (dir) ->
Project.add_root dir
file = dir / 'test.moon'
vc = root: dir, files: -> {}
VC.register 'vc', find: (file) -> return vc if file == file
p = Project.for_file file
VC.unregister 'vc'
assert.equal p.vc, vc
(when there is an open project containing the file)
returns the existing project
with_tmpdir (dir) ->
Project.add_root dir
file = dir / 'test.moon'
file2 = dir / 'test2.moon'
p = Project.for_file file
p2 = Project.for_file file
assert.not_nil p
assert.equal p2, p