blob: 6607e6599e358ae263ce411dd65eceac2680e470 [file] [log] [blame]
Colin Cross86803cf2018-02-15 14:12:26 -08001// 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
Dan Willemsen2249dc82018-10-15 00:35:59 -070015package symbol_inject
Colin Cross86803cf2018-02-15 14:12:26 -080016
17import (
18 "bytes"
19 "strconv"
20 "testing"
21)
22
23func TestCopyAndInject(t *testing.T) {
24 s := "abcdefghijklmnopqrstuvwxyz"
25 testCases := []struct {
Dan Willemsen0db18c22018-10-15 17:05:35 -070026 offset uint64
27 buf string
28 expected string
Colin Cross86803cf2018-02-15 14:12:26 -080029 }{
30 {
31 offset: 0,
Dan Willemsen0db18c22018-10-15 17:05:35 -070032 buf: "A",
Colin Cross86803cf2018-02-15 14:12:26 -080033 expected: "Abcdefghijklmnopqrstuvwxyz",
34 },
35 {
36 offset: 1,
Dan Willemsen0db18c22018-10-15 17:05:35 -070037 buf: "B",
Colin Cross86803cf2018-02-15 14:12:26 -080038 expected: "aBcdefghijklmnopqrstuvwxyz",
39 },
40 {
41 offset: 25,
Dan Willemsen0db18c22018-10-15 17:05:35 -070042 buf: "Z",
Colin Cross86803cf2018-02-15 14:12:26 -080043 expected: "abcdefghijklmnopqrstuvwxyZ",
44 },
45 }
46
47 for i, testCase := range testCases {
48 t.Run(strconv.Itoa(i), func(t *testing.T) {
49 in := bytes.NewReader([]byte(s))
50 out := &bytes.Buffer{}
Dan Willemsen0db18c22018-10-15 17:05:35 -070051 copyAndInject(in, out, testCase.offset, []byte(testCase.buf))
Colin Cross86803cf2018-02-15 14:12:26 -080052
53 if out.String() != testCase.expected {
54 t.Errorf("expected %s, got %s", testCase.expected, out.String())
55 }
56 })
57 }
58}