Skip to content
代码片段 群组 项目
提交 c269a9c7 编辑于 作者: Rajendra Kadam's avatar Rajendra Kadam 提交者: Allen Cook
浏览文件

Add js regex support for empty methods

Add specs to cover function variations in JavaScript
上级 9b5e4aa6
No related branches found
No related tags found
无相关合并请求
...@@ -129,6 +129,10 @@ class ProgrammingLanguage ...@@ -129,6 +129,10 @@ class ProgrammingLanguage
'PHP' => { 'PHP' => {
'empty_function' => %r{function\s+(\w*)\s*\(.*?\)\s*(?::\s*(\w+))?\s*\{|\bfunction\s*\([^)]*\)\s*\{}, 'empty_function' => %r{function\s+(\w*)\s*\(.*?\)\s*(?::\s*(\w+))?\s*\{|\bfunction\s*\([^)]*\)\s*\{},
'function' => %r{\}\s*|function\s+(\w*)\s*\(.*?\)\s*(?::\s*(\w+))?\s*\{|\bfunction\s*\([^)]*\)\s*\{} 'function' => %r{\}\s*|function\s+(\w*)\s*\(.*?\)\s*(?::\s*(\w+))?\s*\{|\bfunction\s*\([^)]*\)\s*\{}
},
'C#' => {
'empty_function' => %r{\b\s*\w+\s+\w+\s*\([^)]*\)\s*\{|\s*\{},
'function' => %r{\}\s*|\b\s*\w+\s+\w+\s*\([^)]*\)\s*(\{?)|\s*\{}
} }
}.freeze }.freeze
......
...@@ -198,6 +198,7 @@ ...@@ -198,6 +198,7 @@
'TypeScript' | 'ts language' 'TypeScript' | 'ts language'
'Java' | 'java language' 'Java' | 'java language'
'PHP' | 'php language' 'PHP' | 'php language'
'C#' | 'c# language'
end end
with_them do with_them do
......
# frozen_string_literal: true
RSpec.shared_examples 'c# language' do
using RSpec::Parameterized::TableSyntax
let(:language_name) { 'C#' }
subject { described_class.new(language_name).cursor_inside_empty_function?(content, suffix) }
context 'when various variations of empty functions are used' do
where(example: [
<<~EXAMPLE,
static int AddNumbers(int num1, int num2) {
<CURSOR>
}
static int SubtractNumbers(int num1, int num2) {
return num1 - num2;
}
EXAMPLE
<<~EXAMPLE,
static int SumValues(params int[] numbers)
{
<CURSOR>
static int SubValues(params int[] numbers)
{
return numbers.Sub();
}
EXAMPLE
<<~EXAMPLE
class MathUtils
{
public static int Multiply(int num1, int num2)
{
<CURSOR>
}
}
EXAMPLE
])
with_them do
let(:content) { example.split("<CURSOR>").first }
let(:suffix) { example.split("<CURSOR>").last }
it { is_expected.to be_truthy }
end
end
context 'when cursor is outside an empty method' do
let(:example) do
<<~CONTENT
static int AddNumbers(int num1, int num2)
{
<CURSOR>
return num1 + num2;
}
static string GreetUser(string name, string timeOfDay)
{
return $"Good {timeOfDay}, {name}!";
}
CONTENT
end
let(:content) { example.split("<CURSOR>").first }
let(:suffix) { example.split("<CURSOR>").last }
it { is_expected.to be_falsey }
end
context 'when language is different that the given' do
let(:example) do
<<~CONTENT
def index4(arg1, arg2):
return 1
def func1():
<CURSOR>
def index2():
return 0
def index3(arg1):
return 1
CONTENT
end
let(:content) { example.split("<CURSOR>").first }
let(:suffix) { example.split("<CURSOR>").last }
it { is_expected.to be_falsey }
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册