diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 5b568a0..4ca0ab4 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -5,36 +5,6 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; // import * as myExtension from '../../extension'; -enum TextFormat { - /** 独立单词 */ - SINGLE_WORD, - /** 小驼峰 */ - CAMEL_CASE, - /** 大驼峰 */ - PASCAL_CASE, - /** 大写 */ - UPPER_CASE, - /** 小写 */ - LOWER_CASE, -} - -interface TestCase { - input: string - inputType: TextFormat | Array - output: { - camelCase: string - } -} -const testCase: Array = [ - { - input: '', - inputType: [], - output: { - camelCase: '', - } - }, -]; - suite('Extension Test Suite', () => { vscode.window.showInformationMessage('Start all tests.'); diff --git a/src/test/test-case.ts b/src/test/test-case.ts new file mode 100644 index 0000000..8e89f33 --- /dev/null +++ b/src/test/test-case.ts @@ -0,0 +1,128 @@ + + +enum SkipReason { + /** 空字符串 */ + EMPTY_STRING, + /** 字符串过长 */ + STRING_TOO_LONG, + /** 不包含英文字母 */ + NOT_CONTAIN_LETTERS, +} + +type TestSkipCase = { + /** 当 input 不是规范的输入时,isSkip 为 true */ + isSkip: true + skipReason: SkipReason +}; +type TestReplaceCase = { + isSkip: false + splitResult: Array + output: { + camelCase: string + pascalCase: string + } +}; +type TestCase = (TestSkipCase | TestReplaceCase) & { + input: string | Array +}; + +/* +Have a nice day! +foo--bar +foo -bar +pineApple +*/ +const testCase: Array = [ + { + input: + '' + , + isSkip: true, + skipReason: SkipReason.EMPTY_STRING + }, + { + 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.` + , + isSkip: true, + skipReason: SkipReason.STRING_TOO_LONG + }, + { + input: + `今天是星期日` + , + isSkip: true, + skipReason: SkipReason.NOT_CONTAIN_LETTERS + }, + { + input: [ + 'test case', + 'test_case', + 'test-case', + 'testCase', + 'TestCase', + 'TEST_CASE', + ], + isSkip: false, + splitResult: [ + '' + ], + output: { + camelCase: 'testCase', + pascalCase: 'TestCase', + } + }, + { + input: [ + ' A nice day! ', + ' a_nice_day! ', + ' ANiceDay! ', + ' A_NICE_DAY! ', + ' A_Nice_DaY ', + ' A-NiCe_Day ', + ' A----NiCe_Day_-_-- ', + ], + isSkip: false, + splitResult: [ + '' + ], + output: { + camelCase: ' aNiceDay! ', + pascalCase: ' ANiceDay! ', + } + }, + { + input: [ + ' A niCe-Day-', + ' A niceDay', + ], + isSkip: false, + splitResult: [ + '' + ], + output: { + camelCase: ' a niceDay', + pascalCase: ' A NiceDay', + } + }, + { + input: [ + 'Have a nice day!', + 'have a nice day!', + 'Have-a-nice-day!', + 'have-a-nice-day!', + 'HAVE-A-NICE-DAY!', + 'Have_a_nice_day!', + 'have_a_nice_day!', + 'HAVE_A_NICE_DAY!', + 'HaveANiceDay!', + 'haveANiceDay!', + ], + isSkip: false, + splitResult: ['have', 'a', 'nice', 'day', '!'], + output: { + camelCase: ' a niceDay', + pascalCase: ' A NiceDay', + } + }, +]; diff --git a/test-code.md b/test-code.md index a61397c..978d3fd 100644 --- a/test-code.md +++ b/test-code.md @@ -13,4 +13,6 @@ const HELLO_WORLD = '' const helloworld = '' // 大写 const HELLOWORLD = '' +// 加空格 +const a = 'hello world' ``` \ No newline at end of file