mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-03 19:29:03 -05:00
Merge pull request #5197 from Microsoft/supportIndentStyle
Support different indentation styles
This commit is contained in:
committed by
Paul van Brenk
parent
12b436bb2c
commit
573652160c
@@ -68,6 +68,13 @@ enum EmitReturnStatus {
|
||||
EmitErrorsEncountered = 4 // Emitter errors occurred during emitting process
|
||||
}
|
||||
|
||||
// This is a duplicate of the indentstyle in services.ts to expose it to testcases in fourslash
|
||||
enum IndentStyle {
|
||||
None,
|
||||
Block,
|
||||
Smart,
|
||||
}
|
||||
|
||||
module FourSlashInterface {
|
||||
|
||||
export interface Marker {
|
||||
@@ -278,8 +285,8 @@ module FourSlashInterface {
|
||||
FourSlash.currentTestState.verifyIndentationAtCurrentPosition(numberOfSpaces);
|
||||
}
|
||||
|
||||
public indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number) {
|
||||
FourSlash.currentTestState.verifyIndentationAtPosition(fileName, position, numberOfSpaces);
|
||||
public indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number, indentStyle = IndentStyle.Smart) {
|
||||
FourSlash.currentTestState.verifyIndentationAtPosition(fileName, position, numberOfSpaces, indentStyle);
|
||||
}
|
||||
|
||||
public textAtCaretIs(text: string) {
|
||||
|
||||
183
tests/cases/fourslash/indentationBlock.ts
Normal file
183
tests/cases/fourslash/indentationBlock.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////
|
||||
////module classes {
|
||||
////{| "indent": 0 |}
|
||||
//// class Bar {
|
||||
////{| "indent": 4 |}
|
||||
////
|
||||
//// constructor() {
|
||||
////{| "indent": 8 |}
|
||||
//// }
|
||||
////
|
||||
//// private foo: string = "";
|
||||
////{| "indent": 8 |}
|
||||
////
|
||||
//// private f() {
|
||||
//// var a: any[] = [[1, 2], [3, 4], 5];
|
||||
////{| "indent": 12 |}
|
||||
//// return ((1 + 1));
|
||||
//// }
|
||||
////
|
||||
////{| "indent": 8 |}
|
||||
//// private f2() {
|
||||
//// if (true) { } { };
|
||||
//// }
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////module interfaces {
|
||||
////{| "indent": 0 |}
|
||||
//// interface Foo {
|
||||
////{| "indent": 4 |}
|
||||
////
|
||||
//// x: number;
|
||||
////{| "indent": 8 |}
|
||||
////
|
||||
//// foo(): number;
|
||||
////{| "indent": 8 |}
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////module nestedModules {
|
||||
//// module Foo2 {
|
||||
////{| "indent": 4 |}
|
||||
//// function f() {
|
||||
//// }
|
||||
////{| "indent": 8 |}
|
||||
//// var x: number;
|
||||
////{| "indent": 8 |}
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////module Enums {
|
||||
//// enum Foo3 {
|
||||
////{| "indent": 4 |}
|
||||
//// val1,
|
||||
////{| "indent": 8 |}
|
||||
//// val2,
|
||||
////{| "indent": 8 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function controlStatements() {
|
||||
//// for (var i = 0; i < 10; i++) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////
|
||||
//// for (var e in foo.bar) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////
|
||||
//// with (foo.bar) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////
|
||||
//// while (false) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////
|
||||
//// do {
|
||||
////{| "indent": 4 |}
|
||||
//// } while (false);
|
||||
////
|
||||
//// switch (foo.bar) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////
|
||||
//// switch (foo.bar) {
|
||||
////{| "indent": 4 |}
|
||||
//// case 1:
|
||||
////{| "indent": 8 |}
|
||||
//// break;
|
||||
//// default:
|
||||
////{| "indent": 8 |}
|
||||
//// break;
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function tryCatch() {
|
||||
////{| "indent": 0 |}
|
||||
//// try {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
//// catch (err) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function tryFinally() {
|
||||
////{| "indent": 0 |}
|
||||
//// try {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
//// finally {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function tryCatchFinally() {
|
||||
////{| "indent": 0 |}
|
||||
//// try {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
//// catch (err) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
//// finally {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////{| "indent": 4 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////class indentBeforeCurly
|
||||
////{| "indent": 0 |}
|
||||
////{| "indent": 0 |}{
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function argumentsListIndentation(bar,
|
||||
//// blah,
|
||||
//// {| "indent": 13 |}
|
||||
////);
|
||||
////
|
||||
////
|
||||
////function blockIndentAfterIndentedParameter1(bar,
|
||||
//// blah) {
|
||||
////{| "indent": 13 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function blockIndentAfterIndentedParameter2(bar,
|
||||
//// blah) {
|
||||
//// if (foo) {
|
||||
////{| "indent": 4 |}
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////// Note: Do not add more tests at the end of this file, as
|
||||
////// the purpose of this test is to verity smart indent
|
||||
////// works for unterminated function arguments at the end of a file.
|
||||
////function unterminatedListIndentation(a,
|
||||
////{| "indent": 0 |}
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent, IndentStyle.Block);
|
||||
});
|
||||
183
tests/cases/fourslash/indentationNone.ts
Normal file
183
tests/cases/fourslash/indentationNone.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////
|
||||
////module classes {
|
||||
////{| "indent": 0 |}
|
||||
//// class Bar {
|
||||
////{| "indent": 0 |}
|
||||
////
|
||||
//// constructor() {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////
|
||||
//// private foo: string = "";
|
||||
////{| "indent": 0 |}
|
||||
////
|
||||
//// private f() {
|
||||
//// var a: any[] = [[1, 2], [3, 4], 5];
|
||||
////{| "indent": 0 |}
|
||||
//// return ((1 + 1));
|
||||
//// }
|
||||
////
|
||||
////{| "indent": 0 |}
|
||||
//// private f2() {
|
||||
//// if (true) { } { };
|
||||
//// }
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////module interfaces {
|
||||
////{| "indent": 0 |}
|
||||
//// interface Foo {
|
||||
////{| "indent": 0 |}
|
||||
////
|
||||
//// x: number;
|
||||
////{| "indent": 0 |}
|
||||
////
|
||||
//// foo(): number;
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////module nestedModules {
|
||||
//// module Foo2 {
|
||||
////{| "indent": 0 |}
|
||||
//// function f() {
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
//// var x: number;
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////module Enums {
|
||||
//// enum Foo3 {
|
||||
////{| "indent": 0 |}
|
||||
//// val1,
|
||||
////{| "indent": 0 |}
|
||||
//// val2,
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function controlStatements() {
|
||||
//// for (var i = 0; i < 10; i++) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////
|
||||
//// for (var e in foo.bar) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////
|
||||
//// with (foo.bar) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////
|
||||
//// while (false) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////
|
||||
//// do {
|
||||
////{| "indent": 0 |}
|
||||
//// } while (false);
|
||||
////
|
||||
//// switch (foo.bar) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////
|
||||
//// switch (foo.bar) {
|
||||
////{| "indent": 0 |}
|
||||
//// case 1:
|
||||
////{| "indent": 0 |}
|
||||
//// break;
|
||||
//// default:
|
||||
////{| "indent": 0 |}
|
||||
//// break;
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function tryCatch() {
|
||||
////{| "indent": 0 |}
|
||||
//// try {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
//// catch (err) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function tryFinally() {
|
||||
////{| "indent": 0 |}
|
||||
//// try {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
//// finally {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function tryCatchFinally() {
|
||||
////{| "indent": 0 |}
|
||||
//// try {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
//// catch (err) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
//// finally {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////class indentBeforeCurly
|
||||
////{| "indent": 0 |}
|
||||
////{| "indent": 0 |}{
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function argumentsListIndentation(bar,
|
||||
//// blah,
|
||||
//// {| "indent": 0 |}
|
||||
////);
|
||||
////
|
||||
////
|
||||
////function blockIndentAfterIndentedParameter1(bar,
|
||||
//// blah) {
|
||||
////{| "indent": 0 |}
|
||||
////}
|
||||
////
|
||||
////
|
||||
////function blockIndentAfterIndentedParameter2(bar,
|
||||
//// blah) {
|
||||
//// if (foo) {
|
||||
////{| "indent": 0 |}
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
////
|
||||
////// Note: Do not add more tests at the end of this file, as
|
||||
////// the purpose of this test is to verity smart indent
|
||||
////// works for unterminated function arguments at the end of a file.
|
||||
////function unterminatedListIndentation(a,
|
||||
////{| "indent": 0 |}
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent, IndentStyle.None);
|
||||
});
|
||||
Reference in New Issue
Block a user