1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

添加 路径转换类型 SupportPathFormat 及测试相关代码

This commit is contained in:
2024-12-14 21:26:36 +08:00
parent f99146703b
commit 6248f3d0cd
13 changed files with 1316 additions and 1234 deletions

View File

@@ -0,0 +1,6 @@
import { SupportPathFormat } from "./types/SupportPathFormatType";
export function pathConversion(SupportPathFormat: SupportPathFormat, input: string) {
// TODO
}

View File

@@ -0,0 +1,23 @@
/**
* 路径转换类型
*
* @since 2024-12-14
*/
export enum SupportPathFormat {
/**
* Windows 格式
*
* @alias: windows / Windows
* @since 2024-12-07
*/
Windows,
/**
* Unix 格式
*
* @alias: unix / Unix
* @since 2024-12-07
*/
Unix,
};

View File

@@ -1,53 +1,53 @@
import { EOL } from '../../types/EOLType';
import { SupportCase } from './types/SupportCaseType';
import { SupportVariableCase } from './types/SupportVariableCaseType';
import { TransformTextResult } from '../../types/TransformTextResultType';
import { transformMutliLineText, transformText } from '../../utils/transform';
/**
* 统一文本转换函数
*
* @param {SupportCase} targetCase 目标文本情况
* @param {SupportVariableCase} targetCase 目标文本情况
* @param {string} str 用户选择的文本 user selection
* @param {EOL} eol 行结束符
* @param {Array<TransformTextResult>?} cutText 行结束符
* @returns 转换后的文本
* @since 2024-04-04
*/
export function caseConversion(targetCase: SupportCase, str: string, eol: EOL, cutText: Array<TransformTextResult> | undefined = undefined): string {
export function caseConversion(targetCase: SupportVariableCase, str: string, eol: EOL, cutText: Array<TransformTextResult> | undefined = undefined): string {
let spaceCharacter: '-' | '_' | ' ' | '.' | undefined = undefined;
switch (targetCase) {
default:
case SupportCase.CAMEL_CASE: // 小驼峰(驼峰)命名
case SupportCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
case SupportVariableCase.CAMEL_CASE: // 小驼峰(驼峰)命名
case SupportVariableCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
spaceCharacter = undefined;
break;
case SupportCase.SNAKE_CASE: // 下划线(蛇形)命名
case SupportCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
case SupportCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
case SupportCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
case SupportVariableCase.SNAKE_CASE: // 下划线(蛇形)命名
case SupportVariableCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
case SupportVariableCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
case SupportVariableCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
spaceCharacter = '_';
break;
case SupportCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
case SupportCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
case SupportCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
case SupportCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
case SupportVariableCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
case SupportVariableCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
case SupportVariableCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
case SupportVariableCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
spaceCharacter = '-';
break;
case SupportCase.SPACE_CASE: // 空格分隔命名
case SupportCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
case SupportCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
case SupportCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
case SupportVariableCase.SPACE_CASE: // 空格分隔命名
case SupportVariableCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
case SupportVariableCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
case SupportVariableCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
spaceCharacter = ' ';
break;
case SupportCase.DOT_CASE: // 点分隔命名
case SupportCase.DOT_CAMEL_CASE: // 点分隔 + 小驼峰(驼峰)命名
case SupportCase.DOT_PASCAL_CASE: // 点分隔 + 大驼峰(帕斯卡)命名
case SupportCase.DOT_UPPER_CASE: // 点分隔 + 全大写命名
case SupportVariableCase.DOT_CASE: // 点分隔命名
case SupportVariableCase.DOT_CAMEL_CASE: // 点分隔 + 小驼峰(驼峰)命名
case SupportVariableCase.DOT_PASCAL_CASE: // 点分隔 + 大驼峰(帕斯卡)命名
case SupportVariableCase.DOT_UPPER_CASE: // 点分隔 + 全大写命名
spaceCharacter = '.';
break;
case SupportCase.LOWER_CASE: // 全小写
case SupportVariableCase.LOWER_CASE: // 全小写
return str.toLowerCase();
case SupportCase.UPPER_CASE: // 全大写
case SupportVariableCase.UPPER_CASE: // 全大写
return str.toUpperCase();
}
@@ -85,11 +85,11 @@ export function caseConversion(targetCase: SupportCase, str: string, eol: EOL, c
// 根据目标情况转换单词
switch (targetCase) {
case SupportCase.CAMEL_CASE: // 小驼峰(驼峰)命名
case SupportCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
case SupportCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
case SupportCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
case SupportCase.DOT_CAMEL_CASE: // 点分隔 + 小驼峰(驼峰)命名
case SupportVariableCase.CAMEL_CASE: // 小驼峰(驼峰)命名
case SupportVariableCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
case SupportVariableCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
case SupportVariableCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
case SupportVariableCase.DOT_CAMEL_CASE: // 点分隔 + 小驼峰(驼峰)命名
if (isFirstWord) {
transformedWords.push(word);
if (isCurrentWordNormal) {
@@ -99,23 +99,23 @@ export function caseConversion(targetCase: SupportCase, str: string, eol: EOL, c
transformedWords.push(pascalCaseWord);
}
break;
case SupportCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
case SupportCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
case SupportCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
case SupportCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
case SupportCase.DOT_PASCAL_CASE: // 点分隔 + 大驼峰(帕斯卡)命名
case SupportVariableCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
case SupportVariableCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
case SupportVariableCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
case SupportVariableCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
case SupportVariableCase.DOT_PASCAL_CASE: // 点分隔 + 大驼峰(帕斯卡)命名
transformedWords.push(pascalCaseWord);
break;
case SupportCase.SNAKE_CASE: // 下划线(蛇形)命名
case SupportCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
case SupportCase.SPACE_CASE: // 空格分隔命名
case SupportCase.DOT_CASE: // 点分隔命名x
case SupportVariableCase.SNAKE_CASE: // 下划线(蛇形)命名
case SupportVariableCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
case SupportVariableCase.SPACE_CASE: // 空格分隔命名
case SupportVariableCase.DOT_CASE: // 点分隔命名x
transformedWords.push(word);
break;
case SupportCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
case SupportCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
case SupportCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
case SupportCase.DOT_UPPER_CASE: // 点分隔 + 全大写命名
case SupportVariableCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
case SupportVariableCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
case SupportVariableCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
case SupportVariableCase.DOT_UPPER_CASE: // 点分隔 + 全大写命名
transformedWords.push(word.toUpperCase());
break;
default:

View File

@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { EOL } from "../../types/EOLType";
import { cyclicConvertCaseOrder } from "./types/SupportCaseType";
import { cyclicConvertCaseOrder } from "./types/SupportVariableCaseType";
import { caseConversion } from "./conversion";
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils';
import { getUserConfigurations } from '../../utils/user-configuration';

View File

@@ -1,5 +1,5 @@
/**
* When support a new case, there's something we need to do.
* When support a new variable case, there's something we need to do.
*
* Code:
* - Add type definition in below `SupportCase` enum and following array
@@ -15,7 +15,7 @@
* - Modify `description` in [package.json] and [package-comment.jsonc]
* - Add changes in [CHANGELOG.md] and [README.md]
*/
export enum SupportCase {
export enum SupportVariableCase {
/**
* ()
@@ -281,116 +281,116 @@ const keyword = {
/**
*
*/
export const commands: Array<{ command: string; targetCase: SupportCase; settingsKey: string }> = [
export const commands: Array<{ command: string; targetCase: SupportVariableCase; settingsKey: string }> = [
{
command: 'variable-conversion.toCamelCase',
targetCase: SupportCase.CAMEL_CASE,
targetCase: SupportVariableCase.CAMEL_CASE,
settingsKey: 'camel_case'
},
{
command: 'variable-conversion.toPascalCase',
targetCase: SupportCase.PASCAL_CASE,
targetCase: SupportVariableCase.PASCAL_CASE,
settingsKey: 'pascal_case'
},
// +++++++++++++++++++++++++++++++++++++++++++++++
{
command: 'variable-conversion.toSnakeCase',
targetCase: SupportCase.SNAKE_CASE,
targetCase: SupportVariableCase.SNAKE_CASE,
settingsKey: 'snake_case'
},
{
command: 'variable-conversion.toSnakeUpperCase',
targetCase: SupportCase.SNAKE_UPPER_CASE,
targetCase: SupportVariableCase.SNAKE_UPPER_CASE,
settingsKey: 'snake_upper_case'
},
{
command: 'variable-conversion.toSnakePascalCase',
targetCase: SupportCase.SNAKE_PASCAL_CASE,
targetCase: SupportVariableCase.SNAKE_PASCAL_CASE,
settingsKey: 'snake_pascal_case'
},
{
command: 'variable-conversion.toSnakeCamelCase',
targetCase: SupportCase.SNAKE_CAMEL_CASE,
targetCase: SupportVariableCase.SNAKE_CAMEL_CASE,
settingsKey: 'snake_camel_case'
},
// +++++++++++++++++++++++++++++++++++++++++++++++
{
command: 'variable-conversion.toKebabCase',
targetCase: SupportCase.KEBAB_CASE,
targetCase: SupportVariableCase.KEBAB_CASE,
settingsKey: 'kebab_case'
},
{
command: 'variable-conversion.toKebabUpperCase',
targetCase: SupportCase.KEBAB_UPPER_CASE,
targetCase: SupportVariableCase.KEBAB_UPPER_CASE,
settingsKey: 'kebab_upper_case'
},
{
command: 'variable-conversion.toKebabPascalCase',
targetCase: SupportCase.KEBAB_PASCAL_CASE,
targetCase: SupportVariableCase.KEBAB_PASCAL_CASE,
settingsKey: 'kebab_pascal_case'
},
{
command: 'variable-conversion.toKebabCamelCase',
targetCase: SupportCase.KEBAB_CAMEL_CASE,
targetCase: SupportVariableCase.KEBAB_CAMEL_CASE,
settingsKey: 'kebab_camel_case'
},
// +++++++++++++++++++++++++++++++++++++++++++++++
{
command: 'variable-conversion.toSpaceCase',
targetCase: SupportCase.SPACE_CASE,
targetCase: SupportVariableCase.SPACE_CASE,
settingsKey: 'space_case'
},
{
command: 'variable-conversion.toSpaceUpperCase',
targetCase: SupportCase.SPACE_UPPER_CASE,
targetCase: SupportVariableCase.SPACE_UPPER_CASE,
settingsKey: 'space_upper_case'
},
{
command: 'variable-conversion.toSpacePascalCase',
targetCase: SupportCase.SPACE_PASCAL_CASE,
targetCase: SupportVariableCase.SPACE_PASCAL_CASE,
settingsKey: 'space_pascal_case'
},
{
command: 'variable-conversion.toSpaceCamelCase',
targetCase: SupportCase.SPACE_CAMEL_CASE,
targetCase: SupportVariableCase.SPACE_CAMEL_CASE,
settingsKey: 'space_camel_case'
},
// +++++++++++++++++++++++++++++++++++++++++++++++
{
command: 'variable-conversion.toDotCase',
targetCase: SupportCase.DOT_CASE,
targetCase: SupportVariableCase.DOT_CASE,
settingsKey: 'dot_case'
},
{
command: 'variable-conversion.toDotUpperCase',
targetCase: SupportCase.DOT_UPPER_CASE,
targetCase: SupportVariableCase.DOT_UPPER_CASE,
settingsKey: 'dot_upper_case'
},
{
command: 'variable-conversion.toDotPascalCase',
targetCase: SupportCase.DOT_PASCAL_CASE,
targetCase: SupportVariableCase.DOT_PASCAL_CASE,
settingsKey: 'dot_pascal_case'
},
{
command: 'variable-conversion.toDotCamelCase',
targetCase: SupportCase.DOT_CAMEL_CASE,
targetCase: SupportVariableCase.DOT_CAMEL_CASE,
settingsKey: 'dot_camel_case'
},
// +++++++++++++++++++++++++++++++++++++++++++++++
{
command: 'variable-conversion.toLowerCase',
targetCase: SupportCase.LOWER_CASE,
targetCase: SupportVariableCase.LOWER_CASE,
settingsKey: 'lower_case'
},
{
command: 'variable-conversion.toUpperCase',
targetCase: SupportCase.UPPER_CASE,
targetCase: SupportVariableCase.UPPER_CASE,
settingsKey: 'upper_case'
},
];
export interface QuickPickSupportCaseItem {
type: SupportCase,
type: SupportVariableCase,
name: string,
shortName: string,
keyword: string[],
@@ -403,140 +403,140 @@ export interface QuickPickSupportCaseItem {
*/
export const quickPickSupportCases: Array<QuickPickSupportCaseItem> = [
{
type: SupportCase.CAMEL_CASE,
type: SupportVariableCase.CAMEL_CASE,
name: '小驼峰(驼峰)命名',
shortName: '小驼峰',
keyword: keyword.camel,
settingsKey: 'camel_case',
},
{
type: SupportCase.PASCAL_CASE,
type: SupportVariableCase.PASCAL_CASE,
name: '大驼峰(帕斯卡)命名',
shortName: '帕斯卡',
keyword: keyword.pascal,
settingsKey: 'pascal_case',
},
{
type: SupportCase.SNAKE_CASE,
type: SupportVariableCase.SNAKE_CASE,
name: '下划线(蛇形)命名',
shortName: '蛇形',
keyword: [...keyword.snake, ...keyword.lower],
settingsKey: 'snake_case',
},
{
type: SupportCase.SNAKE_CAMEL_CASE,
type: SupportVariableCase.SNAKE_CAMEL_CASE,
name: '下划线(蛇形) + 小驼峰(驼峰)命名',
shortName: '蛇形驼峰',
keyword: [...keyword.snake, ...keyword.camel],
settingsKey: 'snake_camel_case',
},
{
type: SupportCase.SNAKE_PASCAL_CASE,
type: SupportVariableCase.SNAKE_PASCAL_CASE,
name: '下划线(蛇形) + 大驼峰(帕斯卡)命名',
shortName: '蛇形帕斯卡',
keyword: [...keyword.snake, ...keyword.pascal],
settingsKey: 'snake_pascal_case',
},
{
type: SupportCase.SNAKE_UPPER_CASE,
type: SupportVariableCase.SNAKE_UPPER_CASE,
name: '下划线(蛇形) + 全大写命名',
shortName: '蛇形大写',
keyword: [...keyword.snake, ...keyword.upper],
settingsKey: 'snake_upper_case',
},
{
type: SupportCase.KEBAB_CASE,
type: SupportVariableCase.KEBAB_CASE,
name: '中划线(连字符/脊柱式)命名',
shortName: '脊柱',
keyword: [...keyword.kebab, ...keyword.lower],
settingsKey: 'kebab_case',
},
{
type: SupportCase.KEBAB_CAMEL_CASE,
type: SupportVariableCase.KEBAB_CAMEL_CASE,
name: '中划线(连字符/脊柱式) + 小驼峰(驼峰)命名',
shortName: '脊柱驼峰',
keyword: [...keyword.kebab, ...keyword.camel],
settingsKey: 'kebab_camel_case',
},
{
type: SupportCase.KEBAB_PASCAL_CASE,
type: SupportVariableCase.KEBAB_PASCAL_CASE,
name: '中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名',
shortName: '脊柱帕斯卡',
keyword: [...keyword.kebab, ...keyword.pascal],
settingsKey: 'kebab_pascal_case',
},
{
type: SupportCase.KEBAB_UPPER_CASE,
type: SupportVariableCase.KEBAB_UPPER_CASE,
name: '中划线(连字符/脊柱式) + 全大写命名',
shortName: '脊柱大写',
keyword: [...keyword.kebab, ...keyword.upper],
settingsKey: 'kebab_upper_case',
},
{
type: SupportCase.SPACE_CASE,
type: SupportVariableCase.SPACE_CASE,
name: '空格分隔命名',
shortName: '脊柱',
keyword: [...keyword.space, ...keyword.lower],
settingsKey: 'space_case',
},
{
type: SupportCase.SPACE_CAMEL_CASE,
type: SupportVariableCase.SPACE_CAMEL_CASE,
name: '空格分隔 + 小驼峰(驼峰)命名',
shortName: '脊柱驼峰',
keyword: [...keyword.space, ...keyword.camel],
settingsKey: 'space_camel_case',
},
{
type: SupportCase.SPACE_PASCAL_CASE,
type: SupportVariableCase.SPACE_PASCAL_CASE,
name: '空格分隔 + 大驼峰(帕斯卡)命名',
shortName: '脊柱帕斯卡',
keyword: [...keyword.space, ...keyword.pascal],
settingsKey: 'space_pascal_case',
},
{
type: SupportCase.SPACE_UPPER_CASE,
type: SupportVariableCase.SPACE_UPPER_CASE,
name: '空格分隔 + 全大写命名',
shortName: '脊柱大写',
keyword: [...keyword.space, ...keyword.upper],
settingsKey: 'space_upper_case',
},
{
type: SupportCase.DOT_CASE,
type: SupportVariableCase.DOT_CASE,
name: '点分隔命名',
shortName: '脊柱',
keyword: [...keyword.dot, ...keyword.lower],
settingsKey: 'dot_case',
},
{
type: SupportCase.DOT_CAMEL_CASE,
type: SupportVariableCase.DOT_CAMEL_CASE,
name: '点分隔 + 小驼峰(驼峰)命名',
shortName: '脊柱驼峰',
keyword: [...keyword.dot, ...keyword.camel],
settingsKey: 'dot_camel_case',
},
{
type: SupportCase.DOT_PASCAL_CASE,
type: SupportVariableCase.DOT_PASCAL_CASE,
name: '点分隔 + 大驼峰(帕斯卡)命名',
shortName: '脊柱帕斯卡',
keyword: [...keyword.dot, ...keyword.pascal],
settingsKey: 'dot_pascal_case',
},
{
type: SupportCase.DOT_UPPER_CASE,
type: SupportVariableCase.DOT_UPPER_CASE,
name: '点分隔 + 全大写命名',
shortName: '脊柱大写',
keyword: [...keyword.dot, ...keyword.upper],
settingsKey: 'dot_upper_case',
},
{
type: SupportCase.LOWER_CASE,
type: SupportVariableCase.LOWER_CASE,
name: '全小写',
shortName: '小写',
keyword: keyword.lower,
settingsKey: 'lower_case',
},
{
type: SupportCase.UPPER_CASE,
type: SupportVariableCase.UPPER_CASE,
name: '全大写',
shortName: '大写',
keyword: keyword.upper,
@@ -545,7 +545,7 @@ export const quickPickSupportCases: Array<QuickPickSupportCaseItem> = [
];
export interface CyclicConvertCaseOrderItem {
type: SupportCase,
type: SupportVariableCase,
settingsKey: string,
}
@@ -554,28 +554,28 @@ export interface CyclicConvertCaseOrderItem {
* @since 2024-04-08
*/
export const cyclicConvertCaseOrder: Array<CyclicConvertCaseOrderItem> = [
{ type: SupportCase.CAMEL_CASE, settingsKey: 'camel_case' },
{ type: SupportCase.SNAKE_CASE, settingsKey: 'snake_case' },
{ type: SupportCase.PASCAL_CASE, settingsKey: 'pascal_case' },
{ type: SupportCase.KEBAB_CASE, settingsKey: 'kebab_case' },
{ type: SupportCase.SPACE_CASE, settingsKey: 'space_case' },
{ type: SupportCase.DOT_CASE, settingsKey: 'dot_case' },
{ type: SupportVariableCase.CAMEL_CASE, settingsKey: 'camel_case' },
{ type: SupportVariableCase.SNAKE_CASE, settingsKey: 'snake_case' },
{ type: SupportVariableCase.PASCAL_CASE, settingsKey: 'pascal_case' },
{ type: SupportVariableCase.KEBAB_CASE, settingsKey: 'kebab_case' },
{ type: SupportVariableCase.SPACE_CASE, settingsKey: 'space_case' },
{ type: SupportVariableCase.DOT_CASE, settingsKey: 'dot_case' },
{ type: SupportCase.SNAKE_UPPER_CASE, settingsKey: 'snake_upper_case' },
{ type: SupportCase.KEBAB_UPPER_CASE, settingsKey: 'kebab_upper_case' },
{ type: SupportCase.SPACE_UPPER_CASE, settingsKey: 'space_upper_case' },
{ type: SupportCase.DOT_UPPER_CASE, settingsKey: 'dot_upper_case' },
{ type: SupportVariableCase.SNAKE_UPPER_CASE, settingsKey: 'snake_upper_case' },
{ type: SupportVariableCase.KEBAB_UPPER_CASE, settingsKey: 'kebab_upper_case' },
{ type: SupportVariableCase.SPACE_UPPER_CASE, settingsKey: 'space_upper_case' },
{ type: SupportVariableCase.DOT_UPPER_CASE, settingsKey: 'dot_upper_case' },
{ type: SupportCase.SNAKE_PASCAL_CASE, settingsKey: 'snake_pascal_case' },
{ type: SupportCase.KEBAB_PASCAL_CASE, settingsKey: 'kebab_pascal_case' },
{ type: SupportCase.SPACE_PASCAL_CASE, settingsKey: 'space_pascal_case' },
{ type: SupportCase.DOT_PASCAL_CASE, settingsKey: 'dot_pascal_case' },
{ type: SupportVariableCase.SNAKE_PASCAL_CASE, settingsKey: 'snake_pascal_case' },
{ type: SupportVariableCase.KEBAB_PASCAL_CASE, settingsKey: 'kebab_pascal_case' },
{ type: SupportVariableCase.SPACE_PASCAL_CASE, settingsKey: 'space_pascal_case' },
{ type: SupportVariableCase.DOT_PASCAL_CASE, settingsKey: 'dot_pascal_case' },
{ type: SupportCase.SNAKE_CAMEL_CASE, settingsKey: 'snake_camel_case' },
{ type: SupportCase.KEBAB_CAMEL_CASE, settingsKey: 'kebab_camel_case' },
{ type: SupportCase.SPACE_CAMEL_CASE, settingsKey: 'space_camel_case' },
{ type: SupportCase.DOT_CAMEL_CASE, settingsKey: 'dot_camel_case' },
{ type: SupportVariableCase.SNAKE_CAMEL_CASE, settingsKey: 'snake_camel_case' },
{ type: SupportVariableCase.KEBAB_CAMEL_CASE, settingsKey: 'kebab_camel_case' },
{ type: SupportVariableCase.SPACE_CAMEL_CASE, settingsKey: 'space_camel_case' },
{ type: SupportVariableCase.DOT_CAMEL_CASE, settingsKey: 'dot_camel_case' },
{ type: SupportCase.LOWER_CASE, settingsKey: 'lower_case' },
{ type: SupportCase.UPPER_CASE, settingsKey: 'upper_case' },
{ type: SupportVariableCase.LOWER_CASE, settingsKey: 'lower_case' },
{ type: SupportVariableCase.UPPER_CASE, settingsKey: 'upper_case' },
];

View File

@@ -13,7 +13,7 @@
import * as vscode from 'vscode';
import handleEditorReplace from './handler/editor-submenu-handler';
import { handleQuickPick } from './handler/quick-pick-handler';
import { commands } from './core/variable-convert/types/SupportCaseType';
import { commands } from './core/variable-convert/types/SupportVariableCaseType';
import { createStatusBarItem, updateStatusBarItemVisable } from './handler/status-bar-handler';
import * as CyclicConversion from './core/variable-convert/cyclic-conversion';
import { EOL } from './types/EOLType';

View File

@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { EOL } from '../types/EOLType';
import { caseConversion } from '../core/variable-convert/conversion';
import { SupportCase } from '../core/variable-convert/types/SupportCaseType';
import { SupportVariableCase } from '../core/variable-convert/types/SupportVariableCaseType';
import { isStringArrayEqual } from '../utils/utils';
/**
@@ -10,7 +10,7 @@ import { isStringArrayEqual } from '../utils/utils';
* @param convertFunction
* @returns
*/
const handleEditorReplace = (targetCase: SupportCase) => {
const handleEditorReplace = (targetCase: SupportVariableCase) => {
// 获取当前编辑器
let editor = vscode.window.activeTextEditor;
if (!editor) {

View File

@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import QuickPickItemEx from "./types/QuickPickItemExType";
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../core/variable-convert/types/SupportCaseType';
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../core/variable-convert/types/SupportVariableCaseType';
import { TransformTextResult } from '../types/TransformTextResultType';
import { transformMutliSelectionText } from '../utils/transform';
import { EOL } from '../types/EOLType';

View File

@@ -3,11 +3,15 @@ import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import { variableConvertTestGroups } from './test-case/variable-convert-test-case';
import { pathConvertTestGroups } from './test-case/path-convert-test-case';
import { TestCase, TestCaseGroup } from './test-case/types/TestCaseType';
import { VariableTestCase, VariableTestCaseGroup } from './test-case/types/VariableTestCaseType';
import { PathTestCase, PathTestCaseGroup } from './test-case/types/PathTestCaseType';
import { transformMutliLineText, transformText } from '../utils/transform';
import { caseConversion } from '../core/variable-convert/conversion';
import { SupportCase } from '../core/variable-convert/types/SupportCaseType';
import { pathConversion } from '../core/path-convert/conversion';
import { SupportVariableCase } from '../core/variable-convert/types/SupportVariableCaseType';
import { SupportPathFormat } from '../core/path-convert/types/SupportPathFormatType';
import { TransformTextResult } from '../types/TransformTextResultType';
// import * as myExtension from '../../extension';
@@ -28,12 +32,12 @@ suite('Extension Test Suite', () => {
* @since 2024-04-02
*/
suite('Extension Test: run variable convert test case', () => {
vscode.window.showInformationMessage('Start all tests.');
vscode.window.showInformationMessage('Start all tests for variable conversion.');
const groups: Array<TestCaseGroup> = pathConvertTestGroups;
const groups: Array<VariableTestCaseGroup> = variableConvertTestGroups;
for (const testGroup of groups) {
const testTitle = testGroup.testTitle;
const testCases: Array<TestCase> = testGroup.cases;
const testCases: Array<VariableTestCase> = testGroup.cases;
for (const testCase of testCases) {
// // 临时
// if (testCase.title !== '') {
@@ -54,34 +58,34 @@ suite('Extension Test: run variable convert test case', () => {
}
// 验证转换
for (let eol of eolList) {
assert.strictEqual(testCase.output.camelCase, caseConversion(SupportCase.CAMEL_CASE, input, eol), 'camel case test failed.');
assert.strictEqual(testCase.output.pascalCase, caseConversion(SupportCase.PASCAL_CASE, input, eol), 'pascal case test failed.');
assert.strictEqual(testCase.output.camelCase, caseConversion(SupportVariableCase.CAMEL_CASE, input, eol), 'camel case test failed.');
assert.strictEqual(testCase.output.pascalCase, caseConversion(SupportVariableCase.PASCAL_CASE, input, eol), 'pascal case test failed.');
assert.strictEqual(testCase.output.snakeCase, caseConversion(SupportCase.SNAKE_CASE, input, eol), 'snake case test failed.');
assert.strictEqual(testCase.output.snakeCamelCase, caseConversion(SupportCase.SNAKE_CAMEL_CASE, input, eol), 'snake camel case test failed.');
assert.strictEqual(testCase.output.snakePascalCase, caseConversion(SupportCase.SNAKE_PASCAL_CASE, input, eol), 'snake pascal case test failed.');
assert.strictEqual(testCase.output.snakeUpperCase, caseConversion(SupportCase.SNAKE_UPPER_CASE, input, eol), 'snake upper case test failed.');
assert.strictEqual(testCase.output.snakeCase, caseConversion(SupportVariableCase.SNAKE_CASE, input, eol), 'snake case test failed.');
assert.strictEqual(testCase.output.snakeCamelCase, caseConversion(SupportVariableCase.SNAKE_CAMEL_CASE, input, eol), 'snake camel case test failed.');
assert.strictEqual(testCase.output.snakePascalCase, caseConversion(SupportVariableCase.SNAKE_PASCAL_CASE, input, eol), 'snake pascal case test failed.');
assert.strictEqual(testCase.output.snakeUpperCase, caseConversion(SupportVariableCase.SNAKE_UPPER_CASE, input, eol), 'snake upper case test failed.');
assert.strictEqual(testCase.output.kebabCase, caseConversion(SupportCase.KEBAB_CASE, input, eol), 'kebab case test failed.');
assert.strictEqual(testCase.output.kebabCamelCase, caseConversion(SupportCase.KEBAB_CAMEL_CASE, input, eol), 'kebab camel case test failed.');
assert.strictEqual(testCase.output.kebabPascalCase, caseConversion(SupportCase.KEBAB_PASCAL_CASE, input, eol), 'kebab pascal case test failed.');
assert.strictEqual(testCase.output.kebabUpperCase, caseConversion(SupportCase.KEBAB_UPPER_CASE, input, eol), 'kebab upper case test failed.');
assert.strictEqual(testCase.output.kebabCase, caseConversion(SupportVariableCase.KEBAB_CASE, input, eol), 'kebab case test failed.');
assert.strictEqual(testCase.output.kebabCamelCase, caseConversion(SupportVariableCase.KEBAB_CAMEL_CASE, input, eol), 'kebab camel case test failed.');
assert.strictEqual(testCase.output.kebabPascalCase, caseConversion(SupportVariableCase.KEBAB_PASCAL_CASE, input, eol), 'kebab pascal case test failed.');
assert.strictEqual(testCase.output.kebabUpperCase, caseConversion(SupportVariableCase.KEBAB_UPPER_CASE, input, eol), 'kebab upper case test failed.');
assert.strictEqual(testCase.output.spaceCase, caseConversion(SupportCase.SPACE_CASE, input, eol), 'space case test failed.');
assert.strictEqual(testCase.output.spaceCamelCase, caseConversion(SupportCase.SPACE_CAMEL_CASE, input, eol), 'space camel case test failed.');
assert.strictEqual(testCase.output.spacePascalCase, caseConversion(SupportCase.SPACE_PASCAL_CASE, input, eol), 'space pascal case test failed.');
assert.strictEqual(testCase.output.spaceUpperCase, caseConversion(SupportCase.SPACE_UPPER_CASE, input, eol), 'space upper case test failed.');
assert.strictEqual(testCase.output.spaceCase, caseConversion(SupportVariableCase.SPACE_CASE, input, eol), 'space case test failed.');
assert.strictEqual(testCase.output.spaceCamelCase, caseConversion(SupportVariableCase.SPACE_CAMEL_CASE, input, eol), 'space camel case test failed.');
assert.strictEqual(testCase.output.spacePascalCase, caseConversion(SupportVariableCase.SPACE_PASCAL_CASE, input, eol), 'space pascal case test failed.');
assert.strictEqual(testCase.output.spaceUpperCase, caseConversion(SupportVariableCase.SPACE_UPPER_CASE, input, eol), 'space upper case test failed.');
assert.strictEqual(testCase.output.dotCase, caseConversion(SupportCase.DOT_CASE, input, eol), 'dot case test failed.');
assert.strictEqual(testCase.output.dotCamelCase, caseConversion(SupportCase.DOT_CAMEL_CASE, input, eol), 'dot camel case test failed.');
assert.strictEqual(testCase.output.dotPascalCase, caseConversion(SupportCase.DOT_PASCAL_CASE, input, eol), 'dot pascal case test failed.');
assert.strictEqual(testCase.output.dotUpperCase, caseConversion(SupportCase.DOT_UPPER_CASE, input, eol), 'dot upper case test failed.');
assert.strictEqual(testCase.output.dotCase, caseConversion(SupportVariableCase.DOT_CASE, input, eol), 'dot case test failed.');
assert.strictEqual(testCase.output.dotCamelCase, caseConversion(SupportVariableCase.DOT_CAMEL_CASE, input, eol), 'dot camel case test failed.');
assert.strictEqual(testCase.output.dotPascalCase, caseConversion(SupportVariableCase.DOT_PASCAL_CASE, input, eol), 'dot pascal case test failed.');
assert.strictEqual(testCase.output.dotUpperCase, caseConversion(SupportVariableCase.DOT_UPPER_CASE, input, eol), 'dot upper case test failed.');
if (testCase.output.lowerCase !== undefined) {
assert.strictEqual(testCase.output.lowerCase, caseConversion(SupportCase.LOWER_CASE, input, eol), 'lower case test failed.');
assert.strictEqual(testCase.output.lowerCase, caseConversion(SupportVariableCase.LOWER_CASE, input, eol), 'lower case test failed.');
}
if (testCase.output.upperCase !== undefined) {
assert.strictEqual(testCase.output.upperCase, caseConversion(SupportCase.UPPER_CASE, input, eol), 'upper case test failed.');
assert.strictEqual(testCase.output.upperCase, caseConversion(SupportVariableCase.UPPER_CASE, input, eol), 'upper case test failed.');
}
}
}
@@ -89,3 +93,33 @@ suite('Extension Test: run variable convert test case', () => {
}
}
});
/**
* 路径转换 测试函数
*
* @since 2024-12-07
*/
suite('Extension Test: run path convert test case', () => {
vscode.window.showInformationMessage('Start all tests for path conversion.');
const groups: Array<PathTestCaseGroup> = pathConvertTestGroups;
for (const testGroup of groups) {
const testTitle = testGroup.testTitle;
const testCases: Array<PathTestCase> = testGroup.cases;
for (const testCase of testCases) {
// // 临时
// if (testCase.title !== '') {
// continue;
// }
test(testTitle + ' - ' + testCase.title, () => {
const inputList = Array.isArray(testCase.input) ? testCase.input : [testCase.input];
for (const input of inputList) {
// console.log('input', '->' + input + '<-');
// 验证转换
assert.strictEqual(testCase.output.Windows, pathConversion(SupportPathFormat.Windows, input), 'Windows path format test failed.');
assert.strictEqual(testCase.output.Unix, pathConversion(SupportPathFormat.Unix, input), 'Unix path format test failed.');
}
});
}
}
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
export type PathTestCaseGroup = {
group: string
testTitle: string
cases: Array<PathTestCase>
};
export type PathTestCase = {
title: string
input: string | Array<string>
output: {
Windows: string
Unix: string
}
};

View File

@@ -1,12 +1,12 @@
import { EOL } from "../../../types/EOLType";
export type TestCaseGroup = {
export type VariableTestCaseGroup = {
group: string
testTitle: string
cases: Array<TestCase>
cases: Array<VariableTestCase>
};
export type TestCase = {
export type VariableTestCase = {
title: string
input: string | Array<string>
eol: EOL | Array<EOL>

File diff suppressed because it is too large Load Diff