Skip to content

Commit

Permalink
Added some explicit tests block comments. (Currently failing, to be f…
Browse files Browse the repository at this point in the history
…ixed soon.)
  • Loading branch information
eggnstone committed Mar 5, 2024
1 parent ee8e8d1 commit c723a4a
Showing 1 changed file with 211 additions and 0 deletions.
211 changes: 211 additions & 0 deletions test/Explicit/BlockCommentsTests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import 'package:dart_format/dart_format.dart';
import 'package:dart_format/src/Analyzer.dart';
import 'package:dart_format/src/Tools/StringTools.dart';
import 'package:eggnstone_dart/eggnstone_dart.dart';
import 'package:test/test.dart';

import '../TestTools/TestTools.dart';

void main()
{
TestTools.init();

group('BlockCommentsTests', ()
{
test('Comment only - no changes expected', ()
{
const String inputText =
'/*START\n'
' TEXT\n'
'END*/\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(inputText);

TestTools.expect(actualText, equals(inputText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment only - indented 1 level too far - removal of 1 level expected', ()
{
const String inputText =
' /*START\n'
' TEXT\n'
' END*/\n';

const String expectedText =
'/*START\n'
' TEXT\n'
'END*/\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(inputText);

TestTools.expect(actualText, equals(expectedText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment in function - indented 1 level too less - addition of 1 level expected', ()
{
const String inputText = 'void f()\n'
'{\n'
'/*START\n'
' TEXT\n'
'END*/\n'
' s;\n'
'}\n';

const String expectedText = 'void f()\n'
'{\n'
' /*START\n'
' TEXT\n'
' END*/\n'
' s;\n'
'}\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(inputText);

TestTools.expect(actualText, equals(expectedText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment in function - no changes expected', ()
{
const String inputText = 'void f()\n'
'{\n'
' /*START\n'
' TEXT\n'
' END*/\n'
' s;\n'
'}\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(inputText);

TestTools.expect(actualText, equals(inputText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment in function - indented 1 level too far - removal of 1 level expected', ()
{
const String inputText = 'void f()\n'
'{\n'
' /*START\n'
' TEXT\n'
' END*/\n'
' s;\n'
'}\n';

const String expectedText = 'void f()\n'
'{\n'
' /*START\n'
' TEXT\n'
' END*/\n'
' s;\n'
'}\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(expectedText);

TestTools.expect(actualText, equals(inputText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment in function - Prevent negative indentation', ()
{
const String inputText = 'void f()\n'
'{\n'
' /*START\n'
' TEXT\n'
'END*/\n'
' s;\n'
'}\n';

const String expectedText = 'void f()\n'
'{\n'
' /*START\n'
' TEXT\n'
' END*/\n'
' s;\n'
'}\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(expectedText);

TestTools.expect(actualText, equals(inputText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment after semicolon - no changes expected', ()
{
const String inputText = 'int i=0; /*START\n'
' TEXT\n'
' END*/\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(inputText);

TestTools.expect(actualText, equals(inputText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);

test('Comment after semicolon - Prevent negative indentation', ()
{
const String inputText = ' int i=0; /*START\n'
' TEXT\n'
'END*/\n';

const String expectedText = 'int i=0; /*START\n'
' TEXT\n'
'END*/\n';

Analyzer().analyze(inputText);

final Config config = Config.all();
final Formatter formatter = Formatter(config);

final String actualText = formatter.format(inputText);

TestTools.expect(actualText, equals(expectedText));
logDebug('actualText:\n${StringTools.toDisplayString(actualText)}\n$actualText');
}
);
}
);
}

0 comments on commit c723a4a

Please sign in to comment.