diff options
Diffstat (limited to '.vim/test')
-rw-r--r-- | .vim/test/autoload/lib_test.rb | 468 | ||||
-rw-r--r-- | .vim/test/autoload_test.rb | 561 | ||||
-rw-r--r-- | .vim/test/ftdetect_test.rb | 45 | ||||
-rw-r--r-- | .vim/test/helper.rb | 54 | ||||
-rw-r--r-- | .vim/test/plugin_test.rb | 85 | ||||
-rw-r--r-- | .vim/test/vimrc | 14 |
6 files changed, 0 insertions, 1227 deletions
diff --git a/.vim/test/autoload/lib_test.rb b/.vim/test/autoload/lib_test.rb deleted file mode 100644 index e39280c..0000000 --- a/.vim/test/autoload/lib_test.rb +++ /dev/null @@ -1,468 +0,0 @@ -require_relative "../helper" -require "json" - -describe "Lib" do - include WithTemporaryDirectory - - before do - # Some tests may change the working directory, so reset it to a known good. - $vim.command "cd #{Dir.getwd}" - Dir.mkdir File.join(@dir, "node_modules") - end - - def set_node_version(version) - executable = File.join(@dir, "node") - touch executable, <<-end.strip - #!/bin/sh - [ $# != 1 -o "$1" != --version ] && exit 1 - echo "v#{version}" - end - File.chmod 0755, executable - $vim.command(%(let $PATH = "#@dir:" . $PATH)) - end - - describe "node#lib#find" do - def find(name) - path = $vim.echo(%(node#lib#find("#{name}", expand("%")))) - File.exists?(path) ? File.realpath(path) : path - end - - it "must return ./README before ./README.js" do - target = touch File.join(@dir, "README") - touch File.join(@dir, "README.js") - - $vim.edit File.join(@dir, "index.js") - find("./README").must_equal target - end - - it "must return ./README.txt relative to file" do - target = touch File.join(@dir, "lib", "README.txt") - $vim.edit File.join(@dir, "lib", "index.js") - find("./README.txt").must_equal target - end - - it "must return ../README.txt" do - target = 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 target - end - - it "must return /.../README.txt" do - target = 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 target - end - - it "must return ./other.js given ./other" do - target = touch File.join(@dir, "other.js") - $vim.edit File.join(@dir, "index.js") - find("./other").must_equal target - end - - it "must return ./other.jsx given ./other" do - target = touch File.join(@dir, "other.jsx") - $vim.edit File.join(@dir, "index.js") - find("./other").must_equal target - end - - it "must return ./other.es given ./other" do - target = touch File.join(@dir, "other.es") - $vim.edit File.join(@dir, "index.js") - find("./other").must_equal target - end - - it "must return ./other.js given ./other relative to file" do - target = touch File.join(@dir, "lib", "other.js") - $vim.edit File.join(@dir, "lib", "index.js") - find("./other").must_equal target - end - - it "must return ./other.js before ./other/index.js given ./other" do - target = touch File.join(@dir, "other.js") - touch File.join(@dir, "other", "index.js") - $vim.edit File.join(@dir, "index.js") - find("./other").must_equal target - end - - it "must return ../other.js given ../other" do - target = touch File.join(@dir, "other.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "index.js") - find("../other").must_equal target - end - - it "must return /.../other.js given /.../other" do - target = 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 target - end - - it "must return ./package.json given ./package" do - target = touch File.join(@dir, "package.json") - $vim.edit File.join(@dir, "index.js") - find("./package").must_equal target - end - - it "must return ./index.js given ." do - target = touch File.join(@dir, "index.js") - $vim.edit File.join(@dir, "other.js") - find(".").must_equal target - end - - it "must return ./index.js given ./" do - target = touch File.join(@dir, "index.js") - $vim.edit File.join(@dir, "other.js") - find("./").must_equal target - 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#lib#find("./", expand("%"))))).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#lib#find("./", expand("%"))))).must_equal "1" - end - - it "must return ../index.js given .." do - target = touch File.join(@dir, "index.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "other.js") - find("..").must_equal target - end - - it "must return ../index.js given ../" do - target = touch File.join(@dir, "index.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "other.js") - find("../").must_equal target - end - - it "must return /.../index.js given /..." do - target = touch File.join(@dir, "index.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "index.js") - find("#@dir").must_equal target - end - - it "must return /.../index.js given /.../" do - target = touch File.join(@dir, "index.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "index.js") - find("#@dir/").must_equal target - end - - it "must return ./lib/index.js given ./lib" do - target = touch File.join(@dir, "lib", "index.js") - $vim.edit File.join(@dir, "index.js") - find("./lib").must_equal target - end - - it "must return ./lib/other.js given ./lib with main" do - target = 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 target - end - - it "must return ./lib/index.js given ./lib with empty main" do - target = 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 target - end - - it "must return ./lib/index.js given ./lib with non-existent main" do - target = 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 target - end - - it "must return ./other.js before ./other/index.js given . with main" do - touch File.join(@dir, "package.json"), JSON.dump(:main => "other") - target = touch File.join(@dir, "other.js") - touch File.join(@dir, "other", "index.js") - - $vim.edit File.join(@dir, "index.js") - find(".").must_equal target - 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") - target = touch File.join(mod, "other.js") - - $vim.edit File.join(@dir, "index.js") - find("foo").must_equal target - 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") - target = touch File.join(mod, "lib/index.js") - - $vim.edit File.join(@dir, "index.js") - find("foo").must_equal target - 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") - target = touch File.join(mod, "lib/index.js") - - $vim.edit File.join(@dir, "index.js") - find("foo").must_equal target - end - - it "must return node_modules/@scope/foo/index.js given @scope/foo" do - target = File.join(@dir, "node_modules", "@scope", "foo", "index.js") - touch target - $vim.edit File.join(@dir, "index.js") - find("@scope/foo").must_equal target - end - - it "must return empty when looking for nothing" do - $vim.edit File.join(@dir, "index.js") - $vim.echo(%(empty(node#lib#find("", expand("%"))))).must_equal "1" - end - - it "must return empty when nothing found" do - $vim.edit File.join(@dir, "index.js") - $vim.echo(%(empty(node#lib#find("new", expand("%"))))).must_equal "1" - end - - it "must return URL for core module for current Node version" do - set_node_version "0.13.37" - $vim.edit File.join(@dir, "index.js") - url = "https://rawgit.com/nodejs/node/v0.13.37/lib/assert.js" - find("assert").must_equal url - end - - it "must return URL for core module on master if no Node version" do - touch File.join(@dir, "node"), "#!/bin/sh\nexit 1" - File.chmod 0755, File.join(@dir, "node") - $vim.edit File.join(@dir, "index.js") - $vim.command(%(let $PATH = "#@dir:" . $PATH)) - url = "https://rawgit.com/nodejs/node/master/lib/assert.js" - find("assert").must_equal url - end - - it "must return URL for node.js for current Node version" do - set_node_version "0.13.37" - $vim.edit File.join(@dir, "index.js") - url = "https://rawgit.com/nodejs/node/v0.13.37/src/node.js" - find("node").must_equal url - end - - it "must return URL for node.js on master if no Node version" do - touch File.join(@dir, "node"), "#!/bin/sh\nexit 1" - File.chmod 0755, File.join(@dir, "node") - $vim.edit File.join(@dir, "index.js") - $vim.command(%(let $PATH = "#@dir:" . $PATH)) - url = "https://rawgit.com/nodejs/node/master/src/node.js" - find("node").must_equal url - end - end - - describe "node#lib#glob" do - require "json" - - before do - $vim.edit File.join(@dir, "index.js") - end - - def glob(arg = "") - # Because of possible locale and filesystem case-sensitiveness - # differences, sort the output explicitly to be resistant. - JSON.parse($vim.echo(%(node#lib#glob("#{arg}"))).gsub("'", '"')).sort - end - - describe "given nothing" do - it "must return files and directories" do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README.txt") - Dir.mkdir File.join(@dir, "test") - - files = %w[./README.txt ./index.js ./test/] - glob.must_equal (CORE_MODULES + files).sort - end - - it "must return modules and core modules" do - FileUtils.mkpath File.join(@dir, "node_modules", "require-guard") - FileUtils.mkpath File.join(@dir, "node_modules", "export") - FileUtils.mkpath File.join(@dir, "node_modules", "soul") - glob.must_equal (CORE_MODULES + %w[export/ require-guard/ soul/]).sort - end - - it "must return core modules without slashes" do - glob.must_equal CORE_MODULES - glob.wont_equal /\// - end - - # Even though node.js is the bootstrapper file in src/. - it "must return \"node\" as one of those core modules" do - glob.must_include "node" - end - - it "must return files, directories and modules" do - FileUtils.mkpath File.join(@dir, "node_modules", "export") - FileUtils.mkpath File.join(@dir, "node_modules", "soul") - touch File.join(@dir, "index.js") - touch File.join(@dir, "README.txt") - Dir.mkdir File.join(@dir, "test") - - files = %w[./README.txt ./index.js ./test/ export/ soul/] - glob.must_equal (CORE_MODULES + files).sort - end - - it "must not return the node_modules directory" do - FileUtils.mkpath File.join(@dir, "node_modules") - glob.must_equal CORE_MODULES - end - end - - describe "given absolute path" do - it "must return files and directories given /" do - files = Dir.entries("/") - files.reject! {|f| f =~ /^\./ } - files.sort! - files.map! {|f| "/" + f } - files.map! {|f| File.directory?(f) ? f + "/" : f } - - glob("/").must_equal files - end - - it "must return files and directories given /.../" do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README") - Dir.mkdir File.join(@dir, "test") - - files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/] - glob(@dir).must_equal files - end - - it "must return files and directories given /.../test" do - touch File.join(@dir, "test", "index_test.js") - touch File.join(@dir, "test", "helpers.js") - files = %W[#@dir/test/helpers.js #@dir/test/index_test.js] - glob(File.join(@dir, "test")).must_equal files - end - - it "must not return modules along with files" do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README") - Dir.mkdir File.join(@dir, "test") - FileUtils.mkpath File.join(@dir, "node_modules", "soul") - - files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/] - glob(@dir).must_equal files - end - end - - describe "given relative path" do - it "must return files and directories given ." do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README") - Dir.mkdir File.join(@dir, "test") - glob(".").must_equal %W[./README ./index.js ./test/] - end - - it "must return files and directories given ./" do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README") - Dir.mkdir File.join(@dir, "test") - glob("./").must_equal %W[./README ./index.js ./test/] - end - - it "must return files and directories given .//" do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README.txt") - Dir.mkdir File.join(@dir, "test") - glob(".//").must_equal %W[.//README.txt .//index.js .//test/] - end - - it "must return files and directories given .///" do - touch File.join(@dir, "index.js") - touch File.join(@dir, "README.txt") - Dir.mkdir File.join(@dir, "test") - glob(".///").must_equal %W[.///README.txt .///index.js .///test/] - end - - it "must return files and directories given ./test" do - touch File.join(@dir, "test", "test.js") - touch File.join(@dir, "test", "helpers.js") - glob("./test/").must_equal %W[./test/helpers.js ./test/test.js] - end - end - - describe "given module name" do - it "must return files and directories given soul" do - touch File.join(@dir, "node_modules", "soul", "index.js") - touch File.join(@dir, "node_modules", "soul", "README") - FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") - glob("soul").must_equal %w[soul/README soul/index.js soul/test/] - end - - it "must return files and directories given soul/" do - touch File.join(@dir, "node_modules", "soul", "index.js") - FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") - glob("soul/").must_equal %w[soul/index.js soul/test/] - end - - it "must return files and directories given soul//" do - touch File.join(@dir, "node_modules", "soul", "index.js") - FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") - glob("soul//").must_equal %w[soul//index.js soul//test/] - end - - it "must return files and directories given soul///" do - touch File.join(@dir, "node_modules", "soul", "index.js") - FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") - glob("soul///").must_equal %w[soul///index.js soul///test/] - end - - it "must return files and directories given soul/test" do - touch File.join(@dir, "node_modules", "soul", "test", "test.js") - touch File.join(@dir, "node_modules", "soul", "test", "helpers.js") - glob("soul/test").must_equal %w[soul/test/helpers.js soul/test/test.js] - end - end - end - - describe "node#lib#version" do - it "should return current Node's version" do - set_node_version "0.13.37" - $vim.echo("node#lib#version()").must_equal "0.13.37" - end - end -end diff --git a/.vim/test/autoload_test.rb b/.vim/test/autoload_test.rb deleted file mode 100644 index aa9bb49..0000000 --- a/.vim/test/autoload_test.rb +++ /dev/null @@ -1,561 +0,0 @@ -require_relative "./helper" -require "json" - -describe "Autoloaded" do - include WithTemporaryDirectory - - before do - 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" - $vim.edit File.join(@dir, "other.js") - $vim.echo(%(g:node_autocommand)).must_equal "1337" - end - end - - describe "Goto file" do - it "must define plug mapping in non-JavaScript files" do - $vim.edit File.join(@dir, "README") - $vim.echo(%(maparg("<Plug>NodeGotoFile", "n"))).wont_equal "" - end - - it "must not be mapped in non-JavaScript files" do - $vim.edit File.join(@dir, "README") - $vim.echo(%(hasmapto("<Plug>NodeGotoFile"))).must_equal "0" - end - - it "must edit README.txt" do - touch File.join(@dir, "index.js"), %(// Please read README.txt) - touch File.join(@dir, "README.txt") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$gf" - $vim.echo(%(bufname("%"))).must_equal File.join(@dir, "README.txt") - end - - it "must edit README before README.js" do - touch File.join(@dir, "index.js"), "// Please read README" - touch File.join(@dir, "README") - touch File.join(@dir, "README.js") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$gf" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "README") - end - - it "must edit ./README.txt relative to file" do - touch File.join(@dir, "foo", "index.js"), %(// Please read ./README.txt) - touch File.join(@dir, "foo", "README.txt") - - $vim.edit File.join(@dir, "foo", "index.js") - $vim.feedkeys "$gf" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "foo", "README.txt") - end - - it "must edit /.../README.txt" do - touch File.join(@dir, "index.js"), %(// Read #@dir/lib/README.txt) - touch File.join(@dir, "lib", "README.txt") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$gf" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "lib", "README.txt") - end - - it "must edit ./other.js relative to file" do - touch File.join(@dir, "foo", "index.js"), %(require("./other")) - touch File.join(@dir, "foo", "other.js") - - $vim.edit File.join(@dir, "foo", "index.js") - $vim.feedkeys "f.gf" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "foo", "other.js") - end - - it "must edit ./index.js given ." do - touch File.join(@dir, "other.js"), %(require(".")) - touch File.join(@dir, "index.js") - - $vim.edit File.join(@dir, "other.js") - $vim.feedkeys "f.gf" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit ./index.js given ./" do - touch File.join(@dir, "other.js"), %(require("./")) - touch File.join(@dir, "index.js") - - $vim.edit File.join(@dir, "other.js") - $vim.feedkeys "f.gf" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit ../index.js given .." do - touch File.join(@dir, "foo", "other.js"), %(require("..")) - touch File.join(@dir, "index.js") - - $vim.edit File.join(@dir, "foo", "other.js") - $vim.feedkeys "f.gf" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit ../index.js given ../" do - touch File.join(@dir, "foo", "other.js"), %(require("../")) - touch File.join(@dir, "index.js") - - $vim.edit File.join(@dir, "foo", "other.js") - $vim.feedkeys "f.gf" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit ./node_modules/foo/index.js given foo" do - touch File.join(@dir, "index.js"), %(require("foo")) - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must edit ./node_modules/@scope/foo/index.js given @scope/foo" do - touch File.join(@dir, "index.js"), %(require("@scope/foo")) - target = File.join(@dir, "node_modules", "@scope", "foo", "index.js") - touch target - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must edit ./foo.js given root/foo with root as symlink" do - touch File.join(@dir, "index.js"), %(require("root/foo")) - target = touch File.join(@dir, "foo.js") - FileUtils.mkpath File.join(@dir, "node_modules") - File.symlink "..", File.join(@dir, "node_modules", "root") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must relativize paths" do - touch File.join(@dir, "index.js"), %(require("root/foo")) - target = touch File.join(@dir, "foo.js") - FileUtils.mkpath File.join(@dir, "node_modules") - File.symlink "..", File.join(@dir, "node_modules", "root") - - $vim.edit File.join(@dir, "index.js") - $vim.command %(:cd %:h) - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal File.basename(target) - end - - it "must not show an error when searching for nothing" do - touch File.join(@dir, "index.js"), %("") - - $vim.edit File.join(@dir, "index.js") - $vim.command(%(let v:errmsg = "")) - $vim.feedkeys "gf" - - error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "") - error.must_equal "" - end - - it "must show error when searching for a non-existent file" do - touch File.join(@dir, "index.js"), %(require("new")) - - $vim.edit File.join(@dir, "index.js") - $vim.command(%(let v:errmsg = "")) - $vim.feedkeys "$hhgf" - - error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "") - error.must_equal %(E447: Can't find file "new" in path) - end - - it "must find when filetype is JavaScript and file exists" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - touch File.join(@dir, "index.js"), %(require("foo")) - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must find when filetype is JavaScript and file new" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - $vim.edit File.join(@dir, "index.js") - $vim.insert %(require("foo")) - $vim.normal - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must find when filetype is JSON" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - # NOTE: Use an extensionless file and set ft manually to not have - # filetype.vim set its filetype to JavaScript automatically. - $vim.command("au BufReadPre package set ft=json") - touch File.join(@dir, "package"), %({"dependencies": {"foo": "1.x"}}) - $vim.edit File.join(@dir, "package") - $vim.echo("&filetype").must_equal "json" - - $vim.feedkeys "/foo\\<CR>gf" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal target - end - - it "must find when filetype set to JavaScript after open" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - touch File.join(@dir, "index.react"), %(require("foo")) - $vim.edit File.join(@dir, "index.react") - $vim.echo("&filetype").must_equal "" - $vim.command("setfiletype javascript") - $vim.echo("&filetype").must_equal "javascript" - - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must find when filetype set to JSX after open" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - touch File.join(@dir, "index.react"), %(require("foo")) - $vim.edit File.join(@dir, "index.react") - $vim.echo("&filetype").must_equal "" - $vim.command("setfiletype jsx") - $vim.echo("&filetype").must_equal "jsx" - - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - it "must find when filetype set to JavaScript and Foo after open" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - touch File.join(@dir, "index.react"), %(require("foo")) - $vim.edit File.join(@dir, "index.react") - $vim.echo("&filetype").must_equal "" - $vim.command("setfiletype javascript.foo") - $vim.echo("&filetype").must_equal "javascript.foo" - - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - - # Ensure the autocommand detects both orderings. - it "must find when filetype set to Foo and JavaScript after open" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - - touch File.join(@dir, "index.react"), %(require("foo")) - $vim.edit File.join(@dir, "index.react") - $vim.echo("&filetype").must_equal "" - $vim.command("setfiletype foo.javascript") - $vim.echo("&filetype").must_equal "foo.javascript" - - $vim.feedkeys "$hhgf" - $vim.echo(%(bufname("%"))).must_equal target - end - end - - describe "Goto file with split" do - it "must edit file in a new split" do - touch File.join(@dir, "index.js"), %(require("./other")) - touch File.join(@dir, "other.js") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "f.\\<C-w>f" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "other.js") - $vim.echo(%(winnr("$"))).must_equal "2" - end - end - - describe "Goto file with tab" do - it "must edit file in a new tab" do - touch File.join(@dir, "index.js"), %(require("./other")) - touch File.join(@dir, "other.js") - - $vim.edit File.join(@dir, "index.js") - $vim.feedkeys "f.\\<C-w>gf" - - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "other.js") - $vim.echo(%(tabpagenr("$"))).must_equal "2" - end - end - - describe "Include file search pattern" do - it "must find matches given a require" do - touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "") - var awesome = require("foo") - awesome() - end - - definition = %(module.exports = function awesome() { return 1337 }) - touch File.join(@dir, "node_modules", "foo", "index.js"), definition - - $vim.edit File.join(@dir, "index.js") - $vim.command("normal G[i").must_equal definition - end - - it "must find matches given a relative require" do - touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "") - var awesome = require("./other") - awesome() - end - - definition = %(module.exports = function awesome() { return 1337 }) - touch File.join(@dir, "other.js"), definition - - $vim.edit File.join(@dir, "index.js") - $vim.command("normal G[i").must_equal definition - end - - it "must find matches given a relative require in another directory" do - touch File.join(@dir, "foo", "index.js"), <<-end.gsub(/^\s+/, "") - var awesome = require("./other") - awesome() - end - - definition = %(module.exports = function awesome() { return 1337 }) - touch File.join(@dir, "foo", "other.js"), definition - - $vim.edit File.join(@dir, "foo", "index.js") - $vim.command("normal G[i").must_equal definition - end - end - - describe ":Nedit" do - # NOTE: Test from a non-JavaScript file everywhere to make sure there are - # no dependencies on JavaScript specific settings. - FULL_COMMAND_MATCH = "2" - - it "must be available in non-JavaScript files" do - $vim.edit File.join(@dir, "README.txt") - $vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH - end - - it "must be available in JavaScript files" do - $vim.edit File.join(@dir, "index.js") - $vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH - end - - it "must edit ./README.txt" do - touch File.join(@dir, "README.txt") - $vim.edit File.join(@dir, "CHANGELOG.txt") - $vim.command "Nedit ./README.txt" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "README.txt") - end - - it "must edit ./README.txt relative to node_root" do - touch File.join(@dir, "README.txt") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") - $vim.command "Nedit ./README.txt" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "README.txt") - end - - it "must edit /.../README.txt" do - touch File.join(@dir, "lib", "README.txt") - $vim.edit File.join(@dir, "CHANGELOG.txt") - $vim.command "Nedit #@dir/lib/README.txt" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "lib", "README.txt") - end - - it "must edit ./other.js relative to node_root" do - touch File.join(@dir, "other.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") - $vim.command "Nedit ./other" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "other.js") - end - - it "must edit ./index.js given ." do - touch File.join(@dir, "index.js") - $vim.edit File.join(@dir, "CHANGELOG.txt") - $vim.command "Nedit ." - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit ./index.js given . relative to node_root" do - touch File.join(@dir, "index.js") - Dir.mkdir File.join(@dir, "lib") - $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") - $vim.command "Nedit ." - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit ./index.js given ./" do - touch File.join(@dir, "index.js") - $vim.edit File.join(@dir, "CHANGELOG.txt") - $vim.command "Nedit ./" - bufname = File.realpath($vim.echo(%(bufname("%")))) - bufname.must_equal File.join(@dir, "index.js") - end - - it "must edit /node_modules/foo/index.js given foo" do - target = touch File.join(@dir, "node_modules", "foo", "index.js") - $vim.edit File.join(@dir, "README.txt") - $vim.command("Nedit foo") - $vim.echo(%(bufname("%"))).must_equal target - end - - describe "completion" do - after do - $vim.command("set wildignorecase&") - $vim.command("set fileignorecase&") - end - - def complete(cmd) - cmdline = $vim.command(%(silent! normal! :#{cmd}e)) - cmdline.sub(/^:\w+\s+/, "") - end - - public_core_modules = CORE_MODULES.select {|m| m[0] != "_" } - private_core_modules = CORE_MODULES.select {|m| m[0] == "_" } - - it "must return files, directories, modules" do - Dir.mkdir File.join(@dir, "node_modules") - Dir.mkdir File.join(@dir, "node_modules", "require-guard") - Dir.mkdir File.join(@dir, "node_modules", "export") - Dir.mkdir File.join(@dir, "node_modules", "soul") - touch File.join(@dir, "index.js") - - $vim.edit File.join(@dir, "README.txt") - files = %w[export/ require-guard/ soul/ ./index.js ./package.json] - all = public_core_modules + files - complete("Nedit ").split.sort.must_equal all.sort - end - - it "must return only public core modules" do - $vim.edit File.join(@dir, "README.txt") - modules = public_core_modules + ["./package.json"] - complete("Nedit ").must_equal modules.join(" ") - end - - it "must return private core modules if explicitly asked" do - $vim.edit File.join(@dir, "README.txt") - complete("Nedit _").must_equal private_core_modules.join(" ") - end - - it "must return only matching modules" do - Dir.mkdir File.join(@dir, "node_modules") - Dir.mkdir File.join(@dir, "node_modules", "export") - Dir.mkdir File.join(@dir, "node_modules", "soul") - Dir.mkdir File.join(@dir, "node_modules", "soulstash") - - $vim.edit File.join(@dir, "README.txt") - modules = "smalloc stream string_decoder sys soul/ soulstash/" - complete("Nedit s").must_equal modules - end - - it "must not return modules with matching bit in the middle" do - Dir.mkdir File.join(@dir, "node_modules") - Dir.mkdir File.join(@dir, "node_modules", "soul") - Dir.mkdir File.join(@dir, "node_modules", "soulstash") - Dir.mkdir File.join(@dir, "node_modules", "asoul") - - $vim.edit File.join(@dir, "README.txt") - complete("Nedit sou").must_equal "soul/ soulstash/" - end - - it "must return files and directories in module's directory" do - touch File.join(@dir, "node_modules", "soul", "index.js") - touch File.join(@dir, "node_modules", "soul", "test", "test.js") - $vim.edit File.join(@dir, "README.txt") - complete("Nedit soul/").must_equal "soul/index.js soul/test/" - end - - it "must return files and directories given a double slash" do - touch File.join(@dir, "node_modules", "soul", "index.js") - touch File.join(@dir, "node_modules", "soul", "test", "test.js") - $vim.edit File.join(@dir, "README.txt") - complete("Nedit soul//").must_equal "soul//index.js soul//test/" - end - - it "must return files case-insensitively given &fileignorecase" do - skip if $vim.echo(%(exists("&fileignorecase"))) != "1" - - $vim.command("set fileignorecase") - $vim.command("set nowildignorecase") - - touch File.join(@dir, "node_modules", "soul", "index.js") - touch File.join(@dir, "node_modules", "soul", "CHANGELOG") - $vim.edit File.join(@dir, "README.txt") - complete("Nedit soul/chan").must_equal "soul/CHANGELOG" - end - - it "must return files case-insensitively given only &wildignorecase" do - skip if $vim.echo(%(exists("&wildignorecase"))) != "1" - - $vim.command("set nofileignorecase") - $vim.command("set wildignorecase") - - touch File.join(@dir, "node_modules", "soul", "index.js") - touch File.join(@dir, "node_modules", "soul", "CHANGELOG") - $vim.edit File.join(@dir, "README.txt") - complete("Nedit soul/chan").must_equal "soul/CHANGELOG" - end - end - end - - describe ":Nopen" do - it "must edit and lcd to module's directory" do - touch File.join(@dir, "node_modules", "foo", "package.json") - touch File.join(@dir, "node_modules", "foo", "index.js") - - $vim.edit File.join(@dir, "README.txt") - $vim.command("vsplit") - - $vim.command("Nopen foo") - $vim.echo(%(bufname("%"))).must_equal "index.js" - $vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo") - - $vim.command("wincmd p") - $vim.command("pwd").must_equal Dir.pwd - end - - it "must edit and lcd to module's root directory" do - touch File.join(@dir, "node_modules", "foo", "package.json") - touch File.join(@dir, "node_modules", "foo", "lib", "utils.js") - - $vim.edit File.join(@dir, "README.txt") - $vim.command("vsplit") - - $vim.command("Nopen foo/lib/utils") - $vim.echo(%(bufname("%"))).must_equal "lib/utils.js" - $vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo") - - $vim.command("wincmd p") - $vim.command("pwd").must_equal Dir.pwd - end - end -end diff --git a/.vim/test/ftdetect_test.rb b/.vim/test/ftdetect_test.rb deleted file mode 100644 index b28326e..0000000 --- a/.vim/test/ftdetect_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative "./helper" - -describe "Ftdetect" do - [ - "#!/usr/bin/env node", - "#!/usr/bin/env node --harmony-generators", - "#!/usr/local/bin/env node", - "#!/usr/local/bin/env node --harmony-generators", - "#!/usr/bin/node", - "#!/usr/bin/node --harmony-generators", - "#!/usr/local/bin/node", - "#!/usr/local/bin/node --harmony-generators", - - ].each do |shebang| - it %(must detect a file with "#{shebang}" shebang as JavaScript) do - file = Tempfile.new("bang") - file.write shebang + $/ - file.close - $vim.edit file.path - $vim.echo("&ft").must_equal "javascript" - end - end - - [ - "#!/usr/bin/env noder", - "#!/usr/bin/noder", - - ].each do |shebang| - it %(must not detect a file with "#{shebang}" shebang as JavaScript) do - file = Tempfile.new("bang") - file.write shebang + $/ - file.close - $vim.edit file.path - $vim.echo("&ft").wont_equal "javascript" - end - end - - it "must not detect a .c file as JavaScript even with Node's shebang" do - file = Tempfile.new(%w[tea .c]) - file.write "#!/usr/bin/node" + $/ - file.close - $vim.edit file.path - $vim.echo("&ft").wont_equal "javascript" - end -end diff --git a/.vim/test/helper.rb b/.vim/test/helper.rb deleted file mode 100644 index 5c50977..0000000 --- a/.vim/test/helper.rb +++ /dev/null @@ -1,54 +0,0 @@ -require "minitest/autorun" -require "vimrunner" -require "fileutils" -require "tempfile" - -MiniTest::Unit::TestCase.define_singleton_method(:test_order) do :alpha end - -begin - require "minitest/reporters" - MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new -rescue LoadError -end - -$vimrc = File.expand_path("../vimrc", __FILE__) -$vim = Vimrunner::Server.new(:vimrc => $vimrc).start -Minitest::Unit.after_tests { $vim.kill } - -module WithTemporaryDirectory - def self.included(base) - require "tmpdir" - end - - def setup - super - # Mac has the temporary directory symlinked, so need File.realpath to - # match the paths that Vim returns. - @dir = File.realpath(Dir.mktmpdir) - end - - def teardown - FileUtils.remove_entry_secure @dir - super - end -end - -def touch(path, contents = nil) - FileUtils.mkpath File.dirname(path) - - if contents.nil? || contents.empty? - FileUtils.touch(path) - else - File.open(path, "w") {|f| f.write contents } - end - - path -end - -CORE_MODULES = %w[_debugger _http_agent _http_client _http_common - _http_incoming _http_outgoing _http_server _linklist _stream_duplex - _stream_passthrough _stream_readable _stream_transform _stream_writable - _tls_legacy _tls_wrap assert buffer child_process cluster console - constants crypto dgram dns domain events freelist fs http https module - net node os path punycode querystring readline repl smalloc stream - string_decoder sys timers tls tty url util vm zlib] diff --git a/.vim/test/plugin_test.rb b/.vim/test/plugin_test.rb deleted file mode 100644 index 722c287..0000000 --- a/.vim/test/plugin_test.rb +++ /dev/null @@ -1,85 +0,0 @@ -require_relative "./helper" - -describe "Plugin" do - include WithTemporaryDirectory - - describe "b:node_root" do - it "must be set when in same directory with package.json" do - FileUtils.touch File.join(@dir, "package.json") - $vim.edit File.join(@dir, "index.js") - $vim.echo("b:node_root").must_equal @dir - end - - it "must be set when in same directory with node_modules" do - Dir.mkdir File.join(@dir, "node_modules") - $vim.edit File.join(@dir, "index.js") - $vim.echo("b:node_root").must_equal @dir - end - - it "must be set when ancestor directory has package.json" do - FileUtils.touch File.join(@dir, "package.json") - - nested = File.join(@dir, "lib", "awesomeness") - FileUtils.mkdir_p nested - $vim.edit File.join(nested, "index.js") - $vim.echo("b:node_root").must_equal @dir - end - - it "must be set when ancestor directory has node_modules" do - Dir.mkdir File.join(@dir, "node_modules") - - nested = File.join(@dir, "lib", "awesomeness") - FileUtils.mkdir_p nested - $vim.edit File.join(nested, "index.js") - $vim.echo("b:node_root").must_equal @dir - end - - it "must be set also for other filetypes" do - FileUtils.touch File.join(@dir, "package.json") - - $vim.edit File.join(@dir, "README.txt") - $vim.echo("b:node_root").must_equal @dir - end - - it "must be set in nested Node projects" do - nested = File.join(@dir, "node_modules", "require-guard") - FileUtils.mkdir_p nested - FileUtils.touch File.join(nested, "package.json") - - test = File.join(nested, "test") - FileUtils.mkdir_p test - $vim.edit File.join(test, "index_test.js") - $vim.echo("b:node_root").must_equal nested - end - - it "must not be set when no ancestor has one" do - $vim.edit File.join(@dir, "index_test.js") - $vim.echo(%(exists("b:node_root"))).must_equal "0" - end - - it "must be set from file, not working directory" do - $vim.command "cd #{@dir}" - FileUtils.touch File.join(@dir, "package.json") - - nested = File.join(@dir, "node_modules", "require-guard") - FileUtils.mkdir_p nested - FileUtils.touch File.join(nested, "package.json") - - $vim.edit File.join(nested, "index_test.js") - $vim.echo("b:node_root").must_equal nested - end - - it "must detect directory as Node's when opening Vim" do - begin - Dir.chdir @dir - FileUtils.touch File.join(@dir, "package.json") - - vim = Vimrunner::Server.new(:vimrc => $vimrc).start - vim.command("pwd").must_equal @dir - vim.echo("b:node_root").must_equal @dir - ensure - vim.kill if vim - end - end - end -end diff --git a/.vim/test/vimrc b/.vim/test/vimrc deleted file mode 100644 index 2f05b18..0000000 --- a/.vim/test/vimrc +++ /dev/null @@ -1,14 +0,0 @@ -set nocompatible -set noswapfile -set nobackup -set hidden - -set runtimepath-=~/.vim -set runtimepath-=~/.vim/after -let &runtimepath = expand("<sfile>:p:h:h") . "," . &runtimepath - -filetype plugin indent on -syntax on - -set columns=80 lines=24 -winpos 1337 0 |