Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move core functions into a separate lib file.

  • Loading branch information...
commit 1925e93ca72f5bb9620f1d62af9be5f4d9bd86e7 1 parent b54af09
@moll authored
View
7 Guardfile
@@ -1,8 +1,7 @@
guard :minitest, :all_on_start => false, :cli => ENV["TEST_OPTS"] do
- watch(%r(^(.*)\.vim)) {|m| [
- "test/#{m[1]}_test.rb",
- "test/#{m[1].sub(/\/\w+$/, "")}_test.rb"
- ]}
+ watch(%r(^(.*)\.vim$)) {|m| "test/#{m[1]}_test.rb" }
+ watch(%r(^([^/]+)/[^/]+\.vim$)) {|m| "test/#{m[1]}_test.rb" }
+ watch(%r(^([^/]+)/[^/]+/(.*)\.vim$)) {|m| "test/#{m[1]}/#{m[2]}_test.rb" }
watch(%r(^test/(.*)\/?_test\.rb))
watch(%r(^test/helper\.rb)) { "test" }
View
92 autoload/node.vim
@@ -1,17 +1,17 @@
-let s:suffixesadd = [".js", ".json"]
-let s:filetypes = ["javascript", "json"]
+let node#suffixesadd = [".js", ".json"]
+let node#filetypes = ["javascript", "json"]
function! node#initialize(root)
let b:node_root = a:root
call s:initializeCommands()
- if index(s:filetypes, &filetype) > -1 | call s:initializeJavaScript() | en
+ if index(g:node#filetypes, &ft) > -1 | call s:initializeJavaScript() | en
silent doautocmd User Node
endfunction
function! s:initializeCommands()
- command! -bar -bang -nargs=1 -buffer Nedit
+ command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nedit
\ exe s:nedit(<q-args>, bufname("%"), "edit<bang>")
- command! -bar -bang -nargs=1 -buffer Nopen
+ command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nopen
\ exe s:nopen(<q-args>, bufname("%"), "edit<bang>")
nnoremap <buffer><silent> <Plug>NodeGotoFile
@@ -26,9 +26,9 @@ endfunction
function! s:initializeJavaScript()
setl path-=/usr/include
- let &l:suffixesadd .= "," . join(s:suffixesadd, ",")
+ let &l:suffixesadd .= "," . join(g:node#suffixesadd, ",")
let &l:include = '\<require(\(["'']\)\zs[^\1]\+\ze\1'
- let &l:includeexpr = s:snr() . "find(v:fname, bufname('%'))"
+ let &l:includeexpr = "node#find(v:fname, bufname('%'))"
if !hasmapto("<Plug>NodeGotoFile")
" Split gotofiles don't take a count for the new window's width, but for
@@ -40,78 +40,9 @@ function! s:initializeJavaScript()
endif
endfunction
-function! s:snr()
- return matchstr(expand("<sfile>"), '.*\zs<SNR>\d\+_')
-endfunction
-
-function! s:find(name, from)
- return s:resolve(s:absolutize(a:name, a:from))
-endfunction
-
-function! s:absolutize(name, from)
- if a:name =~# '^/'
- return a:name
- elseif a:name =~# '^\v\.\.?(/|$)'
- let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h")
- return dir . "/" . a:name
- else
- return b:node_root . "/node_modules/" . a:name
- endif
-endfunction
-
function! node#find(name, ...)
let from = a:0 == 1 ? a:1 : bufname("%")
- return s:find(a:name, from)
-endfunction
-
-function! s:resolve(path)
- " Node checks for files *before* directories, so see if the path does not
- " end with a slash or dots and try to match it as a file.
- if a:path !~# '\v/(\.\.?/?)?$'
- let path_with_suffix = s:resolveSuffix(a:path)
- if !empty(path_with_suffix) | return path_with_suffix | endif
- endif
-
- if isdirectory(a:path) | return s:resolveFromDirectory(a:path) | endif
-endfunction
-
-function! s:resolveFromDirectory(path)
- " Node.js checks for package.json in every directory, not just the
- " module's parent. According to:
- " http://nodejs.org/api/modules.html#modules_all_together
- if filereadable(a:path . "/package.json")
- " Turns out, even though Node says it does not support directories in
- " main, it does.
- " NOTE: If package.json's main is empty or refers to a non-existent file,
- " ./index.js is still tried.
- let main = s:mainFromPackage(a:path . "/package.json")
-
- if !empty(main) && main != ""
- let path = s:resolve(a:path . "/" . main)
- if !empty(path) | return path | endif
- endif
- endif
-
- " We need to check for ./index.js's existence here rather than leave it to
- " the caller, because otherwise we can't distinguish if this ./index was
- " from the directory defaulting to ./index.js or it was the package.json
- " which referred to ./index, which in itself could mean both ./index.js and
- " ./index/index.js.
- return s:resolveSuffix(a:path . "/index")
-endfunction
-
-function! s:mainFromPackage(path)
- for line in readfile(a:path)
- if line !~# '"main"\s*:' | continue | endif
- return matchstr(line, '"main"\s*:\s*"\zs[^"]\+\ze"')
- endfor
-endfunction
-
-function! s:resolveSuffix(path)
- for suffix in s:uniq([""] + s:suffixesadd + split(&l:suffixesadd, ","))
- let path = a:path . suffix
- if filereadable(path) | return path | endif
- endfor
+ return node#lib#find(a:name, from)
endfunction
function! s:edit(name, from, ...)
@@ -123,7 +54,7 @@ function! s:edit(name, from, ...)
if a:name !~# '^\v(/|\./|\.\./)' && filereadable(dir . "/" . a:name)
let path = dir . "/" . a:name
else
- let path = s:find(a:name, dir)
+ let path = node#find(a:name, dir)
end
if empty(path)
@@ -152,8 +83,3 @@ function! s:error(msg)
echohl NONE
let v:errmsg = a:msg
endfunction
-
-function! s:uniq(list)
- let list = reverse(copy(a:list))
- return reverse(filter(list, "index(list, v:val, v:key + 1) == -1"))
-endfunction
View
69 autoload/node/lib.vim
@@ -0,0 +1,69 @@
+function! node#lib#find(name, from)
+ return s:resolve(s:absolutize(a:name, a:from))
+endfunction
+
+function! s:absolutize(name, from)
+ if a:name =~# '^/'
+ return a:name
+ elseif a:name =~# '^\v\.\.?(/|$)'
+ let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h")
+ return dir . "/" . a:name
+ else
+ return b:node_root . "/node_modules/" . a:name
+ endif
+endfunction
+
+function! s:resolve(path)
+ " Node checks for files *before* directories, so see if the path does not
+ " end with a slash or dots and try to match it as a file.
+ if a:path !~# '\v/(\.\.?/?)?$'
+ let path_with_suffix = s:resolveSuffix(a:path)
+ if !empty(path_with_suffix) | return path_with_suffix | endif
+ endif
+
+ if isdirectory(a:path) | return s:resolveFromDirectory(a:path) | endif
+endfunction
+
+function! s:resolveFromDirectory(path)
+ " Node.js checks for package.json in every directory, not just the
+ " module's parent. According to:
+ " http://nodejs.org/api/modules.html#modules_all_together
+ if filereadable(a:path . "/package.json")
+ " Turns out, even though Node says it does not support directories in
+ " main, it does.
+ " NOTE: If package.json's main is empty or refers to a non-existent file,
+ " ./index.js is still tried.
+ let main = s:mainFromPackage(a:path . "/package.json")
+
+ if !empty(main) && main != ""
+ let path = s:resolve(a:path . "/" . main)
+ if !empty(path) | return path | endif
+ endif
+ endif
+
+ " We need to check for ./index.js's existence here rather than leave it to
+ " the caller, because otherwise we can't distinguish if this ./index was
+ " from the directory defaulting to ./index.js or it was the package.json
+ " which referred to ./index, which in itself could mean both ./index.js and
+ " ./index/index.js.
+ return s:resolveSuffix(a:path . "/index")
+endfunction
+
+function! s:mainFromPackage(path)
+ for line in readfile(a:path)
+ if line !~# '"main"\s*:' | continue | endif
+ return matchstr(line, '"main"\s*:\s*"\zs[^"]\+\ze"')
+ endfor
+endfunction
+
+function! s:resolveSuffix(path)
+ for suffix in s:uniq([""] + g:node#suffixesadd + split(&l:suffixesadd, ","))
+ let path = a:path . suffix
+ if filereadable(path) | return path | endif
+ endfor
+endfunction
+
+function! s:uniq(list)
+ let list = reverse(copy(a:list))
+ return reverse(filter(list, "index(list, v:val, v:key + 1) == -1"))
+endfunction
View
233 test/autoload/lib_test.rb
@@ -0,0 +1,233 @@
+require_relative "../helper"
+require "json"
+
+# Test lib through public API as much as possible.
+
+describe "Lib" do
+ include WithTemporaryDirectory
+
+ before do
+ FileUtils.touch File.join(@dir, "package.json")
+ end
+
+ describe "node#find" do
+ def find(path)
+ File.realpath($vim.echo(%(node#find("#{path}"))))
+ end
+
+ it "must return ./README before ./README.js" do
+ touch File.join(@dir, "README")
+ touch File.join(@dir, "README.js")
+
+ $vim.edit File.join(@dir, "index.js")
+ find("./README").must_equal File.join(@dir, "README")
+ end
+
+ it "must return ./README.txt relative to file" do
+ touch File.join(@dir, "lib", "README.txt")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("./README.txt").must_equal File.join(@dir, "lib", "README.txt")
+ end
+
+ it "must return ../README.txt" do
+ touch File.join(@dir, "README.txt")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("../README.txt").must_equal File.join(@dir, "README.txt")
+ end
+
+ it "must return /.../README.txt" do
+ touch File.join(@dir, "README.txt")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("#@dir/README.txt").must_equal File.join(@dir, "README.txt")
+ end
+
+ it "must return ./other.js given ./other" do
+ touch File.join(@dir, "other.js")
+ $vim.edit File.join(@dir, "index.js")
+ find("./other").must_equal File.join(@dir, "other.js")
+ end
+
+ it "must return ./other.js given ./other relative to file" do
+ touch File.join(@dir, "lib", "other.js")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("./other").must_equal File.join(@dir, "lib", "other.js")
+ end
+
+ it "must return ./other.js before ./other/index.js given ./other" do
+ touch File.join(@dir, "other.js")
+ touch File.join(@dir, "other", "index.js")
+ $vim.edit File.join(@dir, "index.js")
+ find("./other").must_equal File.join(@dir, "other.js")
+ end
+
+ it "must return ../other.js given ../other" do
+ touch File.join(@dir, "other.js")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("../other").must_equal File.join(@dir, "other.js")
+ end
+
+ it "must return /.../other.js given /.../other" do
+ touch File.join(@dir, "other.js")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("#@dir/other").must_equal File.join(@dir, "other.js")
+ end
+
+ it "must return ./package.json given ./package" do
+ touch File.join(@dir, "package.json")
+ $vim.edit File.join(@dir, "index.js")
+ find("./package").must_equal File.join(@dir, "package.json")
+ end
+
+ it "must return ./index.js given ." do
+ touch File.join(@dir, "index.js")
+ $vim.edit File.join(@dir, "other.js")
+ find(".").must_equal File.join(@dir, "index.js")
+ end
+
+ it "must return ./index.js given ./" do
+ touch File.join(@dir, "index.js")
+ $vim.edit File.join(@dir, "other.js")
+ find("./").must_equal File.join(@dir, "index.js")
+ end
+
+ it "must not find ./index/index.js given ./" do
+ touch File.join(@dir, "index", "index.js")
+ $vim.edit File.join(@dir, "other.js")
+ $vim.echo(%(empty(node#find("./")))).must_equal "1"
+ end
+
+ it "must not find ./.js given ./" do
+ touch File.join(@dir, ".js")
+ $vim.edit File.join(@dir, "other.js")
+ $vim.echo(%(empty(node#find("./")))).must_equal "1"
+ end
+
+ it "must return ../index.js given .." do
+ touch File.join(@dir, "index.js")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "other.js")
+ find("..").must_equal File.join(@dir, "index.js")
+ end
+
+ it "must return ../index.js given ../" do
+ touch File.join(@dir, "index.js")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "other.js")
+ find("../").must_equal File.join(@dir, "index.js")
+ end
+
+ it "must return /.../index.js given /..." do
+ touch File.join(@dir, "index.js")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("#@dir").must_equal File.join(@dir, "index.js")
+ end
+
+ it "must return /.../index.js given /.../" do
+ touch File.join(@dir, "index.js")
+ Dir.mkdir File.join(@dir, "lib")
+ $vim.edit File.join(@dir, "lib", "index.js")
+ find("#@dir/").must_equal File.join(@dir, "index.js")
+ end
+
+ it "must return ./lib/index.js given ./lib" do
+ touch File.join(@dir, "lib", "index.js")
+ $vim.edit File.join(@dir, "index.js")
+ find("./lib").must_equal File.join(@dir, "lib", "index.js")
+ end
+
+ it "must return ./lib/other.js given ./lib with main" do
+ touch File.join(@dir, "lib", "other.js")
+ touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "other")
+ $vim.edit File.join(@dir, "index.js")
+ find("./lib").must_equal File.join(@dir, "lib", "other.js")
+ end
+
+ it "must return ./lib/index.js given ./lib with empty main" do
+ touch File.join(@dir, "lib", "index.js")
+ touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "")
+ $vim.edit File.join(@dir, "index.js")
+ find("./lib").must_equal File.join(@dir, "lib", "index.js")
+ end
+
+ it "must return ./lib/index.js given ./lib with non-existent main" do
+ touch File.join(@dir, "lib", "index.js")
+ touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "new")
+ $vim.edit File.join(@dir, "index.js")
+ find("./lib").must_equal File.join(@dir, "lib", "index.js")
+ end
+
+ it "must return ./other.js before ./other/index.js given . with main" do
+ touch File.join(@dir, "package.json"), JSON.dump(:main => "other")
+ touch File.join(@dir, "other.js")
+ touch File.join(@dir, "other", "index.js")
+
+ $vim.edit File.join(@dir, "index.js")
+ find(".").must_equal File.join(@dir, "other.js")
+ end
+
+ it "must return node_modules/foo/index.js given foo" do
+ index = File.join(@dir, "node_modules", "foo", "index.js")
+ touch index
+ $vim.edit File.join(@dir, "index.js")
+ find("foo").must_equal index
+ end
+
+ it "must return node_modules/foo/other.js given foo/other" do
+ other = File.join(@dir, "node_modules", "foo", "other.js")
+ touch other
+ $vim.edit File.join(@dir, "index.js")
+ find("foo/other").must_equal other
+ end
+
+ it "must return node_modules/foo/other.js given foo/other.js" do
+ other = File.join(@dir, "node_modules", "foo", "other.js")
+ touch other
+ $vim.edit File.join(@dir, "index.js")
+ find("foo/other.js").must_equal other
+ end
+
+ # When package.json refers to a regular file.
+ it "must return node_modules/foo/other.js given foo with main" do
+ mod = File.join(@dir, "node_modules", "foo")
+ touch File.join(mod, "package.json"), JSON.dump(:main => "./other.js")
+ touch File.join(mod, "other.js")
+
+ $vim.edit File.join(@dir, "index.js")
+ find("foo").must_equal File.join(mod, "other.js")
+ end
+
+ # When package.json refers to a directory.
+ it "must return node_modules/foo/lib/index.js given foo with main as ./lib" do
+ mod = File.join(@dir, "node_modules", "foo")
+ touch File.join(mod, "package.json"), JSON.dump(:main => "./lib")
+ touch File.join(mod, "lib/index.js")
+
+ $vim.edit File.join(@dir, "index.js")
+ find("foo").must_equal File.join(mod, "lib/index.js")
+ end
+
+ it "must return node_modules/foo/lib/index.js given foo with main as lib" do
+ mod = File.join(@dir, "node_modules", "foo")
+ touch File.join(mod, "package.json"), JSON.dump(:main => "lib")
+ touch File.join(mod, "lib/index.js")
+
+ $vim.edit File.join(@dir, "index.js")
+ find("foo").must_equal File.join(mod, "lib/index.js")
+ end
+
+ it "must return empty when looking for nothing" do
+ $vim.edit File.join(@dir, "index.js")
+ $vim.echo(%(empty(node#find("")))).must_equal "1"
+ end
+
+ it "must return empty when nothing found" do
+ $vim.edit File.join(@dir, "index.js")
+ $vim.echo(%(empty(node#find("new")))).must_equal "1"
+ end
+ end
+end
View
225 test/autoload_test.rb
@@ -8,6 +8,10 @@
FileUtils.touch File.join(@dir, "package.json")
end
+ after do
+ $vim.command("windo wincmd c")
+ end
+
describe "Autocommand" do
it "must fire user autcommand \"Node\"" do
$vim.command "au User Node let node_autocommand = 1337"
@@ -16,227 +20,6 @@
end
end
- describe "node#find" do
- def find(path)
- File.realpath($vim.echo(%(node#find("#{path}"))))
- end
-
- it "must return ./README before ./README.js" do
- touch File.join(@dir, "README")
- touch File.join(@dir, "README.js")
-
- $vim.edit File.join(@dir, "index.js")
- find("./README").must_equal File.join(@dir, "README")
- end
-
- it "must return ./README.txt relative to file" do
- touch File.join(@dir, "lib", "README.txt")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("./README.txt").must_equal File.join(@dir, "lib", "README.txt")
- end
-
- it "must return ../README.txt" do
- touch File.join(@dir, "README.txt")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("../README.txt").must_equal File.join(@dir, "README.txt")
- end
-
- it "must return /.../README.txt" do
- touch File.join(@dir, "README.txt")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("#@dir/README.txt").must_equal File.join(@dir, "README.txt")
- end
-
- it "must return ./other.js given ./other" do
- touch File.join(@dir, "other.js")
- $vim.edit File.join(@dir, "index.js")
- find("./other").must_equal File.join(@dir, "other.js")
- end
-
- it "must return ./other.js given ./other relative to file" do
- touch File.join(@dir, "lib", "other.js")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("./other").must_equal File.join(@dir, "lib", "other.js")
- end
-
- it "must return ./other.js before ./other/index.js given ./other" do
- touch File.join(@dir, "other.js")
- touch File.join(@dir, "other", "index.js")
- $vim.edit File.join(@dir, "index.js")
- find("./other").must_equal File.join(@dir, "other.js")
- end
-
- it "must return ../other.js given ../other" do
- touch File.join(@dir, "other.js")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("../other").must_equal File.join(@dir, "other.js")
- end
-
- it "must return /.../other.js given /.../other" do
- touch File.join(@dir, "other.js")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("#@dir/other").must_equal File.join(@dir, "other.js")
- end
-
- it "must return ./package.json given ./package" do
- touch File.join(@dir, "package.json")
- $vim.edit File.join(@dir, "index.js")
- find("./package").must_equal File.join(@dir, "package.json")
- end
-
- it "must return ./index.js given ." do
- touch File.join(@dir, "index.js")
- $vim.edit File.join(@dir, "other.js")
- find(".").must_equal File.join(@dir, "index.js")
- end
-
- it "must return ./index.js given ./" do
- touch File.join(@dir, "index.js")
- $vim.edit File.join(@dir, "other.js")
- find("./").must_equal File.join(@dir, "index.js")
- end
-
- it "must not find ./index/index.js given ./" do
- touch File.join(@dir, "index", "index.js")
- $vim.edit File.join(@dir, "other.js")
- $vim.echo(%(empty(node#find("./")))).must_equal "1"
- end
-
- it "must not find ./.js given ./" do
- touch File.join(@dir, ".js")
- $vim.edit File.join(@dir, "other.js")
- $vim.echo(%(empty(node#find("./")))).must_equal "1"
- end
-
- it "must return ../index.js given .." do
- touch File.join(@dir, "index.js")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "other.js")
- find("..").must_equal File.join(@dir, "index.js")
- end
-
- it "must return ../index.js given ../" do
- touch File.join(@dir, "index.js")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "other.js")
- find("../").must_equal File.join(@dir, "index.js")
- end
-
- it "must return /.../index.js given /..." do
- touch File.join(@dir, "index.js")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("#@dir").must_equal File.join(@dir, "index.js")
- end
-
- it "must return /.../index.js given /.../" do
- touch File.join(@dir, "index.js")
- Dir.mkdir File.join(@dir, "lib")
- $vim.edit File.join(@dir, "lib", "index.js")
- find("#@dir/").must_equal File.join(@dir, "index.js")
- end
-
- it "must return ./lib/index.js given ./lib" do
- touch File.join(@dir, "lib", "index.js")
- $vim.edit File.join(@dir, "index.js")
- find("./lib").must_equal File.join(@dir, "lib", "index.js")
- end
-
- it "must return ./lib/other.js given ./lib with main" do
- touch File.join(@dir, "lib", "other.js")
- touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "other")
- $vim.edit File.join(@dir, "index.js")
- find("./lib").must_equal File.join(@dir, "lib", "other.js")
- end
-
- it "must return ./lib/index.js given ./lib with empty main" do
- touch File.join(@dir, "lib", "index.js")
- touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "")
- $vim.edit File.join(@dir, "index.js")
- find("./lib").must_equal File.join(@dir, "lib", "index.js")
- end
-
- it "must return ./lib/index.js given ./lib with non-existent main" do
- touch File.join(@dir, "lib", "index.js")
- touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "new")
- $vim.edit File.join(@dir, "index.js")
- find("./lib").must_equal File.join(@dir, "lib", "index.js")
- end
-
- it "must return ./other.js before ./other/index.js given . with main" do
- touch File.join(@dir, "package.json"), JSON.dump(:main => "other")
- touch File.join(@dir, "other.js")
- touch File.join(@dir, "other", "index.js")
-
- $vim.edit File.join(@dir, "index.js")
- find(".").must_equal File.join(@dir, "other.js")
- end
-
- it "must return node_modules/foo/index.js given foo" do
- index = File.join(@dir, "node_modules", "foo", "index.js")
- touch index
- $vim.edit File.join(@dir, "index.js")
- find("foo").must_equal index
- end
-
- it "must return node_modules/foo/other.js given foo/other" do
- other = File.join(@dir, "node_modules", "foo", "other.js")
- touch other
- $vim.edit File.join(@dir, "index.js")
- find("foo/other").must_equal other
- end
-
- it "must return node_modules/foo/other.js given foo/other.js" do
- other = File.join(@dir, "node_modules", "foo", "other.js")
- touch other
- $vim.edit File.join(@dir, "index.js")
- find("foo/other.js").must_equal other
- end
-
- # When package.json refers to a regular file.
- it "must return node_modules/foo/other.js given foo with main" do
- mod = File.join(@dir, "node_modules", "foo")
- touch File.join(mod, "package.json"), JSON.dump(:main => "./other.js")
- touch File.join(mod, "other.js")
-
- $vim.edit File.join(@dir, "index.js")
- find("foo").must_equal File.join(mod, "other.js")
- end
-
- # When package.json refers to a directory.
- it "must return node_modules/foo/lib/index.js given foo with main as ./lib" do
- mod = File.join(@dir, "node_modules", "foo")
- touch File.join(mod, "package.json"), JSON.dump(:main => "./lib")
- touch File.join(mod, "lib/index.js")
-
- $vim.edit File.join(@dir, "index.js")
- find("foo").must_equal File.join(mod, "lib/index.js")
- end
-
- it "must return node_modules/foo/lib/index.js given foo with main as lib" do
- mod = File.join(@dir, "node_modules", "foo")
- touch File.join(mod, "package.json"), JSON.dump(:main => "lib")
- touch File.join(mod, "lib/index.js")
-
- $vim.edit File.join(@dir, "index.js")
- find("foo").must_equal File.join(mod, "lib/index.js")
- end
-
- it "must return empty when looking for nothing" do
- $vim.edit File.join(@dir, "index.js")
- $vim.echo(%(empty(node#find("")))).must_equal "1"
- end
-
- it "must return empty when nothing found" do
- $vim.edit File.join(@dir, "index.js")
- $vim.echo(%(empty(node#find("new")))).must_equal "1"
- end
- end
-
describe "Goto file" do
it "must define plug mapping in non-JavaScript files" do
$vim.edit File.join(@dir, "README")
Please sign in to comment.
Something went wrong with that request. Please try again.