(t *testing.T)
| 354 | } |
| 355 | |
| 356 | func TestPrintEntryRedactable(t *testing.T) { |
| 357 | sm := string(redact.StartMarker()) |
| 358 | em := string(redact.EndMarker()) |
| 359 | esc := string(redact.EscapeMarkers(redact.StartMarker())) |
| 360 | b := func(s string) []byte { return []byte(s) } |
| 361 | q := func(s string) string { return sm + s + em } |
| 362 | |
| 363 | testCases := []struct { |
| 364 | entry formatEntry |
| 365 | exp string |
| 366 | }{ |
| 367 | // If the entries are not redactable, they may contain arbitrary |
| 368 | // characters; they get enclosed in redaction markers in the final output. |
| 369 | {formatEntry{}, ""}, |
| 370 | {formatEntry{head: b("abc")}, " " + q("abc")}, |
| 371 | {formatEntry{head: b("abc\nxyz")}, " " + q("abc") + "\n" + q("xyz")}, |
| 372 | {formatEntry{details: b("def")}, " " + q("def")}, |
| 373 | {formatEntry{details: b("def\nxyz")}, " " + q("def") + "\n" + q("xyz")}, |
| 374 | {formatEntry{head: b("abc"), details: b("def")}, " " + q("abc") + q("def")}, |
| 375 | {formatEntry{head: b("abc\nxyz"), details: b("def")}, " " + q("abc") + "\n" + q("xyz") + q("def")}, |
| 376 | {formatEntry{head: b("abc"), details: b("def\n | xyz")}, " " + q("abc") + q("def") + "\n" + q(" | xyz")}, |
| 377 | {formatEntry{head: b("abc\nxyz"), details: b("def\n | xyz")}, " " + q("abc") + "\n" + q("xyz") + q("def") + "\n" + q(" | xyz")}, |
| 378 | // If there were markers in the entry, they get escaped in the output. |
| 379 | {formatEntry{head: b("abc" + em + sm), details: b("def" + em + sm)}, " " + q("abc"+esc+esc) + q("def"+esc+esc)}, |
| 380 | |
| 381 | // If the entries are redactable, then whatever characters they contain |
| 382 | // are assumed safe and copied as-is to the final output. |
| 383 | {formatEntry{redactable: true}, ""}, |
| 384 | {formatEntry{redactable: true, head: b("abc")}, " abc"}, |
| 385 | {formatEntry{redactable: true, head: b("abc\nxyz")}, " abc\nxyz"}, |
| 386 | {formatEntry{redactable: true, details: b("def")}, " def"}, |
| 387 | {formatEntry{redactable: true, details: b("def\nxyz")}, " def\nxyz"}, |
| 388 | {formatEntry{redactable: true, head: b("abc"), details: b("def")}, " abcdef"}, |
| 389 | {formatEntry{redactable: true, head: b("abc\nxyz"), details: b("def")}, " abc\nxyzdef"}, |
| 390 | {formatEntry{redactable: true, head: b("abc"), details: b("def\n | xyz")}, " abcdef\n | xyz"}, |
| 391 | {formatEntry{redactable: true, head: b("abc\nxyz"), details: b("def\n | xyz")}, " abc\nxyzdef\n | xyz"}, |
| 392 | // Entry already contains some markers. |
| 393 | {formatEntry{redactable: true, head: b("a " + q("bc")), details: b("d " + q("ef"))}, " a " + q("bc") + "d " + q("ef")}, |
| 394 | } |
| 395 | |
| 396 | for _, tc := range testCases { |
| 397 | s := state{redactableOutput: true} |
| 398 | s.printEntry(tc.entry) |
| 399 | if s.finalBuf.String() != tc.exp { |
| 400 | t.Errorf("%s: expected %q, got %q", tc.entry, tc.exp, s.finalBuf.String()) |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | func TestFormatSingleLineOutputRedactable(t *testing.T) { |
| 406 | sm := string(redact.StartMarker()) |
nothing calls this directly
no test coverage detected
searching dependent graphs…