gitlab.com/evatix-go/core@v1.3.55/corevalidator/SimpleSliceRangeValidator.go (about) 1 package corevalidator 2 3 import ( 4 "gitlab.com/evatix-go/core/coredata/corestr" 5 ) 6 7 type SimpleSliceRangeValidator struct { 8 actual *corestr.SimpleSlice 9 VerifierSegments []RangesSegment 10 } 11 12 func (it *SimpleSliceRangeValidator) LengthOfVerifierSegments() int { 13 return len(it.VerifierSegments) 14 } 15 16 func (it *SimpleSliceRangeValidator) SetActual( 17 lines []string, 18 ) *SimpleSliceRangeValidator { 19 it.actual = corestr.New.SimpleSlice.Direct( 20 false, 21 lines) 22 23 return it 24 } 25 26 func (it *SimpleSliceRangeValidator) SliceValidators() *SliceValidators { 27 validators := make([]*SliceValidator, it.LengthOfVerifierSegments()) 28 29 for _, segment := range it.VerifierSegments { 30 expectedSegments := segment.ExpectedLines 31 actualSegments := it.actual.Items[segment.RangeInt.Start:segment.RangeInt.End] 32 33 sliceValidator := SliceValidator{ 34 CompareAs: segment.CompareAs, 35 ValidatorCoreCondition: segment.ValidatorCoreCondition, 36 ActualLines: actualSegments, 37 ExpectedLines: expectedSegments, 38 } 39 40 validators = append(validators, &sliceValidator) 41 } 42 43 return &SliceValidators{ 44 Validators: validators, 45 } 46 } 47 48 func (it *SimpleSliceRangeValidator) VerifyAll( 49 header string, 50 actual []string, 51 params *ValidatorParamsBase, 52 isPrintError bool, 53 ) error { 54 it.SetActual(actual) 55 56 return it.SliceValidators().VerifyAll( 57 header, 58 params, 59 isPrintError) 60 } 61 62 func (it *SimpleSliceRangeValidator) VerifyFirst( 63 header string, 64 actual []string, 65 params *ValidatorParamsBase, 66 isPrintError bool, 67 ) error { 68 it.SetActual(actual) 69 70 return it.SliceValidators().VerifyFirst( 71 header, 72 params, 73 isPrintError) 74 } 75 76 func (it *SimpleSliceRangeValidator) VerifyUpto( 77 header string, 78 actual []string, 79 params *ValidatorParamsBase, 80 length int, 81 isPrintError bool, 82 ) error { 83 it.SetActual(actual) 84 85 return it.SliceValidators().VerifyUpto( 86 isPrintError, 87 false, 88 length, 89 header, 90 params, 91 ) 92 }