diff --git a/bytetype/bytetype.go b/bytetype/bytetype.go new file mode 100644 index 0000000000000000000000000000000000000000..99ebad908d3450cd8cb93ab7495c331e6230b909 --- /dev/null +++ b/bytetype/bytetype.go @@ -0,0 +1,78 @@ +package bytetype + +import ( + "gitlab.com/evatix-go/core/corecomparator" + "gitlab.com/evatix-go/core/msgtype" +) + +type Variant byte + +func (v Variant) Value() byte { + return byte(v) +} + +func (v Variant) StringValue() string { + return string(v) +} + +// v + n +func (v Variant) Add(n byte) Variant { + return Variant(v.Value() + n) +} + +// v - n +func (v Variant) Subtract(n byte) Variant { + return Variant(v.Value() - n) +} + +func (v Variant) Is(n Variant) bool { + return v.Value() == n.Value() +} + +func (v Variant) IsEqual(n byte) bool { + return v.Value() == n +} + +// v.Value() > n +func (v Variant) IsGreater(n byte) bool { + return v.Value() > n +} + +// v.Value() >= n +func (v Variant) IsGreaterEqual(n byte) bool { + return v.Value() >= n +} + +// v.Value() < n +func (v Variant) IsLess(n byte) bool { + return v.Value() < n +} + +// v.Value() <= n +func (v Variant) IsLessEqual(n byte) bool { + return v.Value() <= n +} + +// Here left is v, and right is `n` +func (v Variant) IsTrue(n byte, compare corecomparator.Compare) bool { + switch compare { + case corecomparator.Equal: + return v.IsEqual(n) + case corecomparator.LeftGreater: + return v.IsGreater(n) + case corecomparator.LeftGreaterEqual: + return v.IsGreaterEqual(n) + case corecomparator.LeftLess: + return v.IsLess(n) + case corecomparator.LeftLessEqual: + return v.IsLessEqual(n) + default: + msg := msgtype.RangeNotMeet( + msgtype.ComparatorShouldBeWithinRanghe.String(), + corecomparator.Min(), + corecomparator.Max(), + compare.Ranges()) + + panic(msg) + } +} diff --git a/conditional/Bool.go b/conditional/Bool.go new file mode 100644 index 0000000000000000000000000000000000000000..6ea64cff00a41f12f2e4192f9c492b0277dbc426 --- /dev/null +++ b/conditional/Bool.go @@ -0,0 +1,12 @@ +package conditional + +func Bool( + isTrue bool, + value, defaultVal bool, +) bool { + if isTrue { + return value + } + + return defaultVal +} diff --git a/conditional/Byte.go b/conditional/Byte.go new file mode 100644 index 0000000000000000000000000000000000000000..151f3cad62036686489587e007bff3d91af6b5cf --- /dev/null +++ b/conditional/Byte.go @@ -0,0 +1,12 @@ +package conditional + +func Byte( + isTrue bool, + value, defaultVal byte, +) byte { + if isTrue { + return value + } + + return defaultVal +} diff --git a/conditional/Int.go b/conditional/Int.go new file mode 100644 index 0000000000000000000000000000000000000000..7d676f5eed5ade2e7f8738559140ac4293df7db5 --- /dev/null +++ b/conditional/Int.go @@ -0,0 +1,12 @@ +package conditional + +func Int( + isTrue bool, + value, defaultVal int, +) int { + if isTrue { + return value + } + + return defaultVal +} diff --git a/conditional/Interface.go b/conditional/Interface.go new file mode 100644 index 0000000000000000000000000000000000000000..198ab1b84b6e48644271c0067cac82f534c7f7ba --- /dev/null +++ b/conditional/Interface.go @@ -0,0 +1,12 @@ +package conditional + +func Interface( + isTrue bool, + value, defaultVal interface{}, +) interface{} { + if isTrue { + return value + } + + return defaultVal +} diff --git a/conditional/String.go b/conditional/String.go new file mode 100644 index 0000000000000000000000000000000000000000..656f431707adec32058b6ef879d95d424dae866d --- /dev/null +++ b/conditional/String.go @@ -0,0 +1,12 @@ +package conditional + +func String( + isTrue bool, + value, defaultVal string, +) string { + if isTrue { + return value + } + + return defaultVal +} diff --git a/conditional/StringPtr.go b/conditional/StringPtr.go new file mode 100644 index 0000000000000000000000000000000000000000..bb2e652b286c9ef5bd5712c3476c6edea71c2b20 --- /dev/null +++ b/conditional/StringPtr.go @@ -0,0 +1,12 @@ +package conditional + +func StringPtr( + isTrue bool, + value, defaultVal *string, +) *string { + if isTrue { + return value + } + + return defaultVal +} diff --git a/constants/arrayvars.go b/constants/arrayvars.go index 12c3dc07dad770f32d3a5d77fca6cf85b717c89f..960d209a46dfd4f08813a5cce7c2267f2c529847 100644 --- a/constants/arrayvars.go +++ b/constants/arrayvars.go @@ -1,5 +1,6 @@ package constants +//goland:noinspection ALL var ( // Copied from golang strings AsciiSpace = [256]uint8{ diff --git a/constants/constants.go b/constants/constants.go index 3d939446f9bed36ced2114bebe2952c37ba1545f..b6d36b537e6f9bb95d60fadf1d6227d4ba597c47 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -6,150 +6,149 @@ import ( //goland:noinspection ALL const ( - EmptyArray = "[]" - FirstItemEmptyStringArray = "[\"\"]" - EmptyStatus = "Empty Status" - FilePath = "File Path" - DirectoryPath = "Directory Path" - Dot = "." - UpperCaseA byte = 'A' - UpperCaseZ byte = 'Z' - LowerCaseA byte = 'a' - LowerCaseZ byte = 'z' - LowerCase = LowerCaseA - UpperCaseA // c - 'A' + 'a' (ref: https://bit.ly/3mFnUPW) a - A = 32 also works - UpperCase = UpperCaseA - LowerCaseA // c - 'a' + 'A' - NewLineMac = "\n" - NewLineUnix = "\n" - NewLineWindows = "\r\n" - Tab = "\t" - TabV = "\v" - Hash = "#" - DoubleHash = "##" - TrippleHash = "###" - HashSpace = "# " - DoubleHashSpace = "## " - Space = " " - Hyphen = "-" - Semicolon = ";" - Comma = "," - CommaSpace = ", " - SpaceColonSpace = " : " - Pipe = "|" - QuestionMarkSymbol = "?" - NilString = "nil" - SprintValueFormat = "%v" - SprintNumberFormat = "%d" - SprintFullPropertyNameValueFormat = "%#v" - SprintPropertyNameValueFormat = "%+v" - SprintTypeFormat = "%T" - InvalidNotFoundCase = -1 - Zero = 0 - NotImplemented = "Not Implemented" - SingleQuoteSymbol byte = '\'' - DoubleQuoteSymbol byte = '"' - SingleQuoteStringSymbol = "'" - DoubleQuoteStringSymbol = "\"" - DoubleDoubleQuoteStringSymbol = "\"\"" - ParenthesisStartSymbol byte = '(' - ParenthesisEndSymbol byte = ')' - CurlyStartSymbol byte = '{' - CurlyEndSymbol byte = '}' - SquareStartSymbol byte = '[' - SquareEndSymbol byte = ']' - ArbitraryCapacity1 = 1 - ArbitraryCapacity2 = 2 - ArbitraryCapacity3 = 3 - ArbitraryCapacity4 = 4 - ArbitraryCapacity5 = 5 - ArbitraryCapacity6 = 6 - ArbitraryCapacity7 = 7 - ArbitraryCapacity8 = 8 - ArbitraryCapacity9 = 9 - ArbitraryCapacity10 = 10 - ArbitraryCapacity11 = 11 - ArbitraryCapacity12 = 12 - ArbitraryCapacity13 = 13 - ArbitraryCapacity14 = 14 - ArbitraryCapacity15 = 15 - ArbitraryCapacity30 = 30 - ArbitraryCapacity50 = 50 - ArbitraryCapacity100 = 100 - ArbitraryCapacity150 = 150 - ArbitraryCapacity200 = 200 - ArbitraryCapacity250 = 250 - ArbitraryCapacity500 = 500 - ArbitraryCapacity1000 = 1000 - ArbitraryCapacity1500 = 1500 - ArbitraryCapacity2000 = 2000 - ArbitraryCapacity2500 = 2500 - ArbitraryCapacity3000 = 3000 - ArbitraryCapacity5000 = 5000 - ArbitraryCapacity10000 = 10000 - LineFeedUnix byte = '\n' - CarriageReturn byte = '\r' - FormFeed byte = '\f' - SpaceByte byte = ' ' - TabByte byte = '\t' - LineFeedUnixByte byte = '\n' - CarriageReturnByte byte = '\r' - FormFeedByte byte = '\f' - TabVByte byte = '\v' - MaxUnit8 byte = 255 - OtherPathSeparator = "/" - WindowsPathSeparator = "\\" - WindowsOS = "windows" - LowerCaseFileColon = "file:" - DoubleBackSlash = "\\\\" - TripleBackSlash = "\\\\\\" - BackSlash = "\\" - DoubleForwardSlash = "//" - TripleForwardSlash = "///" - BackwardAndForwardSlashes = "\\//" - ForwardSlash = "/" - UriSchemePrefixStandard = "file:///" - UriSchemePrefixTwoSlashes = "file://" - Underscore = "_" - Colon = ":" - Dash = "-" - DoubleDash = "--" - DoubleUnderscore = "__" - GoPath = "GOPATH" - GoBinPath = "GOBIN" - Go111ModuleEnvironment = "GO111MODULE" - On = "on" - PathSeparator = string(os.PathSeparator) - DoublePathSeparator = PathSeparator + PathSeparator - Dollar = "$" - DoubleDollar = "$$" - Percent = "%" - DoublePercent = "%%" - One = 1 - SemiColon = ";" - Path = "PATH" - Unix = "Unix OS" - Windows = "Windows OS" - SymbolicLinkCreationCommandName = "ln" - SymbolicLinkCreationArgument = "-s" - Architecture64 = "X64" - Architecture32 = "X32" - LongPathUncPrefix = `\\?\UNC\` - LongPathQuestionMarkPrefix = `\\?\` - SingleHash = "#" - EmptyString = "" - EndOfBlock = "}" - EndOfLineMark = ";" - StartOfBlock = "{" - MinusOne = -1 - InvalidInstance = -1 - InvalidValue = -1 - WildCardSymbol = "*" - ParenthesisStart = "(" - ParenthesisEnd = ")" - CurlyStart = "{" - CurlyEnd = "}" - SquareStart = "[" - SquareEnd = "]" - ZeroChar byte = '0' - NineChar byte = '9' - HyphenChar byte = '-' + EmptyArray = "[]" + FirstItemEmptyStringArray = "[\"\"]" + EmptyStatus = "Empty Status" + FilePath = "File Path" + DirectoryPath = "Directory Path" + Dot = "." + UpperCaseA byte = 'A' + UpperCaseZ byte = 'Z' + LowerCaseA byte = 'a' + LowerCaseZ byte = 'z' + LowerCase = LowerCaseA - UpperCaseA // c - 'A' + 'a' (ref: https://bit.ly/3mFnUPW) a - A = 32 also works + UpperCase int16 = int16(UpperCaseA) - int16(LowerCaseA) // c - 'a' + 'A' + NewLineMac = "\n" + NewLineUnix = "\n" + NewLineWindows = "\r\n" + Tab = "\t" + TabV = "\v" + Hash = "#" + DoubleHash = "##" + TrippleHash = "###" + HashSpace = "# " + DoubleHashSpace = "## " + Space = " " + Hyphen = "-" + Semicolon = ";" + Comma = "," + CommaSpace = ", " + SpaceColonSpace = " : " + Pipe = "|" + QuestionMarkSymbol = "?" + NilString = "nil" + SprintValueFormat = "%v" + SprintNumberFormat = "%d" + SprintFullPropertyNameValueFormat = "%#v" + SprintPropertyNameValueFormat = "%+v" + SprintTypeFormat = "%T" + InvalidNotFoundCase = -1 + Zero = 0 + NotImplemented = "Not Implemented" + SingleQuoteSymbol byte = '\'' + DoubleQuoteSymbol byte = '"' + SingleQuoteStringSymbol = "'" + DoubleQuoteStringSymbol = "\"" + DoubleDoubleQuoteStringSymbol = "\"\"" + ParenthesisStartSymbol byte = '(' + ParenthesisEndSymbol byte = ')' + CurlyStartSymbol byte = '{' + CurlyEndSymbol byte = '}' + SquareStartSymbol byte = '[' + SquareEndSymbol byte = ']' + ArbitraryCapacity1 = 1 + ArbitraryCapacity2 = 2 + ArbitraryCapacity3 = 3 + ArbitraryCapacity4 = 4 + ArbitraryCapacity5 = 5 + ArbitraryCapacity6 = 6 + ArbitraryCapacity7 = 7 + ArbitraryCapacity8 = 8 + ArbitraryCapacity9 = 9 + ArbitraryCapacity10 = 10 + ArbitraryCapacity11 = 11 + ArbitraryCapacity12 = 12 + ArbitraryCapacity13 = 13 + ArbitraryCapacity14 = 14 + ArbitraryCapacity15 = 15 + ArbitraryCapacity30 = 30 + ArbitraryCapacity50 = 50 + ArbitraryCapacity100 = 100 + ArbitraryCapacity150 = 150 + ArbitraryCapacity200 = 200 + ArbitraryCapacity250 = 250 + ArbitraryCapacity500 = 500 + ArbitraryCapacity1000 = 1000 + ArbitraryCapacity1500 = 1500 + ArbitraryCapacity2000 = 2000 + ArbitraryCapacity2500 = 2500 + ArbitraryCapacity3000 = 3000 + ArbitraryCapacity5000 = 5000 + ArbitraryCapacity10000 = 10000 + LineFeedUnix byte = '\n' + CarriageReturn byte = '\r' + FormFeed byte = '\f' + SpaceByte byte = ' ' + TabByte byte = '\t' + LineFeedUnixByte byte = '\n' + CarriageReturnByte byte = '\r' + FormFeedByte byte = '\f' + TabVByte byte = '\v' + MaxUnit8 byte = 255 + OtherPathSeparator = "/" + WindowsPathSeparator = "\\" + WindowsOS = "windows" + LowerCaseFileColon = "file:" + DoubleBackSlash = "\\\\" + TripleBackSlash = "\\\\\\" + BackSlash = "\\" + DoubleForwardSlash = "//" + TripleForwardSlash = "///" + BackwardAndForwardSlashes = "\\//" + ForwardSlash = "/" + UriSchemePrefixStandard = "file:///" + UriSchemePrefixTwoSlashes = "file://" + Underscore = "_" + Colon = ":" + Dash = "-" + DoubleDash = "--" + DoubleUnderscore = "__" + GoPath = "GOPATH" + GoBinPath = "GOBIN" + Go111ModuleEnvironment = "GO111MODULE" + On = "on" + PathSeparator = string(os.PathSeparator) + DoublePathSeparator = PathSeparator + PathSeparator + Dollar = "$" + DoubleDollar = "$$" + Percent = "%" + DoublePercent = "%%" + One = 1 + SemiColon = ";" + Path = "PATH" + Unix = "Unix OS" + Windows = "Windows OS" + SymbolicLinkCreationCommandName = "ln" + SymbolicLinkCreationArgument = "-s" + Architecture64 = "X64" + Architecture32 = "X32" + LongPathUncPrefix = `\\?\UNC\` + LongPathQuestionMarkPrefix = `\\?\` + SingleHash = "#" + EmptyString = "" + EndOfBlock = "}" + EndOfLineMark = ";" + StartOfBlock = "{" + MinusOne = -1 + InvalidValue = -1 + WildCardSymbol = "*" + ParenthesisStart = "(" + ParenthesisEnd = ")" + CurlyStart = "{" + CurlyEnd = "}" + SquareStart = "[" + SquareEnd = "]" + ZeroChar byte = '0' + NineChar byte = '9' + HyphenChar byte = '-' ) diff --git a/constants/line_darwin.go b/constants/line_darwin.go index 6d5551bee6c536a00956a2a03d291ef631725340..3767e811be473021d6465b79374fccb5f6026383 100644 --- a/constants/line_darwin.go +++ b/constants/line_darwin.go @@ -2,5 +2,7 @@ package constants const ( // Reference: https://stackoverflow.com/a/49963413 + // Operating system based newline, for unix it is "\n" + // For Windows Operating system, "\r\n" NewLine = NewLineMac ) diff --git a/constants/line_linux.go b/constants/line_linux.go index a2c4f9ba5c7ff9ede8472c9c751b6aa7142921ba..68753ea022a921a1aae1b33aaaae2e42b1816361 100644 --- a/constants/line_linux.go +++ b/constants/line_linux.go @@ -2,5 +2,7 @@ package constants const ( // Reference: https://stackoverflow.com/a/49963413 + // Operating system based newline, for unix it is "\n" + // For Windows Operating system, "\r\n" NewLine = NewLineUnix ) diff --git a/constants/line_windwos.go b/constants/line_windwos.go index b2e72c6c46c0303642fc74d49fb62699da3485a1..a3759563c81d3d268aede4a7a7eebd469b434fa3 100644 --- a/constants/line_windwos.go +++ b/constants/line_windwos.go @@ -2,5 +2,7 @@ package constants const ( // Reference: https://stackoverflow.com/a/49963413 + // Operating system based newline, for unix it is "\n" + // For Windows Operating system, "\r\n" NewLine = NewLineWindows ) diff --git a/constants/vars.go b/constants/vars.go index 19ba4a0201a90628b42709de02b195f8c7312b20..580ce5d44b10b307732ed2749411cde957b82381 100644 --- a/constants/vars.go +++ b/constants/vars.go @@ -136,7 +136,6 @@ var ( endOfLineMark = EndOfLineMark startOfBlock = StartOfBlock minusOne = MinusOne - invalidInstance = InvalidInstance invalidValue = InvalidValue wildCardSymbol = WildCardSymbol parenthesisStart = ParenthesisStart diff --git a/constants/varsptr.go b/constants/varsptr.go index 585c986f04531fb8311dec3c5319284889db7208..5a0a2fa1866514e1b650e52811fc11c50de4c31a 100644 --- a/constants/varsptr.go +++ b/constants/varsptr.go @@ -136,7 +136,6 @@ var ( EndOfLineMarkPtr = &endOfLineMark StartOfBlockPtr = &startOfBlock MinusOnePtr = &minusOne - InvalidInstancePtr = &invalidInstance InvalidValuePtr = &invalidValue WildCardSymbolPtr = &wildCardSymbol ParenthesisStartPtr = &parenthesisStart diff --git a/corecomparator/corecomparator.go b/corecomparator/corecomparator.go new file mode 100644 index 0000000000000000000000000000000000000000..7b70c012616f6fcdc2bcc4586275391addf1d16e --- /dev/null +++ b/corecomparator/corecomparator.go @@ -0,0 +1,61 @@ +package corecomparator + +type Compare byte + +var compares = []string{"Equal", "LeftGreater", "LeftGreaterEqual", "LeftLess", "LeftLessEqual"} + +const ( + Equal Compare = iota + LeftGreater + LeftGreaterEqual + LeftLess + LeftLessEqual +) + +func Min() Compare { + return Equal +} + +func Max() Compare { + return LeftLessEqual +} + +func (compare Compare) Is(other Compare) bool { + return compare == other +} + +func (compare Compare) IsEqual() bool { + return compare == Equal +} + +func (compare Compare) IsLeftGreater() bool { + return compare == LeftGreater +} + +func (compare Compare) IsLeftGreaterEqual() bool { + return compare == LeftGreaterEqual +} + +func (compare Compare) IsLeftLess() bool { + return compare == LeftLess +} + +func (compare Compare) IsLeftLessEqual() bool { + return compare == LeftLessEqual +} + +func (compare Compare) Value() byte { + return byte(compare) +} + +func (compare Compare) StringValue() string { + return string(compare) +} + +func (compare Compare) String() string { + return compares[compare] +} + +func (compare Compare) Ranges() []string { + return compares +} diff --git a/coremath/GetValue.go b/coremath/GetValue.go deleted file mode 100644 index ffbcfbe334e835f0fb85487d62d24c316f7aef0d..0000000000000000000000000000000000000000 --- a/coremath/GetValue.go +++ /dev/null @@ -1,9 +0,0 @@ -package coremath - -func GetValue(isTrue bool, value byte) byte { - if isTrue { - return value - } - - return 0 -} diff --git a/coremath/GetValueWithDefault.go b/coremath/GetValueWithDefault.go deleted file mode 100644 index 869f71d3dd729af938a29954b34cff8fdb4612df..0000000000000000000000000000000000000000 --- a/coremath/GetValueWithDefault.go +++ /dev/null @@ -1,9 +0,0 @@ -package coremath - -func GetValueWithDefault(isTrue bool, value, defaultVal byte) byte { - if isTrue { - return value - } - - return defaultVal -} diff --git a/coremath/MaxByte.go b/coremath/MaxByte.go new file mode 100644 index 0000000000000000000000000000000000000000..2bfc443fc758be5e5c60eb264b97ad94a6ed98e1 --- /dev/null +++ b/coremath/MaxByte.go @@ -0,0 +1,9 @@ +package coremath + +func MaxByte(v1, v2 byte) byte { + if v1 < v2 { + return v2 + } + + return v1 +} diff --git a/coremath/MaxFloat32.go b/coremath/MaxFloat32.go new file mode 100644 index 0000000000000000000000000000000000000000..30f25690d70448e1edb9a2b15fa23a0d7b4b0952 --- /dev/null +++ b/coremath/MaxFloat32.go @@ -0,0 +1,9 @@ +package coremath + +func MaxFloat32(v1, v2 float32) float32 { + if v1 < v2 { + return v2 + } + + return v1 +} diff --git a/coremath/MaxInt.go b/coremath/MaxInt.go new file mode 100644 index 0000000000000000000000000000000000000000..1270aed501c635655107fff7638d10172635093a --- /dev/null +++ b/coremath/MaxInt.go @@ -0,0 +1,9 @@ +package coremath + +func MaxInt(int1, int2 int) int { + if int1 < int2 { + return int2 + } + + return int1 +} diff --git a/coremath/MinByte.go b/coremath/MinByte.go new file mode 100644 index 0000000000000000000000000000000000000000..d5bc0976f57e17f28b79df09473efb7fc40b11a8 --- /dev/null +++ b/coremath/MinByte.go @@ -0,0 +1,9 @@ +package coremath + +func MinByte(v1, v2 byte) byte { + if v1 > v2 { + return v2 + } + + return v1 +} diff --git a/coremath/MinFloat32.go b/coremath/MinFloat32.go new file mode 100644 index 0000000000000000000000000000000000000000..cf3ae8a99ec4b264385d48aec04dca5b0ae8cfcf --- /dev/null +++ b/coremath/MinFloat32.go @@ -0,0 +1,9 @@ +package coremath + +func MinFloat32(v1, v2 float32) float32 { + if v1 > v2 { + return v2 + } + + return v1 +} diff --git a/coremath/MinInt.go b/coremath/MinInt.go new file mode 100644 index 0000000000000000000000000000000000000000..01d401e0eb87e15c367dc5716e90ed302e4bb5ff --- /dev/null +++ b/coremath/MinInt.go @@ -0,0 +1,9 @@ +package coremath + +func MinInt(int1, int2 int) int { + if int1 > int2 { + return int2 + } + + return int1 +} diff --git a/coretests/GetAssertMessage.go b/coretests/GetAssertMessage.go new file mode 100644 index 0000000000000000000000000000000000000000..983162900f24ad735b6a4cf96b7e94b12b6c294a --- /dev/null +++ b/coretests/GetAssertMessage.go @@ -0,0 +1,9 @@ +package coretests + +func GetAssertMessage(testCaseMessenger TestCaseMessenger, counter int) string { + return GetAssertMessageQuick( + testCaseMessenger.Value(), + testCaseMessenger.Actual(), + testCaseMessenger.Expected(), + counter) +} diff --git a/coretests/GetAssertMessageQuick.go b/coretests/GetAssertMessageQuick.go new file mode 100644 index 0000000000000000000000000000000000000000..1dcebf4bdb872a229382769f88b03cbd31dce3d2 --- /dev/null +++ b/coretests/GetAssertMessageQuick.go @@ -0,0 +1,17 @@ +package coretests + +import "fmt" + +func GetAssertMessageQuick( + when, + actual, + expected interface{}, + counter int, +) string { + return fmt.Sprintf("----------------------\n%d )\tWhen:%#v\n\t\tActual:%#v , Expected:%#v", + counter, + when, + actual, + expected, + ) +} diff --git a/coretests/GetTestHeader.go b/coretests/GetTestHeader.go new file mode 100644 index 0000000000000000000000000000000000000000..0ae4cefe09501829c51d8a35c0157572faccc2db --- /dev/null +++ b/coretests/GetTestHeader.go @@ -0,0 +1,11 @@ +package coretests + +import ( + "fmt" +) + +func GetTestHeader(testCaseMessenger TestCaseMessenger) string { + return fmt.Sprintf("Method : [%s]", + testCaseMessenger.FuncName(), + ) +} diff --git a/coretests/SkipOnUnix.go b/coretests/SkipOnUnix.go index e904d84de26551b7496f9d6cb2040747776e1828..f11a7e062d0538d29e4a0b6c37a1d11f455d1e77 100644 --- a/coretests/SkipOnUnix.go +++ b/coretests/SkipOnUnix.go @@ -9,7 +9,7 @@ import ( // Skip on Unix func SkipOnUnix(t *testing.T) { - if !osconsts.IsWindows { + if osconsts.IsUnixGroup { t.Skip(msgtype.UnixIgnoreMessage) } } diff --git a/coretests/TestCaseMessenger.go b/coretests/TestCaseMessenger.go new file mode 100644 index 0000000000000000000000000000000000000000..3ae68bc492111ee6b260f662c03f937f9cf4ae03 --- /dev/null +++ b/coretests/TestCaseMessenger.go @@ -0,0 +1,8 @@ +package coretests + +type TestCaseMessenger interface { + FuncName() string + Value() interface{} + Expected() interface{} + Actual() interface{} +} diff --git a/coretests/TestFuncName.go b/coretests/TestFuncName.go new file mode 100644 index 0000000000000000000000000000000000000000..bb5a47c8fc630785d659e5b48e6e22bb7e6ac8ef --- /dev/null +++ b/coretests/TestFuncName.go @@ -0,0 +1,7 @@ +package coretests + +type TestFuncName string + +func (funcName TestFuncName) Value() string { + return string(funcName) +} diff --git a/dtformats/consts.go b/dtformats/consts.go new file mode 100644 index 0000000000000000000000000000000000000000..c2bfdb8038886b9226cfcabf2ca068469162e736 --- /dev/null +++ b/dtformats/consts.go @@ -0,0 +1,67 @@ +package dtformats + +type Layout string + +const ( + ANSIC Layout = "Mon Jan _2 15:04:05 2006" + UnixDate Layout = "Mon Jan _2 15:04:05 MST 2006" + RubyDate Layout = "Mon Jan 02 15:04:05 -0700 2006" + RFC822 Layout = "02 Jan 06 15:04 MST" + RFC822Z Layout = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone + RFC850 Layout = "Monday, 02-Jan-06 15:04:05 MST" + RFC1123 Layout = "Mon, 02 Jan 2006 15:04:05 MST" + RFC1123Z Layout = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone + RFC3339 Layout = "2006-01-02T15:04:05Z07:00" + RFC3339Nano Layout = "2006-01-02T15:04:05.999999999Z07:00" + Kitchen Layout = "3:04PM" + // Handy time stamps. + Stamp Layout = "Jan _2 15:04:05" + StampMilli Layout = "Jan _2 15:04:05.000" + StampMicro Layout = "Jan _2 15:04:05.000000" + StampNano Layout = "Jan _2 15:04:05.000000000" +) + +func (layout Layout) Value() string { + return string(layout) +} + +func (layout Layout) Is(format string) bool { + return string(layout) == format +} + +func (layout Layout) IsTimeOnly() bool { + return layout == Kitchen +} + +func (layout Layout) IsTimeFocused() bool { + return layout == Stamp || + layout == StampMilli || + layout == StampMicro || + layout == Kitchen || + layout == StampNano +} + +func (layout Layout) IsDateTime() bool { + return layout == ANSIC || + layout == UnixDate || + layout == RubyDate || + layout == RFC822 || + layout == RFC822Z || + layout == RFC850 || + layout == RFC1123 || + layout == RFC1123Z || + layout == RFC3339 || + layout == RFC3339Nano +} + +func (layout Layout) HasTimeZone() bool { + return layout == UnixDate || + layout == RubyDate || + layout == RFC822 || + layout == RFC822Z || + layout == RFC850 || + layout == RFC1123 || + layout == RFC1123Z || + layout == RFC3339 || + layout == RFC3339Nano +} diff --git a/filemode/AttrVariant.go b/filemode/AttrVariant.go index fdf514ebcb9dded2c5a63fae0a67b8c4f768306a..97e352bafd43cdcd8170147966b1cbc051ad7aeb 100644 --- a/filemode/AttrVariant.go +++ b/filemode/AttrVariant.go @@ -9,6 +9,7 @@ package filemode // 7 - Read + Write + Execute all true type AttrVariant byte +//goland:noinspection ALL const ( Execute AttrVariant = 1 Write AttrVariant = 2 diff --git a/filemode/Attribute.go b/filemode/Attribute.go index 441b02bda9c318c0e587bb786c918634dc398da4..a1786a59f367a17aa2451c18f4e7c5fd69276956 100644 --- a/filemode/Attribute.go +++ b/filemode/Attribute.go @@ -1,8 +1,8 @@ package filemode import ( + "gitlab.com/evatix-go/core/conditional" "gitlab.com/evatix-go/core/constants" - "gitlab.com/evatix-go/core/coremath" ) type Attribute struct { @@ -23,17 +23,17 @@ func (attribute Attribute) ToAttributeValue() AttributeValue { } func (attribute Attribute) ToSpecificBytes() (read, write, exe, sum byte) { - read = coremath.GetValue(attribute.IsRead, ReadValue) - write = coremath.GetValue(attribute.IsWrite, WriteValue) - exe = coremath.GetValue(attribute.IsExecute, ExecuteValue) + read = conditional.Byte(attribute.IsRead, ReadValue, constants.Zero) + write = conditional.Byte(attribute.IsWrite, WriteValue, constants.Zero) + exe = conditional.Byte(attribute.IsExecute, ExecuteValue, constants.Zero) return read, write, exe, read + write + exe } func (attribute Attribute) ToByte() byte { - r := coremath.GetValue(attribute.IsRead, ReadValue) - w := coremath.GetValue(attribute.IsWrite, WriteValue) - e := coremath.GetValue(attribute.IsExecute, ExecuteValue) + r := conditional.Byte(attribute.IsRead, ReadValue, constants.Zero) + w := conditional.Byte(attribute.IsWrite, WriteValue, constants.Zero) + e := conditional.Byte(attribute.IsExecute, ExecuteValue, constants.Zero) return r + w + e } @@ -44,9 +44,9 @@ func (attribute Attribute) ToSum() byte { func (attribute Attribute) ToRwx() [3]byte { return [3]byte{ - coremath.GetValueWithDefault(attribute.IsRead, ReadChar, constants.HyphenChar), - coremath.GetValueWithDefault(attribute.IsWrite, WriteChar, constants.HyphenChar), - coremath.GetValueWithDefault(attribute.IsExecute, ExecuteChar, constants.HyphenChar), + conditional.Byte(attribute.IsRead, ReadChar, constants.HyphenChar), + conditional.Byte(attribute.IsWrite, WriteChar, constants.HyphenChar), + conditional.Byte(attribute.IsExecute, ExecuteChar, constants.HyphenChar), } } diff --git a/filemode/variant.go b/filemode/Variant.go similarity index 96% rename from filemode/variant.go rename to filemode/Variant.go index f9c860ddb1bc2530bc9ea87a7a166019ae94467d..cb6faa43723535116b891f5814d05bf1c1a3d73c 100644 --- a/filemode/variant.go +++ b/filemode/Variant.go @@ -2,6 +2,7 @@ package filemode type Variant string +//goland:noinspection ALL const ( AllRead Variant = "444" AllWrite Variant = "222" diff --git a/filemode/Wrapper.go b/filemode/Wrapper.go index 6b72160f17a6b539e063d72bbfb3a0a01767aa40..a9f4edb88b6fd2265e75029c25f0a5162c87ac6f 100644 --- a/filemode/Wrapper.go +++ b/filemode/Wrapper.go @@ -66,6 +66,7 @@ func (wrapper Wrapper) ToModeStr() string { return string(allBytes[1:]) } +// returns "-rwxrwxrwx" func (wrapper Wrapper) ToRwxes() string { owner := wrapper.Owner.ToRwxString() group := wrapper.Group.ToRwxString() diff --git a/filemode/attribute-constructors.go b/filemode/attribute-constructors.go index fee0edeef7a5a788e5e5c7fb0954ce2c7776506a..fab39afc5f3fd18f1f4e04f335eea6cc9696ab58 100644 --- a/filemode/attribute-constructors.go +++ b/filemode/attribute-constructors.go @@ -32,9 +32,9 @@ func NewAttributeUsingRwx(rwx string) Attribute { e := rwx[2] return Attribute{ - IsRead: r == 'r', - IsWrite: w == 'w', - IsExecute: e == 'x', + IsRead: r == ReadChar, + IsWrite: w == WriteChar, + IsExecute: e == ExecuteChar, } } diff --git a/filemode/consts.go b/filemode/constants.go similarity index 100% rename from filemode/consts.go rename to filemode/constants.go diff --git a/filemode/wrapper-constructors.go b/filemode/wrapper-constructors.go index e8fe541aee52d52cb9c7ebc9abeb741410554f0d..7edb143941f179fd684a42bb2f3d5763d79d77bf 100644 --- a/filemode/wrapper-constructors.go +++ b/filemode/wrapper-constructors.go @@ -110,7 +110,7 @@ func NewUsingRwxes(rwxrwxrwx string) (Wrapper, error) { LengthShouldBeEqualToMessage. Error("rwxrwxrwx length must be 9", length) - return Wrapper{},err + return Wrapper{}, err } owner := rwxrwxrwx[0:3] diff --git a/filemodes/modes.go b/filemodes/modes.go index d767bc5ed0590d6202b0509eccbd27cb77ce94fc..92f268487a134b3bd0097c442e8eaaaaa84f7e48 100644 --- a/filemodes/modes.go +++ b/filemodes/modes.go @@ -3,6 +3,7 @@ package filemodes import "os" // When used 0, golang treats it as octal not decimal anymore. +//goland:noinspection ALL const ( AllPermission os.FileMode = 0777 AllExecute os.FileMode = 0111 diff --git a/inttype/inttype.go b/inttype/inttype.go new file mode 100644 index 0000000000000000000000000000000000000000..9c6c4b843ac1cd75301c15be5913f2b7c89b62fe --- /dev/null +++ b/inttype/inttype.go @@ -0,0 +1,78 @@ +package inttype + +import ( + "gitlab.com/evatix-go/core/corecomparator" + "gitlab.com/evatix-go/core/msgtype" +) + +type Variant int + +func (v Variant) Value() int { + return int(v) +} + +func (v Variant) StringValue() string { + return string(v) +} + +// v + n +func (v Variant) Add(n int) Variant { + return Variant(v.Value() + n) +} + +// v - n +func (v Variant) Subtract(n int) Variant { + return Variant(v.Value() - n) +} + +func (v Variant) Is(n Variant) bool { + return v.Value() == n.Value() +} + +func (v Variant) IsEqual(n int) bool { + return v.Value() == n +} + +// v.Value() > n +func (v Variant) IsGreater(n int) bool { + return v.Value() > n +} + +// v.Value() >= n +func (v Variant) IsGreaterEqual(n int) bool { + return v.Value() >= n +} + +// v.Value() < n +func (v Variant) IsLess(n int) bool { + return v.Value() < n +} + +// v.Value() <= n +func (v Variant) IsLessEqual(n int) bool { + return v.Value() <= n +} + +// Here left is v, and right is `n` +func (v Variant) IsTrue(n int, compare corecomparator.Compare) bool { + switch compare { + case corecomparator.Equal: + return v.IsEqual(n) + case corecomparator.LeftGreater: + return v.IsGreater(n) + case corecomparator.LeftGreaterEqual: + return v.IsGreaterEqual(n) + case corecomparator.LeftLess: + return v.IsLess(n) + case corecomparator.LeftLessEqual: + return v.IsLessEqual(n) + default: + msg := msgtype.RangeNotMeet( + msgtype.ComparatorShouldBeWithinRanghe.String(), + corecomparator.Min(), + corecomparator.Max(), + compare.Ranges()) + + panic(msg) + } +} \ No newline at end of file diff --git a/msgtype/CombineWithMsgType.go b/msgtype/CombineWithMsgType.go new file mode 100644 index 0000000000000000000000000000000000000000..0cb1bdd61e43968dfdd3610e18f6c2a8bd38be37 --- /dev/null +++ b/msgtype/CombineWithMsgType.go @@ -0,0 +1,17 @@ +package msgtype + +import "gitlab.com/evatix-go/core/constants" + +func CombineWithMsgType( + genericMsg Variation, + otherMsg string, + reference interface{}, +) string { + return genericMsg.String() + + constants.Space + + otherMsg + + constants.Space + + ReferenceStart + + ToValueString(reference) + + ReferenceEnd +} diff --git a/msgtype/PanicRangeNotMeet.go b/msgtype/PanicRangeNotMeet.go new file mode 100644 index 0000000000000000000000000000000000000000..6575fa80afc4f9143215f4b5624fd9002d613823 --- /dev/null +++ b/msgtype/PanicRangeNotMeet.go @@ -0,0 +1,30 @@ +package msgtype + +import ( + "fmt" + + "gitlab.com/evatix-go/core/constants" +) + +func PanicRangeNotMeet( + otherMsg string, + rangeStart interface{}, + rangeEnd interface{}, + wholeRange interface{}, +) string { + rangeStr := "" + + if wholeRange == nil { + rangeStr = fmt.Sprintf(rangeWithOutRangeFormat, rangeStart, rangeEnd) + } else { + rangeStr = fmt.Sprintf(rangeWithRangeFormat, rangeStart, rangeEnd, wholeRange) + } + + return OutOfRange.String() + + constants.Space + + otherMsg + + constants.Space + + ReferenceStart + + rangeStr + + ReferenceEnd +} diff --git a/msgtype/RangeNotMeet.go b/msgtype/RangeNotMeet.go new file mode 100644 index 0000000000000000000000000000000000000000..79f318b071c342d23252144de73f36b80b7722d0 --- /dev/null +++ b/msgtype/RangeNotMeet.go @@ -0,0 +1,30 @@ +package msgtype + +import ( + "fmt" + + "gitlab.com/evatix-go/core/constants" +) + +func RangeNotMeet( + otherMsg string, + rangeStart interface{}, + rangeEnd interface{}, + wholeRange interface{}, +) string { + rangeStr := "" + + if wholeRange == nil { + rangeStr = fmt.Sprintf(rangeWithOutRangeFormat, rangeStart, rangeEnd) + } else { + rangeStr = fmt.Sprintf(rangeWithRangeFormat, rangeStart, rangeEnd, wholeRange) + } + + return OutOfRange.String() + + constants.Space + + otherMsg + + constants.Space + + ReferenceStart + + rangeStr + + ReferenceEnd +} diff --git a/msgtype/ToValueString.go b/msgtype/ToValueString.go new file mode 100644 index 0000000000000000000000000000000000000000..34ed19eb18ac63531d4b1b61d4f2734adfc45c01 --- /dev/null +++ b/msgtype/ToValueString.go @@ -0,0 +1,13 @@ +package msgtype + +import ( + "fmt" + + "gitlab.com/evatix-go/core/constants" +) + +func ToValueString(reference interface{}) string { + return fmt.Sprintf( + constants.SprintPropertyNameValueFormat, + reference) +} diff --git a/msgtype/Variation.go b/msgtype/Variation.go index 511c3b293a2b1e79a1fb76b926a551b3c35b714a..d5a9ae6152995a34a6b5fe07d80171d9a7f8626f 100644 --- a/msgtype/Variation.go +++ b/msgtype/Variation.go @@ -1,9 +1,13 @@ package msgtype -import "errors" +import ( + "errors" + "strings" +) type Variation string +//goland:noinspection ALL const ( InvalidRequest Variation = "Invalid : request, cannot process it." InvalidNullPointer Variation = "Invalid : null pointer, cannot process it." @@ -51,6 +55,7 @@ const ( ShouldBeGreaterThanEqualMessage Variation = "Values or value should be greater or equal to the reference." UnixIgnoreMessage Variation = "Windows tests ignored in Unix." WindowsIgnoreMessage Variation = "Unix tests ignored in Windows." + ComparatorShouldBeWithinRanghe Variation = "Comparator should be within the range." ) func (variation Variation) String() string { @@ -64,5 +69,11 @@ func (variation Variation) Combine(otherMsg string, reference interface{}) strin func (variation Variation) Error(otherMsg string, reference interface{}) error { msg := CombineWithMsgType(variation, otherMsg, reference) - return errors.New(msg) + return errors.New(strings.ToLower(msg)) +} + +func (variation Variation) HandleUsingPanic(otherMsg string, reference interface{}) { + msg := CombineWithMsgType(variation, otherMsg, reference) + + panic(msg) } diff --git a/msgtype/combine.go b/msgtype/combine.go index 9ef3b9db7b48d855862aa009a2c5ab32855cf68e..ab7528b4fd4328e22f615202e3c8819683bff7d6 100644 --- a/msgtype/combine.go +++ b/msgtype/combine.go @@ -1,31 +1,15 @@ package msgtype import ( - "fmt" - "gitlab.com/evatix-go/core/constants" ) func Combine(genericMsg, otherMsg, reference string) string { return genericMsg + - " " + + constants.Space + otherMsg + - " " + + constants.Space + ReferenceStart + reference + ReferenceEnd } - -func ToValueString(reference interface{}) string { - return fmt.Sprintf(constants.SprintPropertyNameValueFormat, reference) -} - -func CombineWithMsgType(genericMsg Variation, otherMsg string, reference interface{}) string { - return genericMsg.String() + - " " + - otherMsg + - " " + - ReferenceStart + - ToValueString(reference) + - ReferenceEnd -} diff --git a/msgtype/consts.go b/msgtype/consts.go index f514919e13d53d94c1c1c33ced397ac457dbeaf4..da094dc49fb446618b2b8a0d0e590ade097e2985 100644 --- a/msgtype/consts.go +++ b/msgtype/consts.go @@ -1,6 +1,8 @@ package msgtype const ( - ReferenceStart = " Reference ( " - ReferenceEnd = " )" + ReferenceStart = " Reference ( " + ReferenceEnd = " )" + rangeWithRangeFormat = "Range must be in between %+v and %+v. Range {%#v}" + rangeWithOutRangeFormat = "Range must be in between %+v and %+v." ) diff --git a/osarchs/archs.go b/osarchs/Architecture.go similarity index 100% rename from osarchs/archs.go rename to osarchs/Architecture.go diff --git a/osconsts/arrayvars.go b/osconsts/arrayvars.go index 7bcac115c4e31531e70770e8406235b24486ec60..b628a0e4ad9f6870ca880f5020b06f965682d455 100644 --- a/osconsts/arrayvars.go +++ b/osconsts/arrayvars.go @@ -1,5 +1,6 @@ package osconsts +//goland:noinspection ALL var ( X32Architectures = []string{ "386", diff --git a/osconsts/constants.go b/osconsts/constants.go index 9686cbb04959487793291f45d095d2cb8e427329..f437a727859539fb80882a96ab618d9d25145950 100644 --- a/osconsts/constants.go +++ b/osconsts/constants.go @@ -31,4 +31,5 @@ const ( IsLinux = CurrentOperatingSystem == Linux IsDarwinOrMacOs = CurrentOperatingSystem == DarwinOrMacOs IsUbuntu = CurrentOperatingSystem == Ubuntu + IsUnixGroup = !IsWindows ) diff --git a/regconsts/regconsts.go b/regconsts/regconsts.go index 9fd14e2f48d5fd744570253c15d044d22276832a..4dd2a9da5d08a36441bee6f253f42d406a27eafd 100644 --- a/regconsts/regconsts.go +++ b/regconsts/regconsts.go @@ -1,5 +1,6 @@ package regconsts +//goland:noinspection ALL const ( RegExForEachWordsWithDollarSymbol = "\\$(\\w+)(\\d*)" // Selects a full word that starts with a "$" symbol EachWordsWithinPercentSymbol = "\\%(\\w+)(\\d*)%" // Selects a full word that is within two "%" symbol diff --git a/strtype/strtype.go b/strtype/strtype.go new file mode 100644 index 0000000000000000000000000000000000000000..f4c64a28e78a0404cce780f3dc7725c79ae52b93 --- /dev/null +++ b/strtype/strtype.go @@ -0,0 +1,73 @@ +package strtype + +import ( + "gitlab.com/evatix-go/core/corecomparator" + "gitlab.com/evatix-go/core/msgtype" +) + +type Variant string + +func (v Variant) Value() string { + return string(v) +} + +func (v Variant) StringValue() string { + return string(v) +} + +// v + n +func (v Variant) Add(n string) Variant { + return Variant(v.Value() + n) +} + +func (v Variant) Is(n Variant) bool { + return v.Value() == n.Value() +} + +func (v Variant) IsEqual(n string) bool { + return v.Value() == n +} + +// v.Value() > n +func (v Variant) IsGreater(n string) bool { + return v.Value() > n +} + +// v.Value() >= n +func (v Variant) IsGreaterEqual(n string) bool { + return v.Value() >= n +} + +// v.Value() < n +func (v Variant) IsLess(n string) bool { + return v.Value() < n +} + +// v.Value() <= n +func (v Variant) IsLessEqual(n string) bool { + return v.Value() <= n +} + +// Here left is v, and right is `n` +func (v Variant) IsTrue(n string, compare corecomparator.Compare) bool { + switch compare { + case corecomparator.Equal: + return v.IsEqual(n) + case corecomparator.LeftGreater: + return v.IsGreater(n) + case corecomparator.LeftGreaterEqual: + return v.IsGreaterEqual(n) + case corecomparator.LeftLess: + return v.IsLess(n) + case corecomparator.LeftLessEqual: + return v.IsLessEqual(n) + default: + msg := msgtype.RangeNotMeet( + msgtype.ComparatorShouldBeWithinRanghe.String(), + corecomparator.Min(), + corecomparator.Max(), + compare.Ranges()) + + panic(msg) + } +}