vitess.io/vitess@v0.16.2/go/tools/asthelpergen/integration/ast_equals.go (about)

     1  /*
     2  Copyright 2023 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  // Code generated by ASTHelperGen. DO NOT EDIT.
    17  
    18  package integration
    19  
    20  // AST does deep equals between the two objects.
    21  func (cmp *Comparator) AST(inA, inB AST) bool {
    22  	if inA == nil && inB == nil {
    23  		return true
    24  	}
    25  	if inA == nil || inB == nil {
    26  		return false
    27  	}
    28  	switch a := inA.(type) {
    29  	case BasicType:
    30  		b, ok := inB.(BasicType)
    31  		if !ok {
    32  			return false
    33  		}
    34  		return a == b
    35  	case Bytes:
    36  		b, ok := inB.(Bytes)
    37  		if !ok {
    38  			return false
    39  		}
    40  		return cmp.Bytes(a, b)
    41  	case InterfaceContainer:
    42  		b, ok := inB.(InterfaceContainer)
    43  		if !ok {
    44  			return false
    45  		}
    46  		return cmp.InterfaceContainer(a, b)
    47  	case InterfaceSlice:
    48  		b, ok := inB.(InterfaceSlice)
    49  		if !ok {
    50  			return false
    51  		}
    52  		return cmp.InterfaceSlice(a, b)
    53  	case *Leaf:
    54  		b, ok := inB.(*Leaf)
    55  		if !ok {
    56  			return false
    57  		}
    58  		return cmp.RefOfLeaf(a, b)
    59  	case LeafSlice:
    60  		b, ok := inB.(LeafSlice)
    61  		if !ok {
    62  			return false
    63  		}
    64  		return cmp.LeafSlice(a, b)
    65  	case *NoCloneType:
    66  		b, ok := inB.(*NoCloneType)
    67  		if !ok {
    68  			return false
    69  		}
    70  		return cmp.RefOfNoCloneType(a, b)
    71  	case *RefContainer:
    72  		b, ok := inB.(*RefContainer)
    73  		if !ok {
    74  			return false
    75  		}
    76  		return cmp.RefOfRefContainer(a, b)
    77  	case *RefSliceContainer:
    78  		b, ok := inB.(*RefSliceContainer)
    79  		if !ok {
    80  			return false
    81  		}
    82  		return cmp.RefOfRefSliceContainer(a, b)
    83  	case *SubImpl:
    84  		b, ok := inB.(*SubImpl)
    85  		if !ok {
    86  			return false
    87  		}
    88  		return cmp.RefOfSubImpl(a, b)
    89  	case ValueContainer:
    90  		b, ok := inB.(ValueContainer)
    91  		if !ok {
    92  			return false
    93  		}
    94  		return cmp.ValueContainer(a, b)
    95  	case ValueSliceContainer:
    96  		b, ok := inB.(ValueSliceContainer)
    97  		if !ok {
    98  			return false
    99  		}
   100  		return cmp.ValueSliceContainer(a, b)
   101  	default:
   102  		// this should never happen
   103  		return false
   104  	}
   105  }
   106  
   107  // Bytes does deep equals between the two objects.
   108  func (cmp *Comparator) Bytes(a, b Bytes) bool {
   109  	if len(a) != len(b) {
   110  		return false
   111  	}
   112  	for i := 0; i < len(a); i++ {
   113  		if a[i] != b[i] {
   114  			return false
   115  		}
   116  	}
   117  	return true
   118  }
   119  
   120  // InterfaceContainer does deep equals between the two objects.
   121  func (cmp *Comparator) InterfaceContainer(a, b InterfaceContainer) bool {
   122  	return true
   123  }
   124  
   125  // InterfaceSlice does deep equals between the two objects.
   126  func (cmp *Comparator) InterfaceSlice(a, b InterfaceSlice) bool {
   127  	if len(a) != len(b) {
   128  		return false
   129  	}
   130  	for i := 0; i < len(a); i++ {
   131  		if !cmp.AST(a[i], b[i]) {
   132  			return false
   133  		}
   134  	}
   135  	return true
   136  }
   137  
   138  // RefOfLeaf does deep equals between the two objects.
   139  func (cmp *Comparator) RefOfLeaf(a, b *Leaf) bool {
   140  	if a == b {
   141  		return true
   142  	}
   143  	if a == nil || b == nil {
   144  		return false
   145  	}
   146  	return a.v == b.v
   147  }
   148  
   149  // LeafSlice does deep equals between the two objects.
   150  func (cmp *Comparator) LeafSlice(a, b LeafSlice) bool {
   151  	if len(a) != len(b) {
   152  		return false
   153  	}
   154  	for i := 0; i < len(a); i++ {
   155  		if !cmp.RefOfLeaf(a[i], b[i]) {
   156  			return false
   157  		}
   158  	}
   159  	return true
   160  }
   161  
   162  // RefOfNoCloneType does deep equals between the two objects.
   163  func (cmp *Comparator) RefOfNoCloneType(a, b *NoCloneType) bool {
   164  	if a == b {
   165  		return true
   166  	}
   167  	if a == nil || b == nil {
   168  		return false
   169  	}
   170  	return a.v == b.v
   171  }
   172  
   173  // RefOfRefContainer does deep equals between the two objects.
   174  func (cmp *Comparator) RefOfRefContainer(a, b *RefContainer) bool {
   175  	if a == b {
   176  		return true
   177  	}
   178  	if a == nil || b == nil {
   179  		return false
   180  	}
   181  	return a.NotASTType == b.NotASTType &&
   182  		cmp.AST(a.ASTType, b.ASTType) &&
   183  		cmp.RefOfLeaf(a.ASTImplementationType, b.ASTImplementationType)
   184  }
   185  
   186  // RefOfRefSliceContainer does deep equals between the two objects.
   187  func (cmp *Comparator) RefOfRefSliceContainer(a, b *RefSliceContainer) bool {
   188  	if a == b {
   189  		return true
   190  	}
   191  	if a == nil || b == nil {
   192  		return false
   193  	}
   194  	return cmp.SliceOfAST(a.ASTElements, b.ASTElements) &&
   195  		cmp.SliceOfInt(a.NotASTElements, b.NotASTElements) &&
   196  		cmp.SliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements)
   197  }
   198  
   199  // RefOfSubImpl does deep equals between the two objects.
   200  func (cmp *Comparator) RefOfSubImpl(a, b *SubImpl) bool {
   201  	if a == b {
   202  		return true
   203  	}
   204  	if a == nil || b == nil {
   205  		return false
   206  	}
   207  	return cmp.SubIface(a.inner, b.inner) &&
   208  		cmp.RefOfBool(a.field, b.field)
   209  }
   210  
   211  // ValueContainer does deep equals between the two objects.
   212  func (cmp *Comparator) ValueContainer(a, b ValueContainer) bool {
   213  	return a.NotASTType == b.NotASTType &&
   214  		cmp.AST(a.ASTType, b.ASTType) &&
   215  		cmp.RefOfLeaf(a.ASTImplementationType, b.ASTImplementationType)
   216  }
   217  
   218  // ValueSliceContainer does deep equals between the two objects.
   219  func (cmp *Comparator) ValueSliceContainer(a, b ValueSliceContainer) bool {
   220  	return cmp.SliceOfAST(a.ASTElements, b.ASTElements) &&
   221  		cmp.SliceOfInt(a.NotASTElements, b.NotASTElements) &&
   222  		cmp.SliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements)
   223  }
   224  
   225  // SubIface does deep equals between the two objects.
   226  func (cmp *Comparator) SubIface(inA, inB SubIface) bool {
   227  	if inA == nil && inB == nil {
   228  		return true
   229  	}
   230  	if inA == nil || inB == nil {
   231  		return false
   232  	}
   233  	switch a := inA.(type) {
   234  	case *SubImpl:
   235  		b, ok := inB.(*SubImpl)
   236  		if !ok {
   237  			return false
   238  		}
   239  		return cmp.RefOfSubImpl(a, b)
   240  	default:
   241  		// this should never happen
   242  		return false
   243  	}
   244  }
   245  
   246  // RefOfInterfaceContainer does deep equals between the two objects.
   247  func (cmp *Comparator) RefOfInterfaceContainer(a, b *InterfaceContainer) bool {
   248  	if a == b {
   249  		return true
   250  	}
   251  	if a == nil || b == nil {
   252  		return false
   253  	}
   254  	return true
   255  }
   256  
   257  // SliceOfAST does deep equals between the two objects.
   258  func (cmp *Comparator) SliceOfAST(a, b []AST) bool {
   259  	if len(a) != len(b) {
   260  		return false
   261  	}
   262  	for i := 0; i < len(a); i++ {
   263  		if !cmp.AST(a[i], b[i]) {
   264  			return false
   265  		}
   266  	}
   267  	return true
   268  }
   269  
   270  // SliceOfInt does deep equals between the two objects.
   271  func (cmp *Comparator) SliceOfInt(a, b []int) bool {
   272  	if len(a) != len(b) {
   273  		return false
   274  	}
   275  	for i := 0; i < len(a); i++ {
   276  		if a[i] != b[i] {
   277  			return false
   278  		}
   279  	}
   280  	return true
   281  }
   282  
   283  // SliceOfRefOfLeaf does deep equals between the two objects.
   284  func (cmp *Comparator) SliceOfRefOfLeaf(a, b []*Leaf) bool {
   285  	if len(a) != len(b) {
   286  		return false
   287  	}
   288  	for i := 0; i < len(a); i++ {
   289  		if !cmp.RefOfLeaf(a[i], b[i]) {
   290  			return false
   291  		}
   292  	}
   293  	return true
   294  }
   295  
   296  // RefOfBool does deep equals between the two objects.
   297  func (cmp *Comparator) RefOfBool(a, b *bool) bool {
   298  	if a == b {
   299  		return true
   300  	}
   301  	if a == nil || b == nil {
   302  		return false
   303  	}
   304  	return *a == *b
   305  }
   306  
   307  // RefOfValueContainer does deep equals between the two objects.
   308  func (cmp *Comparator) RefOfValueContainer(a, b *ValueContainer) bool {
   309  	if a == b {
   310  		return true
   311  	}
   312  	if a == nil || b == nil {
   313  		return false
   314  	}
   315  	return a.NotASTType == b.NotASTType &&
   316  		cmp.AST(a.ASTType, b.ASTType) &&
   317  		cmp.RefOfLeaf(a.ASTImplementationType, b.ASTImplementationType)
   318  }
   319  
   320  // RefOfValueSliceContainer does deep equals between the two objects.
   321  func (cmp *Comparator) RefOfValueSliceContainer(a, b *ValueSliceContainer) bool {
   322  	if a == b {
   323  		return true
   324  	}
   325  	if a == nil || b == nil {
   326  		return false
   327  	}
   328  	return cmp.SliceOfAST(a.ASTElements, b.ASTElements) &&
   329  		cmp.SliceOfInt(a.NotASTElements, b.NotASTElements) &&
   330  		cmp.SliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements)
   331  }
   332  
   333  type Comparator struct{}