1
0
mirror of https://github.com/amix/vimrc synced 2025-06-17 10:55:00 +08:00

Added and updated some plugins

Added: vim-ruby, typescript-vim, vim-javascript
Updated: rust-vim
This commit is contained in:
Amir Salihefendic
2019-11-16 18:43:18 +01:00
parent ff0ede6b30
commit 97e3db7fe9
108 changed files with 12408 additions and 869 deletions

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe "Indenting" do
specify "multi-line arguments" do
assert_correct_indenting <<~EOF
User.new(
:first_name => 'Some',
:second_name => 'Guy'
)
EOF
assert_correct_indenting <<~EOF
User.new(:first_name => 'Some',
:second_name => 'Guy')
EOF
assert_correct_indenting <<~EOF
User.new(
:first_name => 'Some',
:second_name => 'Guy'
)
EOF
end
end

View File

@ -0,0 +1,73 @@
require 'spec_helper'
describe "Indenting" do
specify "if-clauses" do
assert_correct_indenting <<~EOF
if foo
bar
end
EOF
assert_correct_indenting <<~EOF
if foo
bar
else
baz
end
EOF
assert_correct_indenting <<~EOF
bar if foo
something_else
EOF
end
specify "heredocs" do
assert_correct_indenting <<~EOF
def one
two = <<-THREE
four
THREE
end
EOF
assert_correct_indenting <<~EOF
def one
two = <<THREE
four
THREE
end
EOF
assert_correct_indenting <<~EOF
def one
two = <<~THREE
four
THREE
end
EOF
# See https://github.com/vim-ruby/vim-ruby/issues/318 for details
assert_correct_indenting <<~EOF
def foo
<<-EOS
one
\#{two} three
four
EOS
end
EOF
end
specify "comments" do
assert_correct_indenting <<~EOF
def one
example do |something|
=begin
something that is ignored
=end
end
end
EOF
end
end

View File

@ -0,0 +1,167 @@
require 'spec_helper'
describe "Indenting" do
after :each do
vim.command 'let g:ruby_indent_block_style = "expression"'
end
specify "indented blocks with expression style" do
vim.command 'let g:ruby_indent_block_style = "expression"'
assert_correct_indenting <<~EOF
a.
b.
c do |x|
something
end
next_line
EOF
assert_correct_indenting <<~EOF
a.
b.
c { |x|
something
}
next_line
EOF
end
specify "indented blocks with do style" do
vim.command 'let g:ruby_indent_block_style = "do"'
assert_correct_indenting <<~EOF
a.
b.
c do |x|
something
end
next_line
EOF
# Check that "do" style indentation does not mess up indentation
# following the bock.
assert_correct_indenting <<~EOF
a.
b.
c do |x|
something
end
next_line
EOF
# Check that "do" style indenting works properly for brace blocks.
assert_correct_indenting <<~EOF
a.
b.
c { |x|
something
}
next_line
EOF
end
specify "'do' indenting" do
assert_correct_indenting <<~EOF
do
something
end
EOF
assert_correct_indenting <<~EOF
def foo
a_hash = {:do => 'bar'}
end
EOF
assert_correct_indenting <<~EOF
def foo(job)
job.do!
end
EOF
end
specify "blocks with assignment on the previous line" do
assert_correct_indenting <<~EOF
foo =
something do
"other"
end
EOF
assert_correct_indenting <<~EOF
@foo ||=
something do
"other"
end
EOF
end
specify "blocks with multiline parameters" do
assert_correct_indenting <<~EOF
def foo
opts.on('--coordinator host=HOST[,port=PORT]',
'Specify the HOST and the PORT of the coordinator') do |str|
h = sub_opts_to_hash(str)
puts h
end
end
EOF
end
specify "case-insensitive matching" do
vim.set 'ignorecase'
assert_correct_indenting <<~EOF
module X
Class.new do
end
end
EOF
vim.set 'ignorecase&'
end
specify "blocks with tuple arguments" do
assert_correct_indenting <<~EOF
proc do |(a, b)|
puts a
puts b
end
EOF
assert_correct_indenting <<~EOF
proc do |foo, (a, b), bar|
puts a
puts b
end
EOF
assert_correct_indenting <<~EOF
proc do |(a, (b, c)), d|
puts a, b
puts c, d
end
EOF
end
specify "blocks with default arguments" do
assert_correct_indenting <<~EOF
proc do |a = 1|
puts a
end
EOF
# See https://github.com/vim-ruby/vim-ruby/issues/304
assert_correct_indenting <<~EOF
proc do |a: "asdf", b:|
proc do
puts a, b
end
end
EOF
end
end

