DindentRight
Vladimir Bauer
9 years ago
| 14 | 14 | func TestPrependName(t *testing.T) { |
| 15 | 15 | var buf bytes.Buffer |
| 16 | 16 | p := mpb.New().SetOut(&buf) |
| 17 | wantName := "TestBar" | |
| 18 | bar := p.AddBar(100).PrependName(wantName, 0, 0) | |
| 17 | name := "TestBar" | |
| 18 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 19 | PrependName(name, 0, 0) | |
| 19 | 20 | for i := 0; i < 100; i++ { |
| 20 | 21 | bar.Incr(1) |
| 21 | 22 | } |
| 23 | ||
| 22 | 24 | p.Stop() |
| 23 | if !strings.Contains(buf.String(), wantName) { | |
| 24 | t.Errorf("%q not found in bar\n", wantName) | |
| 25 | ||
| 26 | want := name + "[" | |
| 27 | barOut := buf.String() | |
| 28 | if !strings.Contains(barOut, want) { | |
| 29 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | func TestPrependNameDindentRight(t *testing.T) { | |
| 34 | var buf bytes.Buffer | |
| 35 | p := mpb.New().SetOut(&buf) | |
| 36 | name := "TestBar" | |
| 37 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 38 | PrependName(name, len(name)+1, mpb.DidentRight) | |
| 39 | for i := 0; i < 100; i++ { | |
| 40 | bar.Incr(1) | |
| 41 | } | |
| 42 | ||
| 43 | p.Stop() | |
| 44 | ||
| 45 | want := name + " [" | |
| 46 | barOut := buf.String() | |
| 47 | if !strings.Contains(barOut, want) { | |
| 48 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 25 | 49 | } |
| 26 | 50 | } |
| 27 | 51 | |
| 56 | 80 | p := mpb.New().SetOut(&buf) |
| 57 | 81 | |
| 58 | 82 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). |
| 59 | AppendPercentage(0, 0) | |
| 83 | AppendPercentage(6, 0) | |
| 60 | 84 | |
| 61 | 85 | for i := 0; i < 100; i++ { |
| 62 | 86 | time.Sleep(10 * time.Millisecond) |
| 65 | 89 | |
| 66 | 90 | p.Stop() |
| 67 | 91 | |
| 68 | want := "]100 %" | |
| 69 | if !strings.Contains(buf.String(), want) { | |
| 70 | t.Errorf("%q not found in bar\n", want) | |
| 92 | want := "] 100 %" | |
| 93 | barOut := buf.String() | |
| 94 | if !strings.Contains(barOut, want) { | |
| 95 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | func TestAppendPercentageDindentRight(t *testing.T) { | |
| 100 | var buf bytes.Buffer | |
| 101 | p := mpb.New().SetOut(&buf) | |
| 102 | ||
| 103 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 104 | AppendPercentage(6, mpb.DidentRight) | |
| 105 | ||
| 106 | for i := 0; i < 100; i++ { | |
| 107 | time.Sleep(10 * time.Millisecond) | |
| 108 | bar.Incr(1) | |
| 109 | } | |
| 110 | ||
| 111 | p.Stop() | |
| 112 | ||
| 113 | want := "]100 % " | |
| 114 | barOut := buf.String() | |
| 115 | if !strings.Contains(barOut, want) { | |
| 116 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 71 | 117 | } |
| 72 | 118 | } |
| 73 | 119 | |
| 86 | 132 | p.Stop() |
| 87 | 133 | |
| 88 | 134 | want := " 100 %[" |
| 89 | if !strings.Contains(buf.String(), want) { | |
| 90 | t.Errorf("%q not found in bar\n", want) | |
| 135 | barOut := buf.String() | |
| 136 | if !strings.Contains(barOut, want) { | |
| 137 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 91 | 138 | } |
| 92 | 139 | } |
| 93 | 140 | |
| 106 | 153 | p.Stop() |
| 107 | 154 | |
| 108 | 155 | want := "100 % [" |
| 109 | if !strings.Contains(buf.String(), want) { | |
| 110 | t.Errorf("%q not found in bar\n", want) | |
| 156 | barOut := buf.String() | |
| 157 | if !strings.Contains(barOut, want) { | |
| 158 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 111 | 159 | } |
| 112 | 160 | } |