Simplify tests

This commit is contained in:
Vishesh Handa
2020-08-13 00:51:54 +02:00
parent d4b201f7ef
commit ed08672ee2

View File

@ -4,60 +4,59 @@ import 'package:test/test.dart';
import 'package:gitjournal/widgets/markdown_toolbar.dart'; import 'package:gitjournal/widgets/markdown_toolbar.dart';
void main() { void main() {
test('Adds a header to the first line correctly', () { void _testH1({
var val = const TextEditingValue( @required String before,
text: 'Hello', @required int beforeOffset,
selection: TextSelection.collapsed(offset: 5), @required String after,
@required int afterOffset,
}) {
var val = TextEditingValue(
text: before,
selection: TextSelection.collapsed(offset: beforeOffset),
); );
var expectedVal = const TextEditingValue( var expectedVal = TextEditingValue(
text: '# Hello', text: after,
selection: TextSelection.collapsed(offset: 7), selection: TextSelection.collapsed(offset: afterOffset),
); );
expect(modifyCurrentLine(val, '# '), expectedVal); expect(modifyCurrentLine(val, '# '), expectedVal);
}
test('Adds a header to the first line correctly', () {
_testH1(
before: 'Hello',
beforeOffset: 5,
after: '# Hello',
afterOffset: 7,
);
}); });
test('Adds a header to the last line correctly', () { test('Adds a header to the last line correctly', () {
var val = const TextEditingValue( _testH1(
text: 'Hi\nHello', before: 'Hi\nHello',
selection: TextSelection.collapsed(offset: 8), beforeOffset: 8,
after: 'Hi\n# Hello',
afterOffset: 10,
); );
var expectedVal = const TextEditingValue(
text: 'Hi\n# Hello',
selection: TextSelection.collapsed(offset: 10),
);
expect(modifyCurrentLine(val, '# '), expectedVal);
}); });
test('Adds a header to a middle line correctly', () { test('Adds a header to a middle line correctly', () {
var val = const TextEditingValue( _testH1(
text: 'Hi\nHello\nFire', before: 'Hi\nHello\nFire',
selection: TextSelection.collapsed(offset: 8), beforeOffset: 8,
after: 'Hi\n# Hello\nFire',
afterOffset: 10,
); );
var expectedVal = const TextEditingValue(
text: 'Hi\n# Hello\nFire',
selection: TextSelection.collapsed(offset: 10),
);
expect(modifyCurrentLine(val, '# '), expectedVal);
}); });
test('Adds a header to a middle line middle word correctly', () { test('Adds a header to a middle line middle word correctly', () {
var val = const TextEditingValue( _testH1(
text: 'Hi\nHello Darkness\nFire', before: 'Hi\nHello Darkness\nFire',
selection: TextSelection.collapsed(offset: 8), beforeOffset: 8,
after: 'Hi\n# Hello Darkness\nFire',
afterOffset: 10,
); );
var expectedVal = const TextEditingValue(
text: 'Hi\n# Hello Darkness\nFire',
selection: TextSelection.collapsed(offset: 10),
);
expect(modifyCurrentLine(val, '# '), expectedVal);
}); });
// Removes from first line // Removes from first line