-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed indent for switch expressions.
- Loading branch information
Showing
6 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:analyzer/dart/analysis/results.dart'; | ||
import 'package:analyzer/dart/analysis/utilities.dart' as AnalyzerUtilities; // ignore: library_prefixes | ||
import 'package:analyzer/dart/ast/token.dart'; | ||
import 'package:dart_format/src/FormatState.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../TestTools/TestTools.dart'; | ||
|
||
void main() | ||
{ | ||
TestTools.init(); | ||
|
||
group('FormatState', () | ||
{ | ||
// TODO: better tests, tests with non-; | ||
test('addNewLineAfterToken with ;', () | ||
{ | ||
const String inputText = 'int i=0;int j=0;'; | ||
final Token inputToken1 = Token(TokenType.STRING, 0); | ||
final Token inputToken2 = Token(TokenType.SEMICOLON, 6); | ||
final Token inputToken3 = Token(TokenType.STRING, 7); | ||
final Token inputToken4 = Token(TokenType.SEMICOLON, 14); | ||
inputToken1.next = inputToken2; | ||
inputToken2.next = inputToken3; | ||
inputToken3.next = inputToken4; | ||
|
||
final ParseStringResult parseResult = AnalyzerUtilities.parseString(content: inputText); | ||
final FormatState formatState = FormatState( | ||
parseResult, | ||
indentationSpacesPerLevel: 4, | ||
removeTrailingCommas: true | ||
); | ||
|
||
formatState.addText('int i=0', 'SOURCE'); | ||
TestTools.expect(formatState.getResult(), equals('int i=0')); | ||
formatState.addText(';', 'SOURCE'); | ||
formatState.addNewLineAfterToken(inputToken1, 'SOURCE', add: true); | ||
TestTools.expect(formatState.getResult(), equals('int i=0;')); | ||
|
||
formatState.addText('int j=0', 'SOURCE'); | ||
TestTools.expect(formatState.getResult(), equals('int i=0;int j=0')); | ||
formatState.addText(';', 'SOURCE'); | ||
formatState.addNewLineAfterToken(inputToken3, 'SOURCE', add: true); | ||
TestTools.expect(formatState.getResult(), equals('int i=0;int j=0;')); | ||
} | ||
); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:dart_format/src/Formatters/SwitchExpressionFormatter.dart'; | ||
|
||
import '../TestTools/AstCreator.dart'; | ||
import '../TestTools/TestConfig.dart'; | ||
import '../TestTools/TestGroupConfig.dart'; | ||
import '../TestTools/TestTools.dart'; | ||
import '../TestTools/Visitors/TestVisitor.dart'; | ||
|
||
void main() | ||
{ | ||
TestTools.init(); | ||
|
||
final List<TestGroupConfig> testGroupConfigs = <TestGroupConfig>[ | ||
TestGroupConfig( | ||
inputNodeCreator: AstCreator.createSwitchExpressionInReturnStatementExpressionInFunction, | ||
inputLeading: 'int f(){return ', | ||
inputMiddle: 'switch(0){0=>0}', | ||
inputTrailing: ';}', | ||
name: 'SwitchPatternCase', | ||
astVisitors: <TestVisitor<void>>[ | ||
TestVisitor<IntegerLiteral>(22, '0'), | ||
TestVisitor<SwitchExpressionCase>(25, '0=>0'), | ||
], | ||
testConfigs: <TestConfig>[ | ||
TestConfig.none(), | ||
TestConfig('switch(0)\n{\n 0=>0\n}') | ||
] | ||
) | ||
]; | ||
|
||
TestTools.runTestGroupsForFormatter(testGroupConfigs, 'SwitchExpressionFormatter', SwitchExpressionFormatter.new, StackTrace.current); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters