MCPcopy Index your code
hub / github.com/schollz/progressbar / TestOptionSetPredictTime

Function TestOptionSetPredictTime

progressbar_test.go:535–563  ·  view source on GitHub ↗

TestOptionSetPredictTime ensures that when predict time is turned off, the progress bar is showing the total steps completed of the given max, otherwise the predicted time in seconds is specified.

(t *testing.T)

Source from the content-addressed store, hash-verified

533// bar is showing the total steps completed of the given max, otherwise the predicted
534// time in seconds is specified.
535func TestOptionSetPredictTime(t *testing.T) {
536 buf := strings.Builder{}
537 bar := NewOptions(
538 10,
539 OptionSetPredictTime(false),
540 OptionSetWidth(10),
541 OptionSetWriter(&buf),
542 )
543
544 _ = bar.Add(2)
545 result := strings.TrimSpace(buf.String())
546 expect := "20% |██ |"
547
548 if result != expect {
549 t.Errorf("Render miss-match\nResult: '%s'\nExpect: '%s'\n%+v", result, expect, bar)
550 }
551
552 bar.Reset()
553 bar.config.predictTime = true
554 buf.Reset()
555
556 _ = bar.Add(7)
557 result = strings.TrimSpace(buf.String())
558 expect = "70% |███████ | [0s:0s]"
559
560 if result != expect {
561 t.Errorf("Render miss-match\nResult: '%s'\nExpect: '%s'\n%+v", result, expect, bar)
562 }
563}
564
565func TestOptionSetElapsedTime_spinner(t *testing.T) {
566 buf := strings.Builder{}

Callers

nothing calls this directly

Calls 7

NewOptionsFunction · 0.85
OptionSetPredictTimeFunction · 0.85
OptionSetWidthFunction · 0.85
OptionSetWriterFunction · 0.85
AddMethod · 0.80
StringMethod · 0.80
ResetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…