vitess.io/vitess@v0.16.2/go/tools/asthelpergen/integration/integration_clone_test.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package integration 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 ) 24 25 func TestCloneLeaf(t *testing.T) { 26 leaf1 := &Leaf{1} 27 clone := CloneRefOfLeaf(leaf1) 28 assert.Equal(t, leaf1, clone) 29 leaf1.v = 5 30 assert.NotEqual(t, leaf1, clone) 31 } 32 33 func TestClone2(t *testing.T) { 34 container := &RefContainer{ 35 ASTType: &RefContainer{}, 36 NotASTType: 0, 37 ASTImplementationType: &Leaf{2}, 38 } 39 clone := CloneRefOfRefContainer(container) 40 assert.Equal(t, container, clone) 41 container.ASTImplementationType.v = 5 42 assert.NotEqual(t, container, clone) 43 } 44 45 func TestTypeException(t *testing.T) { 46 l1 := &Leaf{1} 47 nc := &NoCloneType{1} 48 49 slice := InterfaceSlice{ 50 l1, 51 nc, 52 } 53 54 clone := CloneAST(slice) 55 56 // change the original values 57 l1.v = 99 58 nc.v = 99 59 60 expected := InterfaceSlice{ 61 &Leaf{1}, // the change is not seen 62 &NoCloneType{99}, // since this type is not cloned, we do see the change 63 } 64 65 assert.Equal(t, expected, clone) 66 }