|
| 1 | +package cliargs |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/stretchr/testify/assert" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestNewRuneBuffer_empty(t *testing.T) { |
| 9 | + rb := newRuneBuffer(0) |
| 10 | + assert.Equal(t, rb.runes, []rune{}) |
| 11 | + assert.Equal(t, rb.length, 0) |
| 12 | + assert.Equal(t, len(rb.runes), 0) |
| 13 | + assert.Equal(t, cap(rb.runes), 0) |
| 14 | + assert.Equal(t, rb.slice(), []rune{}) |
| 15 | +} |
| 16 | + |
| 17 | +func TestRuneBuffer_add(t *testing.T) { |
| 18 | + rb := newRuneBuffer(5) |
| 19 | + assert.Equal(t, rb.runes, []rune{0, 0, 0, 0, 0}) |
| 20 | + assert.Equal(t, rb.length, 0) |
| 21 | + assert.Equal(t, len(rb.runes), 5) |
| 22 | + assert.Equal(t, cap(rb.runes), 5) |
| 23 | + assert.Equal(t, rb.slice(), []rune{}) |
| 24 | + |
| 25 | + assert.True(t, rb.add('1')) |
| 26 | + assert.Equal(t, rb.runes, []rune{'1', 0, 0, 0, 0}) |
| 27 | + assert.Equal(t, rb.length, 1) |
| 28 | + assert.Equal(t, len(rb.runes), 5) |
| 29 | + assert.Equal(t, cap(rb.runes), 5) |
| 30 | + assert.Equal(t, rb.slice(), []rune{'1'}) |
| 31 | + |
| 32 | + assert.True(t, rb.add('2', '3')) |
| 33 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', 0, 0}) |
| 34 | + assert.Equal(t, rb.length, 3) |
| 35 | + assert.Equal(t, len(rb.runes), 5) |
| 36 | + assert.Equal(t, cap(rb.runes), 5) |
| 37 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3'}) |
| 38 | + |
| 39 | + assert.False(t, rb.add('x', 'y', 'z')) |
| 40 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', 0, 0}) |
| 41 | + assert.Equal(t, rb.length, 3) |
| 42 | + assert.Equal(t, len(rb.runes), 5) |
| 43 | + assert.Equal(t, cap(rb.runes), 5) |
| 44 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3'}) |
| 45 | + |
| 46 | + assert.True(t, rb.add('4', '5')) |
| 47 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', '4', '5'}) |
| 48 | + assert.Equal(t, rb.length, 5) |
| 49 | + assert.Equal(t, len(rb.runes), 5) |
| 50 | + assert.Equal(t, cap(rb.runes), 5) |
| 51 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3', '4', '5'}) |
| 52 | + |
| 53 | + assert.False(t, rb.add('6')) |
| 54 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', '4', '5'}) |
| 55 | + assert.Equal(t, rb.length, 5) |
| 56 | + assert.Equal(t, len(rb.runes), 5) |
| 57 | + assert.Equal(t, cap(rb.runes), 5) |
| 58 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3', '4', '5'}) |
| 59 | +} |
| 60 | + |
| 61 | +func TestRuneBuffer_cr(t *testing.T) { |
| 62 | + rb := newRuneBuffer(5) |
| 63 | + assert.Equal(t, rb.runes, []rune{0, 0, 0, 0, 0}) |
| 64 | + assert.Equal(t, rb.length, 0) |
| 65 | + assert.Equal(t, len(rb.runes), 5) |
| 66 | + assert.Equal(t, cap(rb.runes), 5) |
| 67 | + assert.Equal(t, rb.slice(), []rune{}) |
| 68 | + |
| 69 | + assert.True(t, rb.add('1', '2', '3', '4', '5')) |
| 70 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', '4', '5'}) |
| 71 | + assert.Equal(t, rb.length, 5) |
| 72 | + assert.Equal(t, len(rb.runes), 5) |
| 73 | + assert.Equal(t, cap(rb.runes), 5) |
| 74 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3', '4', '5'}) |
| 75 | + |
| 76 | + rb.cr(3) |
| 77 | + assert.Equal(t, rb.runes, []rune{'4', '5', '3', '4', '5'}) |
| 78 | + assert.Equal(t, rb.length, 2) |
| 79 | + assert.Equal(t, len(rb.runes), 5) |
| 80 | + assert.Equal(t, cap(rb.runes), 5) |
| 81 | + assert.Equal(t, rb.slice(), []rune{'4', '5'}) |
| 82 | + |
| 83 | + assert.True(t, rb.add('6')) |
| 84 | + assert.Equal(t, rb.runes, []rune{'4', '5', '6', '4', '5'}) |
| 85 | + assert.Equal(t, rb.length, 3) |
| 86 | + assert.Equal(t, len(rb.runes), 5) |
| 87 | + assert.Equal(t, cap(rb.runes), 5) |
| 88 | + assert.Equal(t, rb.slice(), []rune{'4', '5', '6'}) |
| 89 | + |
| 90 | + rb.cr(3) |
| 91 | + assert.Equal(t, rb.runes, []rune{'4', '5', '6', '4', '5'}) |
| 92 | + assert.Equal(t, rb.length, 0) |
| 93 | + assert.Equal(t, len(rb.runes), 5) |
| 94 | + assert.Equal(t, cap(rb.runes), 5) |
| 95 | + assert.Equal(t, rb.slice(), []rune{}) |
| 96 | + |
| 97 | + assert.True(t, rb.add('1', '2', '3', '4', '5')) |
| 98 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', '4', '5'}) |
| 99 | + assert.Equal(t, rb.length, 5) |
| 100 | + assert.Equal(t, len(rb.runes), 5) |
| 101 | + assert.Equal(t, cap(rb.runes), 5) |
| 102 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3', '4', '5'}) |
| 103 | + |
| 104 | + rb.cr(0) |
| 105 | + assert.False(t, rb.add('1', '2', '3', '4', '5')) |
| 106 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', '4', '5'}) |
| 107 | + assert.Equal(t, rb.length, 5) |
| 108 | + assert.Equal(t, len(rb.runes), 5) |
| 109 | + assert.Equal(t, cap(rb.runes), 5) |
| 110 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3', '4', '5'}) |
| 111 | + |
| 112 | + rb.cr(-1) |
| 113 | + assert.False(t, rb.add('1', '2', '3', '4', '5')) |
| 114 | + assert.Equal(t, rb.runes, []rune{'1', '2', '3', '4', '5'}) |
| 115 | + assert.Equal(t, rb.length, 5) |
| 116 | + assert.Equal(t, len(rb.runes), 5) |
| 117 | + assert.Equal(t, cap(rb.runes), 5) |
| 118 | + assert.Equal(t, rb.slice(), []rune{'1', '2', '3', '4', '5'}) |
| 119 | +} |
0 commit comments