diff --git a/.chloggen/ottl-hide-consts.yaml b/.chloggen/ottl-hide-consts.yaml new file mode 100755 index 000000000000..533d916be3f3 --- /dev/null +++ b/.chloggen/ottl-hide-consts.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/ottl + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Unexport `ADD`, `SUB`, `MULT`, `DIV`, `EQ`, `NE`, `LT`, `LTE`, `GT`, and `GTE` + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [29925] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/pkg/ottl/boolean_value_test.go b/pkg/ottl/boolean_value_test.go index 757db6eae8fc..ad42555e192f 100644 --- a/pkg/ottl/boolean_value_test.go +++ b/pkg/ottl/boolean_value_test.go @@ -38,7 +38,7 @@ func valueFor(x any) value { } case strings.Contains(v, "ENUM"): // if the string contains ENUM construct an EnumSymbol from it. - val.Enum = (*EnumSymbol)(ottltest.Strp(v)) + val.Enum = (*enumSymbol)(ottltest.Strp(v)) case v == "dur1" || v == "dur2": val.Literal = &mathExprLiteral{ Path: &path{ @@ -198,9 +198,9 @@ func Test_newConditionEvaluator_invalid(t *testing.T) { name: "unknown path", comparison: &comparison{ Left: value{ - Enum: (*EnumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), + Enum: (*enumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("trash"), }, @@ -488,7 +488,7 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) { Left: value{ String: ottltest.Strp("test"), }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("not test"), }, diff --git a/pkg/ottl/compare.go b/pkg/ottl/compare.go index fc93186c4985..50d1109f00ca 100644 --- a/pkg/ottl/compare.go +++ b/pkg/ottl/compare.go @@ -15,29 +15,29 @@ import ( // values of type any, which for the purposes of OTTL mean values that are one of // int, float, string, bool, or pointers to those, or []byte, or nil. -// invalidComparison returns false for everything except NE (where it returns true to indicate that the +// invalidComparison returns false for everything except ne (where it returns true to indicate that the // objects were definitely not equivalent). // It also gives us an opportunity to log something. func (p *Parser[K]) invalidComparison(msg string, op compareOp) bool { p.telemetrySettings.Logger.Debug(msg, zap.Any("op", op)) - return op == NE + return op == ne } // comparePrimitives implements a generic comparison helper for all Ordered types (derived from Float, Int, or string). // According to benchmarks, it's faster than explicit comparison functions for these types. func comparePrimitives[T constraints.Ordered](a T, b T, op compareOp) bool { switch op { - case EQ: + case eq: return a == b - case NE: + case ne: return a != b - case LT: + case lt: return a < b - case LTE: + case lte: return a <= b - case GTE: + case gte: return a >= b - case GT: + case gt: return a > b default: return false @@ -46,17 +46,17 @@ func comparePrimitives[T constraints.Ordered](a T, b T, op compareOp) bool { func compareBools(a bool, b bool, op compareOp) bool { switch op { - case EQ: + case eq: return a == b - case NE: + case ne: return a != b - case LT: + case lt: return !a && b - case LTE: + case lte: return !a || b - case GTE: + case gte: return a || !b - case GT: + case gt: return a && !b default: return false @@ -65,17 +65,17 @@ func compareBools(a bool, b bool, op compareOp) bool { func compareBytes(a []byte, b []byte, op compareOp) bool { switch op { - case EQ: + case eq: return bytes.Equal(a, b) - case NE: + case ne: return !bytes.Equal(a, b) - case LT: + case lt: return bytes.Compare(a, b) < 0 - case LTE: + case lte: return bytes.Compare(a, b) <= 0 - case GTE: + case gte: return bytes.Compare(a, b) >= 0 - case GT: + case gt: return bytes.Compare(a, b) > 0 default: return false @@ -103,10 +103,10 @@ func (p *Parser[K]) compareString(a string, b any, op compareOp) bool { func (p *Parser[K]) compareByte(a []byte, b any, op compareOp) bool { switch v := b.(type) { case nil: - return op == NE + return op == ne case []byte: if v == nil { - return op == NE + return op == ne } return compareBytes(a, v, op) default: @@ -151,17 +151,17 @@ func (p *Parser[K]) compareTime(a time.Time, b any, op compareOp) bool { switch v := b.(type) { case time.Time: switch op { - case EQ: + case eq: return a.Equal(v) - case NE: + case ne: return !a.Equal(v) - case LT: + case lt: return a.Before(v) - case LTE: + case lte: return a.Before(v) || a.Equal(v) - case GTE: + case gte: return a.After(v) || a.Equal(v) - case GT: + case gt: return a.After(v) default: return p.invalidComparison("invalid comparison operator", op) @@ -177,7 +177,7 @@ func (p *Parser[K]) compare(a any, b any, op compareOp) bool { // nils are equal to each other and never equal to anything else, // so if they're both nil, report equality. if a == nil && b == nil { - return op == EQ || op == LTE || op == GTE + return op == eq || op == lte || op == gte } // Anything else, we switch on the left side first. switch v := a.(type) { @@ -206,9 +206,9 @@ func (p *Parser[K]) compare(a any, b any, op compareOp) bool { // If we don't know what type it is, we can't do inequalities yet. So we can fall back to the old behavior where we just // use Go's standard equality. switch op { - case EQ: + case eq: return a == b - case NE: + case ne: return a != b default: return p.invalidComparison("unsupported type for inequality on left", op) diff --git a/pkg/ottl/compare_test.go b/pkg/ottl/compare_test.go index b2dffba38a4f..e051ececb739 100644 --- a/pkg/ottl/compare_test.go +++ b/pkg/ottl/compare_test.go @@ -45,7 +45,7 @@ func Test_compare(t *testing.T) { name string a any b any - want []bool // in order of EQ, NE, LT, LTE, GTE, GT. + want []bool // in order of eq, ne, lt, lte, gte, gt. }{ {"identity string", sa, sa, []bool{true, false, false, true, true, false}}, {"identity int64", i64a, i64a, []bool{true, false, false, true, true, false}}, @@ -101,7 +101,7 @@ func Test_compare(t *testing.T) { {"non-prim, int type", testA{"hi"}, 5, []bool{false, true, false, false, false, false}}, {"int, non-prim", 5, testA{"hi"}, []bool{false, true, false, false, false, false}}, } - ops := []compareOp{EQ, NE, LT, LTE, GTE, GT} + ops := []compareOp{eq, ne, lt, lte, gte, gt} for _, tt := range tests { for _, op := range ops { t.Run(fmt.Sprintf("%s %v", tt.name, op), func(t *testing.T) { @@ -123,7 +123,7 @@ func BenchmarkCompareEQInt64(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(i64a, i64b, EQ) + testParser.compare(i64a, i64b, eq) } } @@ -132,7 +132,7 @@ func BenchmarkCompareEQFloat(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(f64a, f64b, EQ) + testParser.compare(f64a, f64b, eq) } } @@ -141,7 +141,7 @@ func BenchmarkCompareEQString(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(sa, sb, EQ) + testParser.compare(sa, sb, eq) } } @@ -150,7 +150,7 @@ func BenchmarkCompareEQPString(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(&sa, &sb, EQ) + testParser.compare(&sa, &sb, eq) } } @@ -159,7 +159,7 @@ func BenchmarkCompareEQBytes(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(ba, bb, EQ) + testParser.compare(ba, bb, eq) } } @@ -168,7 +168,7 @@ func BenchmarkCompareEQNil(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(nil, nil, EQ) + testParser.compare(nil, nil, eq) } } @@ -177,7 +177,7 @@ func BenchmarkCompareNEInt(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(i64a, i64b, NE) + testParser.compare(i64a, i64b, ne) } } @@ -186,7 +186,7 @@ func BenchmarkCompareNEFloat(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(f64a, f64b, NE) + testParser.compare(f64a, f64b, ne) } } @@ -195,7 +195,7 @@ func BenchmarkCompareNEString(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(sa, sb, NE) + testParser.compare(sa, sb, ne) } } @@ -204,7 +204,7 @@ func BenchmarkCompareLTFloat(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(f64a, f64b, LT) + testParser.compare(f64a, f64b, lt) } } @@ -213,7 +213,7 @@ func BenchmarkCompareLTString(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(sa, sb, LT) + testParser.compare(sa, sb, lt) } } @@ -222,17 +222,17 @@ func BenchmarkCompareLTNil(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - testParser.compare(nil, nil, LT) + testParser.compare(nil, nil, lt) } } // this is only used for benchmarking, and is a rough equivalent of the original compare function -// before adding LT, LTE, GTE, and GT. +// before adding lt, lte, gte, and gt. func compareEq(a any, b any, op compareOp) bool { switch op { - case EQ: + case eq: return a == b - case NE: + case ne: return a != b default: return false @@ -241,6 +241,6 @@ func compareEq(a any, b any, op compareOp) bool { func BenchmarkCompareEQFunction(b *testing.B) { for i := 0; i < b.N; i++ { - compareEq(sa, sb, EQ) + compareEq(sa, sb, eq) } } diff --git a/pkg/ottl/expression.go b/pkg/ottl/expression.go index 863fe1c0e6c7..770c055e7630 100644 --- a/pkg/ottl/expression.go +++ b/pkg/ottl/expression.go @@ -616,7 +616,7 @@ func (p *Parser[K]) newGetter(val value) (Getter[K], error) { } if val.Enum != nil { - enum, err := p.enumParser(val.Enum) + enum, err := p.enumParser((*EnumSymbol)(val.Enum)) if err != nil { return nil, err } diff --git a/pkg/ottl/expression_test.go b/pkg/ottl/expression_test.go index 1b33b4ed9f9c..4e18958d3822 100644 --- a/pkg/ottl/expression_test.go +++ b/pkg/ottl/expression_test.go @@ -240,7 +240,7 @@ func Test_newGetter(t *testing.T) { { name: "enum", val: value{ - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM_ONE")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM_ONE")), }, want: int64(1), }, diff --git a/pkg/ottl/functions.go b/pkg/ottl/functions.go index 7a1fc1e89a3e..801a80289ad1 100644 --- a/pkg/ottl/functions.go +++ b/pkg/ottl/functions.go @@ -19,6 +19,8 @@ type EnumParser func(*EnumSymbol) (*Enum, error) type Enum int64 +type EnumSymbol string + func newPath[K any](fields []field) Path[K] { if len(fields) == 0 { return nil @@ -430,7 +432,7 @@ func (p *Parser[K]) buildArg(argVal value, argType reflect.Type) (any, error) { } return StandardTimeGetter[K]{Getter: arg.Get}, nil case name == "Enum": - arg, err := p.enumParser(argVal.Enum) + arg, err := p.enumParser((*EnumSymbol)(argVal.Enum)) if err != nil { return nil, fmt.Errorf("must be an Enum") } diff --git a/pkg/ottl/functions_test.go b/pkg/ottl/functions_test.go index b886748f3578..3e88e6555f23 100644 --- a/pkg/ottl/functions_test.go +++ b/pkg/ottl/functions_test.go @@ -368,7 +368,7 @@ func Test_NewFunctionCall_invalid(t *testing.T) { Arguments: []argument{ { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), + Enum: (*enumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), }, }, }, @@ -568,7 +568,7 @@ func Test_NewFunctionCall(t *testing.T) { Bool: (*boolean)(ottltest.Boolp(true)), }, { - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM")), }, { List: &list{ @@ -1384,7 +1384,7 @@ func Test_NewFunctionCall(t *testing.T) { Arguments: []argument{ { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM")), }, }, }, diff --git a/pkg/ottl/grammar.go b/pkg/ottl/grammar.go index 0cd63ae7feb9..cbcfdf39256c 100644 --- a/pkg/ottl/grammar.go +++ b/pkg/ottl/grammar.go @@ -123,22 +123,22 @@ type compareOp int // These are the allowed values of a compareOp const ( - EQ compareOp = iota - NE - LT - LTE - GTE - GT + eq compareOp = iota + ne + lt + lte + gte + gt ) // a fast way to get from a string to a compareOp var compareOpTable = map[string]compareOp{ - "==": EQ, - "!=": NE, - "<": LT, - "<=": LTE, - ">": GT, - ">=": GTE, + "==": eq, + "!=": ne, + "<": lt, + "<=": lte, + ">": gt, + ">=": gte, } // Capture is how the parser converts an operator string to a compareOp. @@ -154,18 +154,18 @@ func (c *compareOp) Capture(values []string) error { // String() for compareOp gives us more legible test results and error messages. func (c *compareOp) String() string { switch *c { - case EQ: - return "EQ" - case NE: - return "NE" - case LT: - return "LT" - case LTE: - return "LTE" - case GTE: - return "GTE" - case GT: - return "GT" + case eq: + return "eq" + case ne: + return "ne" + case lt: + return "lt" + case lte: + return "lte" + case gte: + return "gte" + case gt: + return "gt" default: return "UNKNOWN OP!" } @@ -235,7 +235,7 @@ type value struct { Bytes *byteSlice `parser:"| @Bytes"` String *string `parser:"| @String"` Bool *boolean `parser:"| @Boolean"` - Enum *EnumSymbol `parser:"| @Uppercase (?! Lowercase)"` + Enum *enumSymbol `parser:"| @Uppercase (?! Lowercase)"` FunctionName *string `parser:"| @(Uppercase(Uppercase | Lowercase)*)"` List *list `parser:"| @@)"` } @@ -386,17 +386,17 @@ func (m *mathExpression) checkForCustomError() error { type mathOp int const ( - ADD mathOp = iota - SUB - MULT - DIV + add mathOp = iota + sub + mult + div ) var mathOpTable = map[string]mathOp{ - "+": ADD, - "-": SUB, - "*": MULT, - "/": DIV, + "+": add, + "-": sub, + "*": mult, + "/": div, } func (m *mathOp) Capture(values []string) error { @@ -410,20 +410,20 @@ func (m *mathOp) Capture(values []string) error { func (m *mathOp) String() string { switch *m { - case ADD: + case add: return "+" - case SUB: + case sub: return "-" - case MULT: + case mult: return "*" - case DIV: + case div: return "/" default: return "UNKNOWN OP!" } } -type EnumSymbol string +type enumSymbol string // buildLexer constructs a SimpleLexer definition. // Note that the ordering of these rules matters. diff --git a/pkg/ottl/math.go b/pkg/ottl/math.go index eae661e639ef..9c9dd3dc18d6 100644 --- a/pkg/ottl/math.go +++ b/pkg/ottl/math.go @@ -113,7 +113,7 @@ func attemptMathOperation[K any](lhs Getter[K], op mathOp, rhs Getter[K]) Getter func performOpTime(x time.Time, y any, op mathOp) (any, error) { switch op { - case ADD: + case add: switch newY := y.(type) { case time.Duration: result := x.Add(newY) @@ -121,7 +121,7 @@ func performOpTime(x time.Time, y any, op mathOp) (any, error) { default: return nil, fmt.Errorf("time.Time must be added to time.Duration; found %v instead", y) } - case SUB: + case sub: switch newY := y.(type) { case time.Time: result := x.Sub(newY) @@ -138,7 +138,7 @@ func performOpTime(x time.Time, y any, op mathOp) (any, error) { func performOpDuration(x time.Duration, y any, op mathOp) (any, error) { switch op { - case ADD: + case add: switch newY := y.(type) { case time.Duration: result := x + newY @@ -149,7 +149,7 @@ func performOpDuration(x time.Duration, y any, op mathOp) (any, error) { default: return nil, fmt.Errorf("time.Duration must be added to time.Duration or time.Time; found %v instead", y) } - case SUB: + case sub: switch newY := y.(type) { case time.Duration: result := x - newY @@ -163,13 +163,13 @@ func performOpDuration(x time.Duration, y any, op mathOp) (any, error) { func performOp[N int64 | float64](x N, y N, op mathOp) (N, error) { switch op { - case ADD: + case add: return x + y, nil - case SUB: + case sub: return x - y, nil - case MULT: + case mult: return x * y, nil - case DIV: + case div: if y == 0 { return 0, fmt.Errorf("attempted to divide by 0") } diff --git a/pkg/ottl/math_test.go b/pkg/ottl/math_test.go index bdc04094ec98..3fc73ca10c7e 100644 --- a/pkg/ottl/math_test.go +++ b/pkg/ottl/math_test.go @@ -269,7 +269,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { input: "1 / 0", }, { - name: "time DIV time", + name: "time div time", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -294,7 +294,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: DIV, + Operator: div, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -322,7 +322,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { errorMsg: "only addition and subtraction supported", }, { - name: "dur MULT dur", + name: "dur mult dur", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -342,7 +342,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: MULT, + Operator: mult, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -365,7 +365,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { errorMsg: "only addition and subtraction supported", }, { - name: "time ADD int", + name: "time add int", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -390,7 +390,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -404,7 +404,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { errorMsg: "time.Time must be added to time.Duration", }, { - name: "dur SUB int", + name: "dur sub int", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -424,7 +424,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -438,7 +438,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { errorMsg: "time.Duration must be subtracted from time.Duration", }, { - name: "time ADD time", + name: "time add time", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -463,7 +463,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -491,7 +491,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { errorMsg: "time.Time must be added to time.Duration", }, { - name: "dur SUB time", + name: "dur sub time", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -511,7 +511,7 @@ func Test_evaluateMathExpression_error(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -629,7 +629,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected any }{ { - name: "time SUB time, no difference", + name: "time sub time, no difference", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -654,7 +654,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -682,7 +682,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: zeroSecs, }, { - name: "time SUB time", + name: "time sub time", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -707,7 +707,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -735,7 +735,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: -fourtySevenHourseFourtyTwoMinutesTwentySevenSecs, }, { - name: "dur ADD time", + name: "dur add time", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -755,7 +755,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -783,7 +783,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: time.Date(2000, 1, 1, 10, 0, 0, 0, time.Local), }, { - name: "time ADD dur", + name: "time add dur", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -808,7 +808,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -831,7 +831,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: time.Date(2023, 2, 15, 10, 0, 0, 0, time.Local), }, { - name: "time ADD dur, complex dur", + name: "time add dur, complex dur", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -856,7 +856,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -879,7 +879,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: time.Date(2023, 2, 4, 1, 2, 3, 0, time.Local), }, { - name: "time SUB dur, complex dur", + name: "time sub dur, complex dur", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -904,7 +904,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -927,7 +927,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: time.Date(2023, 3, 14, 6, 0, 1, 0, time.Local), }, { - name: "time SUB dur, nanosecs", + name: "time sub dur, nanosecs", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -952,7 +952,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -975,7 +975,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: time.Date(2023, 4, 30, 23, 59, 59, 999999900, time.Local), }, { - name: "dur ADD dur, complex durs", + name: "dur add dur, complex durs", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -995,7 +995,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -1018,7 +1018,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: oneHundredOne, }, { - name: "dur ADD dur, zero dur", + name: "dur add dur, zero dur", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -1038,7 +1038,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -1061,7 +1061,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: oneThousandHours, }, { - name: "dur SUB dur, zero dur", + name: "dur sub dur, zero dur", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -1081,7 +1081,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -1104,7 +1104,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { expected: -threeTwentyEightMins, }, { - name: "dur SUB dur, complex durs", + name: "dur sub dur, complex durs", mathExpr: &mathExpression{ Left: &addSubTerm{ Left: &mathValue{ @@ -1124,7 +1124,7 @@ func Test_evaluateMathExpressionTimeDuration(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ diff --git a/pkg/ottl/parser_test.go b/pkg/ottl/parser_test.go index 56c26a2c0abc..fa09f3253077 100644 --- a/pkg/ottl/parser_test.go +++ b/pkg/ottl/parser_test.go @@ -219,7 +219,7 @@ func Test_parse(t *testing.T) { }, { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("SHA256")), + Enum: (*enumSymbol)(ottltest.Strp("SHA256")), }, }, }, @@ -289,7 +289,7 @@ func Test_parse(t *testing.T) { }, { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("S")), + Enum: (*enumSymbol)(ottltest.Strp("S")), }, }, }, @@ -406,7 +406,7 @@ func Test_parse(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("fido"), }, @@ -469,7 +469,7 @@ func Test_parse(t *testing.T) { }, }, }, - Op: NE, + Op: ne, Right: value{ String: ottltest.Strp("fido"), }, @@ -532,7 +532,7 @@ func Test_parse(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("fido"), }, @@ -700,7 +700,7 @@ func Test_parse(t *testing.T) { }, { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM")), }, }, }, @@ -971,7 +971,7 @@ func Test_parse(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: SUB, + Operator: sub, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -1001,7 +1001,7 @@ func Test_parse(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -1010,7 +1010,7 @@ func Test_parse(t *testing.T) { }, Right: []*opMultDivValue{ { - Operator: MULT, + Operator: mult, Value: &mathValue{ Literal: &mathExprLiteral{ Int: ottltest.Intp(2), @@ -1023,7 +1023,7 @@ func Test_parse(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ MathExpression: &mathExpression{ Left: &addSubTerm{ @@ -1040,7 +1040,7 @@ func Test_parse(t *testing.T) { }, Right: []*opMultDivValue{ { - Operator: DIV, + Operator: div, Value: &mathValue{ Literal: &mathExprLiteral{ Converter: &converter{ @@ -1112,7 +1112,7 @@ func Test_parseCondition_full(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("fido"), }, @@ -1139,7 +1139,7 @@ func Test_parseCondition_full(t *testing.T) { }, }, }, - Op: NE, + Op: ne, Right: value{ String: ottltest.Strp("fido"), }, @@ -1166,7 +1166,7 @@ func Test_parseCondition_full(t *testing.T) { }, Right: []*opAddSubTerm{ { - Operator: ADD, + Operator: add, Term: &addSubTerm{ Left: &mathValue{ Literal: &mathExprLiteral{ @@ -1175,7 +1175,7 @@ func Test_parseCondition_full(t *testing.T) { }, Right: []*opMultDivValue{ { - Operator: MULT, + Operator: mult, Value: &mathValue{ Literal: &mathExprLiteral{ Int: ottltest.Intp(2), @@ -1188,7 +1188,7 @@ func Test_parseCondition_full(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ MathExpression: &mathExpression{ Left: &addSubTerm{ @@ -1205,7 +1205,7 @@ func Test_parseCondition_full(t *testing.T) { }, Right: []*opMultDivValue{ { - Operator: DIV, + Operator: div, Value: &mathValue{ Literal: &mathExprLiteral{ Converter: &converter{ @@ -1534,7 +1534,7 @@ func Test_parseWhere(t *testing.T) { }, }, }, - Op: NE, + Op: ne, Right: value{ String: ottltest.Strp("foo"), }, @@ -1556,7 +1556,7 @@ func Test_parseWhere(t *testing.T) { }, }, }, - Op: NE, + Op: ne, Right: value{ String: ottltest.Strp("bar"), }, @@ -1584,7 +1584,7 @@ func Test_parseWhere(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("foo"), }, @@ -1608,7 +1608,7 @@ func Test_parseWhere(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("bar"), }, @@ -1660,7 +1660,7 @@ func Test_parseWhere(t *testing.T) { }, }, }, - Op: EQ, + Op: eq, Right: value{ String: ottltest.Strp("bar"), },