Merge pull request #147422 from amanasifkhalid/snippet-transform-case

This commit is contained in:
Johannes Rieken 2022-04-14 09:26:50 +02:00 committed by GitHub
commit a8f5fc20e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -395,8 +395,7 @@ export class FormatString extends Marker {
return value;
}
return match.map(word => {
return word.charAt(0).toUpperCase()
+ word.substr(1).toLowerCase();
return word.charAt(0).toUpperCase() + word.substr(1);
})
.join('');
}
@ -408,11 +407,9 @@ export class FormatString extends Marker {
}
return match.map((word, index) => {
if (index === 0) {
return word.toLowerCase();
} else {
return word.charAt(0).toUpperCase()
+ word.substr(1).toLowerCase();
return word.charAt(0).toLowerCase() + word.substr(1);
}
return word.charAt(0).toUpperCase() + word.substr(1);
})
.join('');
}

View file

@ -656,8 +656,14 @@ suite('SnippetParser', () => {
assert.strictEqual(new FormatString(1, 'capitalize').resolve('bar no repeat'), 'Bar no repeat');
assert.strictEqual(new FormatString(1, 'pascalcase').resolve('bar-foo'), 'BarFoo');
assert.strictEqual(new FormatString(1, 'pascalcase').resolve('bar-42-foo'), 'Bar42Foo');
assert.strictEqual(new FormatString(1, 'pascalcase').resolve('snake_AndPascalCase'), 'SnakeAndPascalCase');
assert.strictEqual(new FormatString(1, 'pascalcase').resolve('kebab-AndPascalCase'), 'KebabAndPascalCase');
assert.strictEqual(new FormatString(1, 'pascalcase').resolve('_justPascalCase'), 'JustPascalCase');
assert.strictEqual(new FormatString(1, 'camelcase').resolve('bar-foo'), 'barFoo');
assert.strictEqual(new FormatString(1, 'camelcase').resolve('bar-42-foo'), 'bar42Foo');
assert.strictEqual(new FormatString(1, 'camelcase').resolve('snake_AndCamelCase'), 'snakeAndCamelCase');
assert.strictEqual(new FormatString(1, 'camelcase').resolve('kebab-AndCamelCase'), 'kebabAndCamelCase');
assert.strictEqual(new FormatString(1, 'camelcase').resolve('_JustCamelCase'), 'justCamelCase');
assert.strictEqual(new FormatString(1, 'notKnown').resolve('input'), 'input');
// if