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 15package symbol_inject 16 17import ( 18 "bytes" 19 "strconv" 20 "testing" 21) 22 23func TestCopyAndInject(t *testing.T) { 24 s := "abcdefghijklmnopqrstuvwxyz" 25 testCases := []struct { 26 offset uint64 27 buf string 28 expected string 29 }{ 30 { 31 offset: 0, 32 buf: "A", 33 expected: "Abcdefghijklmnopqrstuvwxyz", 34 }, 35 { 36 offset: 1, 37 buf: "B", 38 expected: "aBcdefghijklmnopqrstuvwxyz", 39 }, 40 { 41 offset: 25, 42 buf: "Z", 43 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{} 51 copyAndInject(in, out, testCase.offset, []byte(testCase.buf)) 52 53 if out.String() != testCase.expected { 54 t.Errorf("expected %s, got %s", testCase.expected, out.String()) 55 } 56 }) 57 } 58} 59