symbol_inject_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2018 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package symbol_inject
  15. import (
  16. "bytes"
  17. "strconv"
  18. "testing"
  19. )
  20. func TestCopyAndInject(t *testing.T) {
  21. s := "abcdefghijklmnopqrstuvwxyz"
  22. testCases := []struct {
  23. offset uint64
  24. buf string
  25. expected string
  26. }{
  27. {
  28. offset: 0,
  29. buf: "A",
  30. expected: "Abcdefghijklmnopqrstuvwxyz",
  31. },
  32. {
  33. offset: 1,
  34. buf: "B",
  35. expected: "aBcdefghijklmnopqrstuvwxyz",
  36. },
  37. {
  38. offset: 25,
  39. buf: "Z",
  40. expected: "abcdefghijklmnopqrstuvwxyZ",
  41. },
  42. }
  43. for i, testCase := range testCases {
  44. t.Run(strconv.Itoa(i), func(t *testing.T) {
  45. in := bytes.NewReader([]byte(s))
  46. out := &bytes.Buffer{}
  47. copyAndInject(in, out, testCase.offset, []byte(testCase.buf))
  48. if out.String() != testCase.expected {
  49. t.Errorf("expected %s, got %s", testCase.expected, out.String())
  50. }
  51. })
  52. }
  53. }