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