View File

@ -0,0 +1,317 @@
require 'spec_helper'
describe "Indenting" do
specify "method chaining" do
assert_correct_indenting <<~EOF
some_object.
method_one.
method_two.
method_three
EOF
assert_correct_indenting <<~EOF
some_object
.method_one
.method_two
.method_three
EOF
assert_correct_indenting <<~EOF
some_object&.
method_one&.
method_two&.
method_three
EOF
assert_correct_indenting <<~EOF
some_object
&.method_one
&.method_two
&.method_three
EOF
end
specify "arrays" do
assert_correct_indenting <<~EOF
foo = [one,
two,
three]
EOF
end
specify "tricky string interpolation" do
# See https://github.com/vim-ruby/vim-ruby/issues/75 for details
assert_correct_indenting <<~EOF
puts %{\#{}}
puts "OK"
EOF
assert_correct_indenting <<~EOF
while true
begin
puts %{\#{x}}
rescue ArgumentError
end
end
EOF
end
specify "continuations after round braces" do
assert_correct_indenting <<~EOF
opts.on('--coordinator host=HOST[,port=PORT]',
'Specify the HOST and the PORT of the coordinator') do |str|
h = sub_opts_to_hash(str)
puts h
end
EOF
end
describe "assignments" do
after :each do
vim.command 'let g:ruby_indent_assignment_style = "hanging"'
end
specify "continuations after assignment" do
assert_correct_indenting <<~EOF
variable =
if condition?
1
else
2
end
EOF
assert_correct_indenting <<~EOF
variable = # evil comment
case something
when 'something'
something_else
else
other
end
EOF
assert_correct_indenting <<~EOF
variable = case something
when 'something'
something_else
else
other
end
EOF
assert_correct_indenting <<~EOF
variable = if something == something_else
something_else
elsif other == none
none
else
other
end
EOF
assert_correct_indenting <<~EOF
variable = while
break something
end
EOF
assert_correct_indenting <<~EOF
variable = if [].
map { |x| x * 2 }.
filter { |x| x % 3 == 0 }.
empty?
something
end
EOF
vim.command 'let g:ruby_indent_assignment_style = "variable"'
assert_correct_indenting <<~EOF
variable = case something # evil comment
when 'something'
something_else
else
other
end
EOF
assert_correct_indenting <<~EOF
variable = if something == something_else
something_else
elsif other == none
none
else
other
end
EOF
assert_correct_indenting <<~EOF
variable = while
break something
end
EOF
assert_correct_indenting <<~EOF
variable = if [].
map { |x| x * 2 }.
filter { |x| x % 3 == 0 }.
empty?
something
end
EOF
end
end
specify "continuations after hanging comma" do
assert_correct_indenting <<~EOF
array = [
:one,
].each do |x|
puts x.to_s
end
EOF
end
specify "string interpolation" do
# For details, see:
#
# https://github.com/vim-ruby/vim-ruby/issues/93
# https://github.com/vim-ruby/vim-ruby/issues/160
#
assert_correct_indenting <<~EOF
command = %|\#{file}|
settings.log.info("Returning: \#{command}")
EOF
assert_correct_indenting <<~EOF
{
thing: "[\#{}]",
thong: "b"
}
EOF
assert_correct_indenting <<~EOF
{
a: "(\#{a})",
b: "(\#{b})",
c: "(c)",
d: "(d)",
e: "(e)",
}
EOF
end
specify "closing bracket not on its own line" do
# See https://github.com/vim-ruby/vim-ruby/issues/81 for details
assert_correct_indenting <<~EOF
one { two >>
three }
four
EOF
end
specify "lonesome single parenthesis in a method definition" do
# See https://github.com/vim-ruby/vim-ruby/issues/130 for details
assert_correct_indenting <<~EOF
def bar(
baz
)
return baz+1
end
EOF
end
specify "brackets on their own line, followed by a comma" do
# See https://github.com/vim-ruby/vim-ruby/issues/124 for details
assert_correct_indenting <<~EOF
bla = {
:one => [
{:bla => :blub}
],
:two => (
{:blub => :abc}
),
:three => {
:blub => :abc
},
:four => 'five'
}
EOF
end
specify "string with an and#" do
# See https://github.com/vim-ruby/vim-ruby/issues/108 for details
assert_correct_indenting <<~EOF
outside_block "and#" do
inside_block do
end
end
EOF
end
specify "continuation with a symbol at the end" do
# See https://github.com/vim-ruby/vim-ruby/issues/132 for details
assert_correct_indenting <<~EOF
foo = :+
# Next indents correctly
EOF
end
specify "continuation with a hanging comma" do
# See https://github.com/vim-ruby/vim-ruby/issues/139 for details
assert_correct_indenting <<~EOF
thing :foo
thing 'a',
'b'
EOF
end
specify "continuations in an if-clause condition" do
# See https://github.com/vim-ruby/vim-ruby/issues/215 for details
assert_correct_indenting <<~EOF
if foo || bar ||
bong &&
baz || bing
puts "foo"
end
EOF
end
specify "continuations with round brackets" do
# See https://github.com/vim-ruby/vim-ruby/issues/17 for details
assert_correct_indenting <<~EOF
foo and
(bar and
baz) and
bing
EOF
end
specify "block within an argument list" do
# See https://github.com/vim-ruby/vim-ruby/issues/312 for details
assert_correct_indenting <<~EOF
foo(
x: 1,
y: [1, 2, 3].map { |i|
i + 1
}
)
EOF
end
specify "backslashes" do
# See https://github.com/vim-ruby/vim-ruby/issues/311 for details
assert_correct_indenting <<~EOF
def foo
x = 1
string = ". \#{x}" \\
"xyz"
puts string
puts string
end
EOF
end
end

View File

@ -0,0 +1,31 @@
require 'spec_helper'
describe "Indenting" do
specify "end constructs" do
assert_correct_indenting <<~EOF
f do
g { def h; end }
end
EOF
assert_correct_indenting <<~EOF
if foo
bar ; end
something_else
EOF
assert_correct_indenting <<~EOF
if bar ; end
something_else
EOF
assert_correct_indenting <<~EOF
foo do
foo = 3 . class
foo = lambda { class One; end }
foo = lambda { |args| class One; end }
foo = bar; class One; end
end
EOF
end
end

View File

@ -0,0 +1,18 @@
require 'spec_helper'
describe "Indenting" do
specify "closing html tag after multiline eruby tag" do
assert_correct_indenting 'erb', <<~EOF
<form>
<div>
<%= text_field_tag :email, nil,
placeholder: "email" %>
text
<%= text_field_tag :password, nil,
placeholder: "password" %>
</div>
</form>
EOF
end
end

View File

@ -0,0 +1,10 @@
require 'spec_helper'
describe "Indenting" do
specify "identifiers containing keyword substrings" do
assert_correct_indenting <<~EOF
foo_def
42
EOF
end
end

View File

@ -0,0 +1,137 @@
require 'spec_helper'
describe "Indenting" do
after :each do
vim.command 'let g:ruby_indent_access_modifier_style = "normal"'
end
specify "default indented access modifiers" do
assert_correct_indenting <<~EOF
class OuterClass
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
class InnerClass
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
end
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
end
EOF
end
specify "indented access modifiers" do
vim.command 'let g:ruby_indent_access_modifier_style = "indent"'
assert_correct_indenting <<~EOF
class OuterClass
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
class InnerClass
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
end
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
end
EOF
end
specify "outdented access modifiers" do
vim.command 'let g:ruby_indent_access_modifier_style = "outdent"'
assert_correct_indenting <<~EOF
class OuterClass
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
class InnerClass
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
end
private :method
protected :method
def method; end
protected
def method; end
private
def method; end
public
def method; end
end
EOF
end
end

View File

@ -0,0 +1,40 @@
require 'spec_helper'
describe "Indenting" do
specify "method definitions prefixed with access modifiers" do
assert_correct_indenting <<~EOF
class Foo
public def one(x)
end
private def two(y)
code
end
end
EOF
end
specify "method definitions prefixed with any method call" do
assert_correct_indenting <<~EOF
class Foo
foobar def one(x)
end
foobar? def one(x)
end
foobar! def one(x)
end
фубар def one(x)
end
foobar
def one(x)
end
FooBar1 def two(y)
code
end
end
EOF
end
end

View File

@ -0,0 +1,66 @@
require 'spec_helper'
describe "Indenting" do
specify "nested blocks" do
assert_correct_indenting <<~EOF
var.func1(:param => 'value') do
var.func2(:param => 'value') do
puts "test"
end
end
EOF
assert_correct_indenting <<~EOF
var.func1(:param => 'value') {
var.func2(:param => 'value') {
foo({ bar => baz })
puts "test one"
puts "test two"
}
}
EOF
assert_correct_indenting <<~EOF
var.
func1(:param => 'value') {
var.func2(:param => 'value') {
puts "test"
}
}
EOF
end
specify "nested hashes" do
assert_correct_indenting <<~EOF
foo, bar = {
:bar => {
:one => 'two',
:five => 'six'
}
}
EOF
assert_correct_indenting <<~EOF
foo,
bar = {
:bar => {
:foo => { 'bar' => 'baz' },
:one => 'two',
:three => 'four'
}
}
EOF
end
specify "nested blocks with a continuation and function call inbetween" do
assert_correct_indenting <<~EOF
var.
func1(:param => 'value') {
func1_5(:param => 'value')
var.func2(:param => 'value') {
puts "test"
}
}
EOF
end
end

View File

@ -0,0 +1,46 @@
require 'spec_helper'
describe "Indenting" do
specify "splats with blocks in square brackets" do
assert_correct_indenting <<~EOF
x = Foo[*
y do
z
end
]
EOF
assert_correct_indenting <<~EOF
x = Foo[* # with a comment
y do
z
end
]
EOF
end
specify "splats with blocks in assignment" do
assert_correct_indenting <<~EOF
x = *
array.map do
3
end
EOF
end
specify "splats with blocks in round brackets" do
assert_correct_indenting <<~EOF
x = Foo(*y do
z
end)
EOF
assert_correct_indenting <<~EOF
x = Foo(
*y do
z
end
)
EOF
end
end

View File

@ -0,0 +1,40 @@
require 'vimrunner'
require 'vimrunner/rspec'
Vimrunner::RSpec.configure do |config|
config.reuse_server = true
config.start_vim do
vim = Vimrunner.start_gvim
vim.prepend_runtimepath(File.expand_path('../..', __FILE__))
vim.add_plugin(File.expand_path('../vim', __FILE__), 'plugin/syntax_test.vim')
vim.set 'expandtab'
vim.set 'shiftwidth', 2
vim
end
def assert_correct_indenting(extension='rb', string)
filename = "test.#{extension}"
IO.write filename, string
vim.edit filename
vim.normal 'gg=G'
vim.write
expect(IO.read(filename)).to eq string
end
def assert_correct_highlighting(extension='rb', string, patterns, group)
filename = "test.#{extension}"
IO.write filename, string
vim.edit filename
Array(patterns).each do |pattern|
# TODO: add a custom matcher
expect(vim.echo("TestSyntax('#{pattern}', '#{group}')")).to eq '1'
end
end
end

View File

@ -0,0 +1,17 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "block parameters" do
assert_correct_highlighting <<~'EOF', 'bar', 'rubySymbol'
foo { |bar:| 42 }
EOF
assert_correct_highlighting <<~'EOF', %w[bar\ze: baz\ze:], 'rubySymbol'
foo { |bar: 'bar', baz: 'baz'| 42 }
EOF
end
specify "block parameters with default values including '|'" do
assert_correct_highlighting <<~'EOF', %w[|\zebar qux)\zs|], 'rubyBlockParameterList'
foo { |bar=(baz|qux)| 42 }
EOF
end
end

View File

@ -0,0 +1,54 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "single line comments" do
assert_correct_highlighting <<~'EOF', '#.*', 'rubyComment'
# comment line
EOF
end
specify "end of line comments" do
assert_correct_highlighting <<~'EOF', '#.*', 'rubyComment'
foo = 42 # comment
EOF
end
specify "multiline comments" do
assert_correct_highlighting <<~'EOF', ['#.*line 1', '#.*line 2'], 'rubyComment'
# comment line 1
# comment line 2
EOF
end
specify "embedded documentation" do
assert_correct_highlighting <<~'EOF', 'documentation.*', 'rubyDocumentation'
=begin
documentation line
=end
EOF
# See issue #3
assert_correct_highlighting <<~'EOF', 'documentation.*', 'rubyDocumentation'
=begin rdoc
documentation line
=end rdoc
EOF
end
specify "magic comments" do
assert_correct_highlighting <<~'EOF', 'frozen_string_literal', 'rubyMagicComment'
# frozen_string_literal: true
EOF
end
specify "TODO comments" do
assert_correct_highlighting <<~'EOF', 'TODO', 'rubyTodo'
# TODO: turn off the oven
EOF
end
specify "shebang comments" do
assert_correct_highlighting <<~'EOF', '#.*', 'rubySharpBang'
#!/bin/ruby
EOF
end
end

View File

@ -0,0 +1,23 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "useless line continuations" do
str = <<~'EOF'
foo = \
if true
42
end
EOF
assert_correct_highlighting str, '\\', 'rubyUselessLineContinuation'
assert_correct_highlighting str, 'if', 'rubyConditional'
end
specify "line continuations" do
str = <<~'EOF'
foo = 42 \
if true
EOF
assert_correct_highlighting str, '\\', 'rubyLineContinuation'
assert_correct_highlighting str, 'if', 'rubyConditionalModifier'
end
end

View File

@ -0,0 +1,36 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "method definitions" do
str = <<~'EOF'
def foo bar
end
EOF
assert_correct_highlighting str, %w[def end], 'rubyDefine'
assert_correct_highlighting str, 'foo', 'rubyMethodName'
end
specify "method definitions named 'end'" do
assert_correct_highlighting <<~'EOF', 'end', 'rubyMethodName'
def end end
EOF
assert_correct_highlighting <<~'EOF', 'end', 'rubyMethodName'
def
end
end
EOF
end
specify "method parameters with symbol default values" do
assert_correct_highlighting <<~'EOF', ':baz', 'rubySymbol'
def foo bar=:baz
end
EOF
end
specify "unparenthesised method parameters with a required trailing keyword then semicolon" do
assert_correct_highlighting <<~'EOF', 'bar', 'rubySymbol'
def foo bar:; end
EOF
end
end

View File

@ -0,0 +1,204 @@
require 'spec_helper'
describe "Syntax highlighting" do
before :each do
vim.command 'let g:ruby_operators = 1'
end
after :each do
vim.command 'unlet g:ruby_operators'
end
specify "defined? operator" do
assert_correct_highlighting 'defined? foo', 'defined?', 'rubyDefinedOperator'
end
specify "English boolean operators" do
assert_correct_highlighting <<~'EOF', %w[not and or], 'rubyEnglishBooleanOperator'
not true
true and false
true or false
EOF
end
specify "modulo-assignment operators" do
assert_correct_highlighting <<~'EOF', '%=', 'rubyAssignmentOperator'
foo %= bar
EOF
end
specify "ternary operators" do
assert_correct_highlighting <<~'EOF', %w[? :], 'rubyTernaryOperator'
foo = bar ? 4 : 2
EOF
end
context "bracket operators" do
specify "after a plain identifier" do
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
foo[42]
EOF
end
specify "after a ?!-named bare method call" do
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
foo?[42]
EOF
end
specify "after a closing parenthesis" do
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
(foo)[42]
EOF
end
specify "after a literal hash" do
assert_correct_highlighting <<~'EOF', '\\[...]', 'rubyOperator'
{ foo: bar }[foo]
EOF
end
specify "after a block arg method call" do
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
foo { bar }[42]
EOF
end
end
specify "exponentiation operators" do
[
'foo**bar',
'foo ** bar',
'foo** bar',
].each do |str|
assert_correct_highlighting str, '\*\*', 'rubyArithmeticOperator'
end
end
context "double splat operators" do
specify "in method definitions" do
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
def foo(**bar)
end
EOF
end
specify "in multiline parameter list method definitions" do
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
def foo(bar,
**baz)
end
EOF
end
specify "as an anonymous parameter in method definitions" do
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
def foo(**)
end
EOF
end
specify "in unparenthesised method definitions" do
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
def foo **bar
end
EOF
end
specify "in unparenthesised method calls" do
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
foo **bar
EOF
end
specify "in block parameter lists" do
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
foo { |**bar| 42 }
EOF
end
end
specify "multiplication operators" do
[
'foo*bar',
'foo * bar',
'foo* bar',
].each do |str|
assert_correct_highlighting str, '\*', 'rubyArithmeticOperator'
end
end
context "splat operators" do
specify "in method definitions" do
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
def foo(*bar)
end
EOF
end
specify "in multiline parameter list method definitions" do
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
def foo(bar,
*baz)
end
EOF
end
specify "as an anonymous parameter in method definitions" do
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
def foo(*)
end
EOF
end
specify "in unparenthesised method definitions" do
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
def foo *bar
end
EOF
end
specify "in unparenthesised method calls" do
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
foo *bar
EOF
end
specify "in block parameter lists" do
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
foo { |*bar| 42 }
EOF
end
end
context "proc operators" do
specify "in method definitions" do
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
def foo(&bar)
end
EOF
end
specify "in multiline parameter list method definitions" do
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
def foo(bar,
&baz)
end
EOF
end
specify "in unparenthesised method definitions" do
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
def foo &bar
end
EOF
end
specify "in unparenthesised method calls" do
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
foo &bar
EOF
end
specify "before literal lambdas" do
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
foo &->{}
EOF
end
end
specify "eigenclass operators" do
assert_correct_highlighting <<~'EOF', '<<', 'rubyEigenClassOperator'
class << self
end
EOF
end
specify "superclass operators" do
assert_correct_highlighting <<~'EOF', '<', 'rubySuperClassOperator'
class Foo < Bar
end
EOF
end
end

View File

@ -0,0 +1,21 @@
require 'spec_helper'
describe "Syntax highlighting" do
# See issue #171
specify "ambiguous / at end of line is not a regexp" do
vim.command 'let g:ruby_operators = 1'
assert_correct_highlighting <<~'EOF', '/', 'rubyArithmeticOperator'
a = calculate(90).and_some_long_expression /
and_long_expression_here
puts a
EOF
vim.command 'unlet g:ruby_operators'
end
# See issue #63
specify "interpolated regexp in a host regexp" do
assert_correct_highlighting <<~'EOF', '/$', 'rubyRegexpDelimiter'
/#{foo.sub(/bar/, 'baz')}/
EOF
end
end

View File

@ -0,0 +1,31 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "only modifiers can appear after regexp literals" do
# See issue #254
assert_correct_highlighting <<~'EOF', 'if', 'rubyConditionalModifier'
def get_regex
/some regex/ if false
end
EOF
end
specify "only modifiers can appear after unparenthesised no-arg method calls" do
[
"foo if true",
"foo? if true",
"foo! if true",
"foo_ if true",
"foo_? if true",
"foo_! if true",
"foo42 if true",
"foo42? if true",
"foo42! if true",
"Foo if true",
"Foo? if true",
"Foo! if true"
].each do |str|
assert_correct_highlighting str, 'if', 'rubyConditionalModifier'
end
end
end

View File

@ -0,0 +1,26 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "heredocs starting after parenthesised method definitions" do
# See issue #356
assert_correct_highlighting <<~'EOF', 'HTML', 'rubyHeredocDelimiter'
def youtube_video(token, width = 360, height = 215)
<<-HTML if token
<iframe width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{token}" frameborder="0" allowfullscreen></iframe>
HTML
end
EOF
end
specify "heredocs do not start after string literals" do
assert_correct_highlighting <<~'EOF', 'FOO', 'rubyConstant'
"abc" <<FOO
EOF
assert_correct_highlighting <<~'EOF', 'FOO', 'rubyConstant'
'abc' <<FOO
EOF
assert_correct_highlighting <<~'EOF', 'FOO', 'rubyConstant'
`abc` <<FOO
EOF
end
end

View File

@ -0,0 +1,9 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "invalid interpolated predefined global variables are literal text" do
assert_correct_highlighting <<~'EOF', '#\$', 'rubyString'
"abc(#$)def"
EOF
end
end

View File

@ -0,0 +1,9 @@
require 'spec_helper'
describe "Syntax highlighting" do
specify "percent strings with a modulo-assignment operator look-alike delimiter" do
assert_correct_highlighting <<~'EOF', '%=', 'rubyPercentStringDelimiter'
foo = %= bar =
EOF
end
end

View File

@ -0,0 +1,45 @@
require 'spec_helper'
describe "Syntax highlighting" do
# See issue #356
specify "hashes with symbol keys and values on different lines" do
assert_correct_highlighting <<~'EOF', 'x', 'rubySymbol'
h = {
x:
really_long_method_name,
y: 5,
}
EOF
end
# See issue #44
specify "1.9 style hash keys with keyword names" do
assert_correct_highlighting <<~EOF, %w[class if def include case end], 'rubySymbol'
{ class: "hello", if: "world", def: "i am", include: "foo", case: "bar", end: "baz" }
EOF
assert_correct_highlighting <<~'EOF', 'end', 'rubyDefine'
def hello
{ if: "world" }
end
EOF
end
# See issue #144
specify "1.9 style hash keys with keyword names in parameter lists" do
assert_correct_highlighting <<~'EOF', 'prepend', 'rubySymbol'
{prepend: true}
EOF
assert_correct_highlighting <<~'EOF', 'for', 'rubySymbol'
Subscription.generate(for: topic,
to: subscriber)
EOF
end
# See issue #12
specify "1.9 style hash keys with keyword names in argument lists" do
assert_correct_highlighting <<~EOF, %w[:\zsgender in\ze: if\ze: :\zsgender_required?], 'rubySymbol'
validates_inclusion_of :gender, in: %w(male female), if: :gender_required?
EOF
end
end

View File

@ -0,0 +1,21 @@
let s:debug = 0
function! s:CursorHasGroup(group) abort
return synIDattr(synID(line('.'), col('.'), 0), 'name') =~ a:group
endfunction
function! TestSyntax(pattern, group) abort
let pattern = '\C' . a:pattern
call cursor(1, 1)
redraw
let start_match = search(pattern, 'c') && s:CursorHasGroup(a:group)
if s:debug
redraw | sleep 500m
endif
let end_match = search(pattern, 'e') && s:CursorHasGroup(a:group)
if s:debug
redraw | sleep 500m
endif
return start_match && end_match
endfunction