MCPcopy
hub / github.com/sirupsen/logrus / TestNewlineBehavior

Function TestNewlineBehavior

text_formatter_test.go:299–320  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

297}
298
299func TestNewlineBehavior(t *testing.T) {
300 tf := &TextFormatter{ForceColors: true}
301
302 // Ensure a single new line is removed as per stdlib log
303 e := NewEntry(StandardLogger())
304 e.Message = "test message\n"
305 b, _ := tf.Format(e)
306 if bytes.Contains(b, []byte("test message\n")) {
307 t.Error("first newline at end of Entry.Message resulted in unexpected 2 newlines in output. Expected newline to be removed.")
308 }
309
310 // Ensure a double new line is reduced to a single new line
311 e = NewEntry(StandardLogger())
312 e.Message = "test message\n\n"
313 b, _ = tf.Format(e)
314 if bytes.Contains(b, []byte("test message\n\n")) {
315 t.Error("Double newline at end of Entry.Message resulted in unexpected 2 newlines in output. Expected single newline")
316 }
317 if !bytes.Contains(b, []byte("test message\n")) {
318 t.Error("Double newline at end of Entry.Message did not result in a single newline after formatting")
319 }
320}
321
322func TestTextFormatterFieldMap(t *testing.T) {
323 formatter := &TextFormatter{

Callers

nothing calls this directly

Calls 4

FormatMethod · 0.95
NewEntryFunction · 0.85
StandardLoggerFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected