gitlab.com/evatix-go/core@v1.3.55/coretests/CompareInstruction.go (about) 1 package coretests 2 3 import ( 4 "gitlab.com/evatix-go/core/coredata/corestr" 5 "gitlab.com/evatix-go/core/errcore" 6 ) 7 8 type ComparingInstruction struct { 9 FunName, 10 Header, 11 TestCaseName, 12 MatchingAsEqualExpectation string 13 ComparingItems []Compare 14 HasWhitespace, IsMatchingAsEqual bool 15 actualHashset *corestr.Hashset 16 actual string 17 } 18 19 func (it *ComparingInstruction) Actual() string { 20 return it.actual 21 } 22 23 func (it *ComparingInstruction) SetActual(actual string) { 24 it.actual = actual 25 it.actualHashset = nil 26 } 27 28 func (it *ComparingInstruction) ActualHashset() *corestr.Hashset { 29 if it.actualHashset != nil { 30 return it.actualHashset 31 } 32 33 whitespaceRemovedSplits := GetMessageToSortedArray( 34 false, 35 true, 36 it.Actual()) 37 38 it.actualHashset = corestr.New.Hashset.StringsPtr(&whitespaceRemovedSplits) 39 40 return it.actualHashset 41 } 42 43 func (it *ComparingInstruction) IsMatch( 44 caseIndexPlusIsPrint *CaseIndexPlusIsPrint, 45 ) bool { 46 isMatchesEqual := it.isMatchingEqual(caseIndexPlusIsPrint) 47 48 for i, item := range it.ComparingItems { 49 isMatchesEqual = item.IsMatch( 50 caseIndexPlusIsPrint.IsPrint, 51 i, 52 it) && 53 isMatchesEqual 54 } 55 56 return isMatchesEqual 57 } 58 59 func (it *ComparingInstruction) isMatchingEqual(caseIndexPlusIsPrint *CaseIndexPlusIsPrint) bool { 60 if !it.IsMatchingAsEqual { 61 return true 62 } 63 64 expectation := &errcore.ExpectationMessageDef{ 65 CaseIndex: caseIndexPlusIsPrint.CaseIndex, 66 FuncName: it.FunName, 67 TestCaseName: it.TestCaseName, 68 When: it.Header, 69 Expected: it.MatchingAsEqualExpectation, 70 IsNonWhiteSort: it.HasWhitespace, 71 } 72 73 return IsStrMsgNonWhiteSortedEqual( 74 caseIndexPlusIsPrint.IsPrint, 75 it.actual, 76 expectation) 77 }