|
| 1 | +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:build_daemon/data/server_log.dart'; |
| 6 | +import 'package:logging/logging.dart'; |
| 7 | +import 'package:test/test.dart'; |
| 8 | +import 'package:webdev/src/logging.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + group('trimLoggerName', () { |
| 12 | + test('properly removes logger names', () { |
| 13 | + expect(trimLoggerName('SomeLogName: foo bar'), equals('foo bar')); |
| 14 | + }); |
| 15 | + |
| 16 | + test('leaves messages untouched if no logger name is present', () { |
| 17 | + expect(trimLoggerName('foo bar looksLikeALoggerName: '), |
| 18 | + equals('foo bar looksLikeALoggerName: ')); |
| 19 | + }); |
| 20 | + |
| 21 | + test('works with empty messages', () { |
| 22 | + expect(trimLoggerName(''), equals('')); |
| 23 | + }); |
| 24 | + |
| 25 | + test('assumes logger names is one word', () { |
| 26 | + expect(trimLoggerName('not a logger: foo bar'), |
| 27 | + equals('not a logger: foo bar')); |
| 28 | + expect(trimLoggerName('foo baz: foo bar'), equals('foo baz: foo bar')); |
| 29 | + }); |
| 30 | + |
| 31 | + test('assumes loggers are directly at the front of a message', () { |
| 32 | + expect( |
| 33 | + trimLoggerName(' notLogger: foo bar'), equals(' notLogger: foo bar')); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + group('levelForLog', () { |
| 38 | + test('correctly returns the level from the log', () { |
| 39 | + expect(levelForLog(ServerLog((b) => b.log = '[INFO] foo bar')), |
| 40 | + equals(Level.INFO)); |
| 41 | + expect(levelForLog(ServerLog((b) => b.log = '[SEVERE] foo bar')), |
| 42 | + equals(Level.SEVERE)); |
| 43 | + }); |
| 44 | + |
| 45 | + test('returns null if no level is present', () { |
| 46 | + expect(levelForLog(ServerLog((b) => b.log = 'foo bar')), isNull); |
| 47 | + }); |
| 48 | + |
| 49 | + test('only looks for levels at the start of a log', () { |
| 50 | + expect(levelForLog(ServerLog((b) => b.log = 'foo bar [INFO]')), isNull); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + group('trimLevel', () { |
| 55 | + test('correctly trims the level from the message', () { |
| 56 | + expect(trimLevel(Level.INFO, '[INFO]foo bar'), equals('foo bar')); |
| 57 | + expect(trimLevel(Level.INFO, '[INFO]no space'), equals('no space')); |
| 58 | + }); |
| 59 | + |
| 60 | + test('leaves the message untouched if the level is not present', () { |
| 61 | + expect(trimLevel(Level.INFO, '[SEVERE] foo bar'), |
| 62 | + equals('[SEVERE] foo bar')); |
| 63 | + }); |
| 64 | + }); |
| 65 | +} |
0 commit comments