实现 转小驼峰 Camel Case;转大驼峰 Pascal Case;transformText 函数通过测试用例
This commit is contained in:
@@ -35,7 +35,8 @@ suite('Extension Test: run test case', () => {
|
||||
const inputList = Array.isArray(testCase.input) ? testCase.input : [testCase.input];
|
||||
for (const input of inputList) {
|
||||
// 验证 transformText
|
||||
assert.strictEqual(testCase.transformText, transformText(input));
|
||||
const transformTextResult = transformText(input);
|
||||
assert.strictEqual(testCase.transformText, transformTextResult.result);
|
||||
// 验证转换
|
||||
assert.strictEqual(testCase.output.camelCase, toCamelCase(input));
|
||||
assert.strictEqual(testCase.output.pascalCase, toPascalCase(input));
|
||||
|
@@ -24,13 +24,43 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
pascalCase: ' ',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'empty input (contains space and enter 1)',
|
||||
input: ' \n ',
|
||||
transformText: ' \n ',
|
||||
output: {
|
||||
camelCase: ' \n ',
|
||||
pascalCase: ' \n ',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'empty input (contains space and enter 2)',
|
||||
input: ' a\nb ',
|
||||
transformText: ' a|\n|b ',
|
||||
output: {
|
||||
camelCase: ' a\nb ',
|
||||
pascalCase: ' a\nb ',
|
||||
},
|
||||
},
|
||||
// 输入长文本
|
||||
{
|
||||
title: 'long text input',
|
||||
input:
|
||||
`China's factory activity expanded in March after five consecutive months of contraction, an official survey revealed on Sunday, adding to a run of indicators that suggest the stabilization of the world's second-largest economy.`
|
||||
,
|
||||
transformText: '',
|
||||
transformText:
|
||||
"china|'|s|factory|activity|expanded|in|march|after|five|consecutive|months|of|contraction|,|an|official|survey|revealed|on|sunday|,|adding|to|a|run|of|indicators|that|suggest|the|stabilization|of|the|world|'|s|second|largest|economy|."
|
||||
,
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
},
|
||||
},
|
||||
// 输入包含数字
|
||||
{
|
||||
title: 'text and number input',
|
||||
input: 'entity2Map',
|
||||
transformText: 'entity|2|map',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
@@ -41,10 +71,9 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
title: 'enter input',
|
||||
input:
|
||||
`How do you\bdo?
|
||||
How do you\tdo!
|
||||
`
|
||||
How do you\tdo!`
|
||||
,
|
||||
transformText: '',
|
||||
transformText: 'how|do|you|\b|do|?\n|how|do|you|\t|do|!',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
@@ -56,7 +85,7 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
input:
|
||||
'今天是星期日'
|
||||
,
|
||||
transformText: '',
|
||||
transformText: '今天是星期日',
|
||||
output: {
|
||||
camelCase: '今天是星期日',
|
||||
pascalCase: '今天是星期日',
|
||||
@@ -67,7 +96,7 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
input:
|
||||
'🥰 a-cup/_of Coffee🍻,-_please!. '
|
||||
,
|
||||
transformText: '',
|
||||
transformText: '🥰|a|cup|/|of|coffee|🍻,|please|!. ',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
@@ -78,7 +107,7 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
input:
|
||||
' NHDAs--+90-usz&* '
|
||||
,
|
||||
transformText: '',
|
||||
transformText: ' n|h|d|as|+90|usz|&* ',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
@@ -89,7 +118,7 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
input:
|
||||
'--担心你鸿dAf_=coffee—_— '
|
||||
,
|
||||
transformText: '',
|
||||
transformText: '担心你鸿|d|af|=|coffee|—|— ',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
@@ -100,7 +129,7 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
input:
|
||||
'fsdi_sdacsaf+desd'
|
||||
,
|
||||
transformText: '',
|
||||
transformText: 'fsdi|sdacsaf|+|desd',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
@@ -181,9 +210,10 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
' a_nice_day! ',
|
||||
' ANiceDay! ',
|
||||
' A_NICE_DAY! ',
|
||||
' A_Nice_DaY! ',
|
||||
' A-NiCe_Day! ',
|
||||
' A----NiCe_Day_-_!-- ',
|
||||
// ' A_Nice_DaY! ',
|
||||
// ' A-NiCe_Day! ',
|
||||
// ' A----NiCe_Day_-_!-- ',
|
||||
' A----NICE_Day_-_!-- ',
|
||||
],
|
||||
transformText: ' a|nice|day|! ',
|
||||
output: {
|
||||
@@ -194,7 +224,7 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
{
|
||||
title: 'Normal input (a-nice-day)',
|
||||
input: [
|
||||
' A niCe-Day-',
|
||||
' A NICE-Day-',
|
||||
' A niceDay',
|
||||
],
|
||||
transformText: ' a|nice|day',
|
||||
@@ -203,6 +233,18 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
pascalCase: ' A NiceDay',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Normal input (foo-bar)',
|
||||
input: [
|
||||
' app2-Trrre ',
|
||||
' app2Trrre ',
|
||||
],
|
||||
transformText: ' app|2|trrre ',
|
||||
output: {
|
||||
camelCase: '',
|
||||
pascalCase: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Normal input (Julius-Caesar, William-Shakespeare, ...)',
|
||||
input:
|
||||
|
Reference in New Issue
Block a user