check bar.Current() in TestBarEnableTriggerCompleteAndIncrementAfter
Vladimir Bauer
2 years ago
| 101 | 101 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) |
| 102 | 102 | bar := p.AddBar(0) // never complete bar |
| 103 | 103 | |
| 104 | targetTotal := int64(80) | |
| 105 | ||
| 104 | 106 | for _, f := range []func(){ |
| 105 | 107 | func() { bar.SetTotal(40, false) }, |
| 106 | 108 | func() { bar.IncrBy(60) }, |
| 107 | func() { bar.SetTotal(80, false) }, | |
| 108 | func() { bar.EnableTriggerComplete() }, | |
| 109 | func() { bar.SetTotal(targetTotal, false) }, | |
| 110 | func() { bar.EnableTriggerComplete() }, // disables any next SetTotal | |
| 111 | func() { bar.SetTotal(100, true) }, // nop | |
| 109 | 112 | } { |
| 110 | 113 | f() |
| 111 | 114 | if bar.Completed() { |
| 117 | 120 | |
| 118 | 121 | if !bar.Completed() { |
| 119 | 122 | t.Fail() |
| 123 | } | |
| 124 | ||
| 125 | if current := bar.Current(); current != targetTotal { | |
| 126 | t.Errorf("Expected current: %d, got: %d", targetTotal, current) | |
| 120 | 127 | } |
| 121 | 128 | |
| 122 | 129 | p.Wait() |