string_builder_test.go 852 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestStringBuilderWriteByte(t *testing.T) {
  10. var b StringBuilder
  11. err := b.WriteByte('c')
  12. assert.NoError(t, err)
  13. assert.EqualValues(t, "c", b.String())
  14. b.Reset()
  15. var content = "123456"
  16. for _, c := range content {
  17. _, err = b.WriteRune(c)
  18. assert.NoError(t, err)
  19. }
  20. assert.EqualValues(t, 6, b.Len())
  21. assert.EqualValues(t, content, b.String())
  22. for i := 0; i < 100; i++ {
  23. for _, c := range content {
  24. _, err = b.WriteRune(c)
  25. assert.NoError(t, err)
  26. }
  27. }
  28. b.Grow(600)
  29. for i := 0; i < 100; i++ {
  30. for _, c := range content {
  31. _, err = b.WriteRune(c)
  32. assert.NoError(t, err)
  33. }
  34. }
  35. }