Added show non-printing option.

This commit is contained in:
Erik C. Thauvin 2021-10-10 20:23:09 -07:00
parent 4948aaa970
commit 9397ebaa37
14 changed files with 316 additions and 298 deletions

View file

@ -7,96 +7,139 @@ void main() {
final List<String> log = [];
int exitCode;
test('Test Help', () async {
expect(app.main(['-h']), completion(equals(0)));
expect(app.main(['--help']), completion(equals(0)));
exitCode = await app.main(['-h']);
expect(exitCode, equals(exitSuccess));
group('app', () {
test('Test Help', () async {
expect(app.main(['-h']), completion(equals(0)));
expect(app.main(['--help']), completion(equals(0)));
exitCode = await app.main(['-h']);
expect(exitCode, equals(exitSuccess));
});
test('Test --version', () async {
expect(app.main(['--version']), completion(equals(0)));
exitCode = await app.main(['--version']);
expect(exitCode, equals(exitSuccess));
});
test('Test directory', () async {
exitCode = await app.main(['bin']);
expect(exitCode, equals(exitFailure));
});
test('Test missing file', () async {
exitCode = await app.main(['foo']);
expect(exitCode, equals(exitFailure), reason: 'foo not found');
exitCode = await app.main(['bin/dcat.dart', 'foo']);
expect(exitCode, equals(exitFailure), reason: 'one missing file');
});
});
test('Test --version', () async {
expect(app.main(['--version']), completion(equals(0)));
exitCode = await app.main(['--version']);
expect(exitCode, equals(exitSuccess));
});
group('lib', () {
test('Test cat source', () async {
await cat(['bin/dcat.dart'], log: log);
expect(log.isEmpty, false, reason: 'log is empty');
expect(log.first, startsWith('// Copyright (c)'),
reason: 'has copyright');
expect(log.last, equals('}'));
});
test('Test directory', () async {
exitCode = await app.main(['bin']);
expect(exitCode, equals(exitFailure));
});
test('Test missing file', () async {
exitCode = await app.main(['foo']);
expect(exitCode, equals(exitFailure), reason: 'foo not found');
exitCode = await app.main(['bin/dcat.dart', 'foo']);
expect(exitCode, equals(exitFailure), reason: 'one missing file');
});
test('Test cat source', () async {
await cat(['bin/dcat.dart'], log: log);
expect(log.isEmpty, false, reason: 'log is empty');
expect(log.first, startsWith('// Copyright (c)'), reason: 'has copyright');
expect(log.last, equals('}'));
});
test('Test cat -n source', () async {
exitCode = await cat(['bin/dcat.dart'], log: log, showLineNumbers: true);
expect(exitCode, 0, reason: 'result code is 0');
expect(log.first, startsWith('1: // Copyright (c)'),
reason: 'has copyright');
expect(log.last, endsWith(': }'), reason: 'last line');
for (final String line in log) {
expect(line, matches('^\\d+: .*'), reason: 'has line number');
}
});
test('Test cat -E', () async {
await cat(['test/test.txt'], log: log, showEnds: true);
var hasBlank = false;
for (final String line in log) {
expect(line, endsWith('\$'));
if (line == '\$') {
hasBlank = true;
test('Test cat -n source', () async {
exitCode = await cat(['bin/dcat.dart'], log: log, showLineNumbers: true);
expect(exitCode, 0, reason: 'result code is 0');
expect(log.first, startsWith(' 1 // Copyright (c)'),
reason: 'has copyright');
expect(log.last, endsWith(' }'), reason: 'last line');
for (final String line in log) {
expect(line, matches('^ +\\d+ .*'), reason: 'has line number');
}
}
expect(hasBlank, true, reason: 'has blank line');
});
});
test('Test cat -bE', () async {
await cat(['test/test.txt'],
log: log, numberNonBlank: true, showEnds: true);
var hasBlank = false;
for (final String line in log) {
expect(line, endsWith('\$'));
if (line.contains(RegExp(r'^\d+: .*\$$'))) {
hasBlank = true;
}
}
expect(hasBlank, true, reason: 'has blank line');
});
test('Test cat source test', () async {
await cat(['bin/dcat.dart', 'test/test.txt'], log: log);
expect(log.length, greaterThan(10), reason: 'more than 10 lines');
expect(log.first, startsWith('// Copyright'),
reason: 'start with copyright');
expect(log.last, endsWith(''), reason: 'end with checkmark');
});
test('Test cat -T', () async {
await cat(['test/test.txt'], log: log, showTabs: true);
var hasTab = false;
for (final String line in log) {
if (line.startsWith('^I')) {
hasTab = true;
break;
test('Test cat -E', () async {
await cat(['test/test.txt'], log: log, showEnds: true);
var hasBlank = false;
for (final String line in log) {
expect(line, endsWith('\$'));
if (line == '\$') {
hasBlank = true;
}
}
}
expect(hasTab, true, reason: 'has tab');
});
expect(hasBlank, true, reason: 'has blank line');
expect(log.last, endsWith('\$'), reason: 'has unicode');
});
test('Test cat -s', () async {
await cat(['test/test.txt'], log: log, squeezeBlank: true);
var hasSqueeze = true;
var prevLine = 'foo';
for (final String line in log) {
if (line == prevLine) {
hasSqueeze = false;
test('Test cat -bE', () async {
await cat(['test/test.txt'],
log: log, numberNonBlank: true, showEnds: true);
var hasBlank = false;
for (final String line in log) {
expect(line, endsWith('\$'));
if (line.contains(RegExp(r'^ +\d+ .*\$$'))) {
hasBlank = true;
}
}
prevLine = line;
}
expect(hasSqueeze, true, reason: 'has squeeze');
expect(hasBlank, true, reason: 'has blank line');
});
test('Test cat -T', () async {
await cat(['test/test.txt'], log: log, showTabs: true);
var hasTab = false;
for (final String line in log) {
if (line.startsWith('^I')) {
hasTab = true;
break;
}
}
expect(hasTab, true, reason: 'has tab');
});
test('Test cat -s', () async {
await cat(['test/test.txt'], log: log, squeezeBlank: true);
var hasSqueeze = true;
var prevLine = 'foo';
for (final String line in log) {
if (line == prevLine) {
hasSqueeze = false;
}
prevLine = line;
}
expect(hasSqueeze, true, reason: 'has squeeze');
});
test('Test cat -A', () async {
await cat(['test/test.txt'],
log: log, showNonPrinting: true, showEnds: true, showTabs: true);
expect(log.last, equals('^I^A^B^C^DM-^?\$'));
});
test('Test cat -t', () async {
await cat(['test/test.txt'],
log: log, showNonPrinting: true, showTabs: true);
expect(log.last, equals('^I^A^B^C^DM-^?'));
});
test('Test cat-Abs', () async {
await cat(['test/test.txt'],
log: log,
showNonPrinting: true,
showEnds: true,
showTabs: true,
numberNonBlank: true,
squeezeBlank: true);
var blankLines = 0;
for (final String line in log) {
if (line == '\$') {
blankLines++;
}
}
expect(blankLines, 2, reason: 'only 2 blank lines.');
});
});
}