summaryrefslogtreecommitdiff
path: root/internal/rpn
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 18:50:00 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 18:50:00 +0300
commitdc89fa2bbcdea7c8847828f64be5e46ddded33fb (patch)
tree67dd57478d39d9e75ccfcb576f5651bf53896379 /internal/rpn
parent4188db97bcb771c1c8790ddbac2db3f9ee8884c3 (diff)
fix(rpn): change variadic NewRPN/NewOperations to single optional MetricReader (task ok)
Diffstat (limited to 'internal/rpn')
-rw-r--r--internal/rpn/assignment_test.go52
-rw-r--r--internal/rpn/boolean_test.go8
-rw-r--r--internal/rpn/compare_metric_test.go8
-rw-r--r--internal/rpn/constants_test.go26
-rw-r--r--internal/rpn/custom_metric_test.go24
-rw-r--r--internal/rpn/metric_test.go18
-rw-r--r--internal/rpn/operations.go6
-rw-r--r--internal/rpn/operations_fastpower_test.go2
-rw-r--r--internal/rpn/operations_hyper_test.go6
-rw-r--r--internal/rpn/operations_metric_cmd_test.go50
-rw-r--r--internal/rpn/operations_stack_test.go20
-rw-r--r--internal/rpn/operations_test.go96
-rw-r--r--internal/rpn/rpn_state.go4
-rw-r--r--internal/rpn/rpn_state_test.go16
-rw-r--r--internal/rpn/rpn_test.go62
15 files changed, 199 insertions, 199 deletions
diff --git a/internal/rpn/assignment_test.go b/internal/rpn/assignment_test.go
index 82d4a12..f9f4a3e 100644
--- a/internal/rpn/assignment_test.go
+++ b/internal/rpn/assignment_test.go
@@ -11,7 +11,7 @@ import (
// TestAssignmentStandard tests standard assignment 'x 5 ='
func TestAssignmentStandard(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("x 5 =")
if err != nil {
@@ -33,7 +33,7 @@ func TestAssignmentStandard(t *testing.T) {
// TestAssignmentRight tests right assignment '5 x :='
func TestAssignmentRight(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("5 x :=")
if err != nil {
@@ -55,7 +55,7 @@ func TestAssignmentRight(t *testing.T) {
// TestAssignmentLeft tests left assignment '5 x =:'
func TestAssignmentLeft(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("5 x =:")
if err != nil {
@@ -77,7 +77,7 @@ func TestAssignmentLeft(t *testing.T) {
// TestAssignmentReassignment tests variable reassignment
func TestAssignmentReassignment(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("x 5 =")
if err != nil {
@@ -104,7 +104,7 @@ func TestAssignmentReassignment(t *testing.T) {
// TestAssignmentInExpression tests assignment used in an expression
func TestAssignmentInExpression(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// 'x 5 = x 2 +' should assign x=5, then push x and 2, then add: 5 + 2 = 7
result, err := rpn.ParseAndEvaluate("x 5 = x 2 +")
@@ -119,7 +119,7 @@ func TestAssignmentInExpression(t *testing.T) {
// TestAssignmentMultipleVariables tests multiple variable assignments
func TestAssignmentMultipleVariables(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, _ = rpn.ParseAndEvaluate("x 5 =")
_, _ = rpn.ParseAndEvaluate("y 10 =")
@@ -146,7 +146,7 @@ func TestAssignmentMultipleVariables(t *testing.T) {
// TestAssignmentArithmeticWithVariable tests arithmetic using assigned variable
func TestAssignmentArithmeticWithVariable(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, _ = rpn.ParseAndEvaluate("x 5 =")
@@ -163,7 +163,7 @@ func TestAssignmentArithmeticWithVariable(t *testing.T) {
// TestAssignmentNegativeValue tests assignment with negative value
func TestAssignmentNegativeValue(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("x -5 =")
if err != nil {
@@ -182,7 +182,7 @@ func TestAssignmentNegativeValue(t *testing.T) {
// TestAssignmentDecimalValue tests assignment with decimal value
func TestAssignmentDecimalValue(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("x 3.14 =")
if err != nil {
@@ -201,7 +201,7 @@ func TestAssignmentDecimalValue(t *testing.T) {
// TestAssignmentUnderscoreVariable tests assignment with underscore variable
func TestAssignmentUnderscoreVariable(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("my_var 42 =")
if err != nil {
@@ -220,7 +220,7 @@ func TestAssignmentUnderscoreVariable(t *testing.T) {
// TestAssignmentWithCalculationResult tests assigning result of calculation
func TestAssignmentWithCalculationResult(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// 3 4 + x =: should push 3, 4, add (=7), then assign 7 to x
_, err := rpn.ParseAndEvaluate("3 4 + x =:")
@@ -240,7 +240,7 @@ func TestAssignmentWithCalculationResult(t *testing.T) {
// TestAssignmentAllOperatorsInSequence tests all three assignment operators
func TestAssignmentAllOperatorsInSequence(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, _ = rpn.ParseAndEvaluate("a 1 =") // standard
_, _ = rpn.ParseAndEvaluate("2 b :=") // right
@@ -260,7 +260,7 @@ func TestAssignmentAllOperatorsInSequence(t *testing.T) {
// TestAssignmentOperatorRegistry verifies all assignment operators are registered
func TestAssignmentOperatorRegistry(t *testing.T) {
vars := NewVariables()
- ops := NewOperations(vars)
+ ops := NewOperations(vars, nil)
reg := NewOperatorRegistry(ops)
// Verify assignment operators are registered as standard operators
@@ -278,7 +278,7 @@ func TestAssignmentOperatorRegistry(t *testing.T) {
// TestAssignmentNotTriggeredByEqualEqual ensures that == is not misparsed as an assignment.
func TestAssignmentNotTriggeredByEqualEqual(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// "a == b" should NOT be treated as an assignment
_, err := rpn.ParseAndEvaluate("a == b")
@@ -297,7 +297,7 @@ func TestAssignmentNotTriggeredByEqualEqual(t *testing.T) {
// TestAssignmentNotTriggeredByNotEqual ensures that != is not misparsed as an assignment.
func TestAssignmentNotTriggeredByNotEqual(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// "a != b" should NOT be treated as an assignment
_, err := rpn.ParseAndEvaluate("a != b")
@@ -311,7 +311,7 @@ func TestAssignmentNotTriggeredByNotEqual(t *testing.T) {
// TestAssignmentAfterEqualEqual ensures "x 5 =" still works even when == exists in the expression.
func TestAssignmentAfterEqualEqual(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// A standalone assignment should work regardless of == elsewhere
result, err := rpn.ParseAndEvaluate("x 5 =")
@@ -342,7 +342,7 @@ func TestAssignRightOperator(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
result, err := r.ParseAndEvaluate(tt.expr)
if err != nil {
t.Fatalf("ParseAndEvaluate(%q) error = %v", tt.expr, err)
@@ -367,7 +367,7 @@ func TestAssignLeftOperator(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
result, err := r.ParseAndEvaluate(tt.expr)
if err != nil {
t.Fatalf("ParseAndEvaluate(%q) error = %v", tt.expr, err)
@@ -393,7 +393,7 @@ func TestStandardAssignOperator(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
result, err := r.ParseAndEvaluate(tt.expr)
if err != nil {
t.Fatalf("ParseAndEvaluate(%q) error = %v", tt.expr, err)
@@ -421,7 +421,7 @@ func TestVariableInExpression(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
_, err := r.ParseAndEvaluate(tt.setup)
if err != nil {
t.Fatalf("Setup failed for %q: %v", tt.setup, err)
@@ -439,7 +439,7 @@ func TestVariableInExpression(t *testing.T) {
// TestChainedAssignments tests chaining multiple assignments in one expression.
func TestChainedAssignments(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
result, err := r.ParseAndEvaluate("a 10 := b 3 := c 2 :=")
if err != nil {
t.Fatalf("Chained assignment failed: %v", err)
@@ -472,7 +472,7 @@ func TestChainedAssignments(t *testing.T) {
// TestVarsCommand tests the vars command.
func TestVarsCommand(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
// Empty vars
result, err := r.ParseAndEvaluate("vars")
@@ -501,7 +501,7 @@ func TestVarsCommand(t *testing.T) {
// TestClearCommand tests the clear command.
func TestClearCommand(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
r.ParseAndEvaluate("x 5 :=")
r.ParseAndEvaluate("y 10 :=")
@@ -521,7 +521,7 @@ func TestClearCommand(t *testing.T) {
// TestDeleteVariableOperator tests the d (delete) operator.
func TestDeleteVariableOperator(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
// Create variable
r.ParseAndEvaluate("x 5 :=")
@@ -544,7 +544,7 @@ func TestDeleteVariableOperator(t *testing.T) {
// TestDeleteNonExistentVariableOperator tests deleting a variable that doesn't exist.
func TestDeleteNonExistentVariableOperator(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
_, err := r.ParseAndEvaluate(":nonexistent d")
if err == nil {
t.Error("Deleting non-existent variable should return error")
@@ -554,7 +554,7 @@ func TestDeleteNonExistentVariableOperator(t *testing.T) {
// TestVariablePersistenceAcrossExpressions tests that variables persist across
// multiple ParseAndEvaluate calls on the same RPN instance.
func TestVariablePersistenceAcrossExpressions(t *testing.T) {
- r := NewRPN(NewVariables())
+ r := NewRPN(NewVariables(), nil)
r.ParseAndEvaluate("a 10 :=")
r.ParseAndEvaluate("b 3 :=")
diff --git a/internal/rpn/boolean_test.go b/internal/rpn/boolean_test.go
index f0ced89..6eea269 100644
--- a/internal/rpn/boolean_test.go
+++ b/internal/rpn/boolean_test.go
@@ -98,7 +98,7 @@ func TestBooleanOperators(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate(tt.expression)
@@ -163,7 +163,7 @@ func TestBooleanToNumberCoercion(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate(tt.expression)
@@ -221,7 +221,7 @@ func TestMixedBooleanNumericArithmetic(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate(tt.expression)
@@ -268,7 +268,7 @@ func TestBooleanShowFormat(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate(tt.expression)
diff --git a/internal/rpn/compare_metric_test.go b/internal/rpn/compare_metric_test.go
index e1b5134..d32ac60 100644
--- a/internal/rpn/compare_metric_test.go
+++ b/internal/rpn/compare_metric_test.go
@@ -177,7 +177,7 @@ func TestMetricAwareComparisons(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
if tt.prefixMode == IEC {
rpnCalc.SetPrefixMode(IEC)
@@ -282,7 +282,7 @@ func TestShorthandComparisonOperators(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate(tt.expression)
@@ -356,7 +356,7 @@ func TestIncompatibleCategoryComparison(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
_, err := rpnCalc.ParseAndEvaluate(tt.expression)
@@ -414,7 +414,7 @@ func TestMetricComparisonEdgeCases(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
if tt.prefixMode == IEC {
rpnCalc.SetPrefixMode(IEC)
diff --git a/internal/rpn/constants_test.go b/internal/rpn/constants_test.go
index 68b79d1..4eb2129 100644
--- a/internal/rpn/constants_test.go
+++ b/internal/rpn/constants_test.go
@@ -213,7 +213,7 @@ func TestConstants_ThreadSafety(t *testing.T) {
func TestConstants_RetrieveInRPN(t *testing.T) {
v := NewVariables()
- r := NewRPN(v)
+ r := NewRPN(v, nil)
// Test pi constant
result, err := r.ParseAndEvaluate("pi")
@@ -226,7 +226,7 @@ func TestConstants_RetrieveInRPN(t *testing.T) {
// Create a new RPN instance for each test to avoid stack state conflicts
v2 := NewVariables()
- r2 := NewRPN(v2)
+ r2 := NewRPN(v2, nil)
// Test e constant
result, err = r2.ParseAndEvaluate("e")
@@ -239,7 +239,7 @@ func TestConstants_RetrieveInRPN(t *testing.T) {
// Create a new RPN instance for the next test
v3 := NewVariables()
- r3 := NewRPN(v3)
+ r3 := NewRPN(v3, nil)
// Test pi in expression
result, err = r3.ParseAndEvaluate("pi 2 *")
@@ -252,7 +252,7 @@ func TestConstants_RetrieveInRPN(t *testing.T) {
// Create a new RPN instance for phi test
v4 := NewVariables()
- r4 := NewRPN(v4)
+ r4 := NewRPN(v4, nil)
// Test phi constant
result, err = r4.ParseAndEvaluate("phi")
@@ -266,7 +266,7 @@ func TestConstants_RetrieveInRPN(t *testing.T) {
func TestConstants_RetrieveWithGreekLetters(t *testing.T) {
v := NewVariables()
- r := NewRPN(v)
+ r := NewRPN(v, nil)
// Test pi with Greek letter
result, err := r.ParseAndEvaluate("π")
@@ -279,7 +279,7 @@ func TestConstants_RetrieveWithGreekLetters(t *testing.T) {
// Create a new RPN instance for phi test
v2 := NewVariables()
- r2 := NewRPN(v2)
+ r2 := NewRPN(v2, nil)
// Test phi with Greek letter
result, err = r2.ParseAndEvaluate("φ")
@@ -293,7 +293,7 @@ func TestConstants_RetrieveWithGreekLetters(t *testing.T) {
func TestConstants_ConflictWithVariables(t *testing.T) {
v := NewVariables()
- r := NewRPN(v)
+ r := NewRPN(v, nil)
// First set a variable named pi
result, err := r.ParseAndEvaluate("pi = 3.0")
@@ -316,7 +316,7 @@ func TestConstants_ConflictWithVariables(t *testing.T) {
func TestConstantsCommand(t *testing.T) {
v := NewVariables()
- r := NewRPN(v)
+ r := NewRPN(v, nil)
result, err := r.ParseAndEvaluate("constants")
if err != nil {
t.Fatalf("ParseAndEvaluate(\"constants\") returned error: %v", err)
@@ -328,7 +328,7 @@ func TestConstantsCommand(t *testing.T) {
func TestClearConstantsCommand(t *testing.T) {
v := NewVariables()
- r := NewRPN(v)
+ r := NewRPN(v, nil)
// First add a custom constant
result, err := r.ParseAndEvaluate("custom 42 =")
@@ -409,7 +409,7 @@ func TestConstants_NewConstants(t *testing.T) {
// TestConstants_ParseInRPN tests that new constants can be used in RPN expressions
func TestConstants_ParseInRPN(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
tests := []struct {
expression string
@@ -532,7 +532,7 @@ func TestConstants_MoreInRPN(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate(tt.expression)
if err != nil {
@@ -567,7 +567,7 @@ func TestConstants_ListConstantsIncludesUserDefined(t *testing.T) {
// TestConstants_NegativeInfInRPN tests negative infinity constant in RPN
func TestConstants_NegativeInfInRPN(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
result, err := rpnCalc.ParseAndEvaluate("-inf")
if err != nil {
@@ -581,7 +581,7 @@ func TestConstants_NegativeInfInRPN(t *testing.T) {
// TestConstants_InfExpression tests infinity in RPN expressions
func TestConstants_InfExpression(t *testing.T) {
vars := NewVariables()
- rpnCalc := NewRPN(vars)
+ rpnCalc := NewRPN(vars, nil)
// inf 1 + should still be inf
result, err := rpnCalc.ParseAndEvaluate("inf 1 +")
diff --git a/internal/rpn/custom_metric_test.go b/internal/rpn/custom_metric_test.go
index e555cee..47ece0f 100644
--- a/internal/rpn/custom_metric_test.go
+++ b/internal/rpn/custom_metric_test.go
@@ -20,7 +20,7 @@ func customCleanup(t *testing.T, rpn *RPN, name string) {
// TestCustomDefineFactorZero tests defining a custom metric with factor=0
func TestCustomDefineFactorZero(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "zero")
result, err := rpn.ParseAndEvaluate("custom define zero 0 Custom")
@@ -42,7 +42,7 @@ func TestCustomDefineFactorZero(t *testing.T) {
// TestCustomDefineNegativeFactor tests defining a custom metric with negative factor
func TestCustomDefineNegativeFactor(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "negtest")
result, err := rpn.ParseAndEvaluate("custom define negtest -5 Custom")
@@ -64,7 +64,7 @@ func TestCustomDefineNegativeFactor(t *testing.T) {
// TestCustomDefineMalformedInput tests that malformed custom define input
func TestCustomDefineMalformedInput(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("custom define 1 Custom")
// Double-space collapses: fields = ["custom", "define", "1", "Custom"] (metric "" already exists as alias or empty check)
@@ -78,7 +78,7 @@ func TestCustomDefineMalformedInput(t *testing.T) {
// that conflicts with an existing metric
func TestCustomDefineConflictingAlias(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Try to define a metric with a name that matches an existing one
_, err := rpn.ParseAndEvaluate("custom define Mbps 1000 DataRate")
@@ -90,7 +90,7 @@ func TestCustomDefineConflictingAlias(t *testing.T) {
// TestCustomMetricArithmetic tests using a custom metric in arithmetic operations
func TestCustomMetricArithmetic(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "arithmetic_test")
_, err := rpn.ParseAndEvaluate("custom define arithmetic_test 42 Custom")
@@ -109,7 +109,7 @@ func TestCustomMetricArithmetic(t *testing.T) {
// TestCustomMetricHyperOperations tests using a custom metric in hyper operations
func TestCustomMetricHyperOperations(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "hyper_test")
_, err := rpn.ParseAndEvaluate("custom define hyper_test 100 Custom")
@@ -128,7 +128,7 @@ func TestCustomMetricHyperOperations(t *testing.T) {
// TestCustomMetricSubtraction tests subtraction with custom metrics
func TestCustomMetricSubtraction(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "sub_test")
_, err := rpn.ParseAndEvaluate("custom define sub_test 10 Custom")
@@ -146,7 +146,7 @@ func TestCustomMetricSubtraction(t *testing.T) {
// TestCustomMetricMultiplication tests multiplication with custom metrics
func TestCustomMetricMultiplication(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "mul_test")
_, err := rpn.ParseAndEvaluate("custom define mul_test 5 Custom")
@@ -164,7 +164,7 @@ func TestCustomMetricMultiplication(t *testing.T) {
// TestCustomMetricDivision tests division with custom metrics
func TestCustomMetricDivision(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "div_test")
_, err := rpn.ParseAndEvaluate("custom define div_test 10 Custom")
@@ -183,7 +183,7 @@ func TestCustomMetricDivision(t *testing.T) {
// between different categories
func TestCustomMetricConversionFail(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "conv_test")
_, err := rpn.ParseAndEvaluate("custom define conv_test 10 Custom")
@@ -202,7 +202,7 @@ func TestCustomMetricConversionFail(t *testing.T) {
// can't be mixed in operations
func TestCustomMetricCrossCategory(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "cat_test1")
defer customCleanup(t, rpn, "cat_test2")
@@ -219,7 +219,7 @@ func TestCustomMetricCrossCategory(t *testing.T) {
// TestCustomMetricShow tests that custom metrics display correctly in Show
func TestCustomMetricShow(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
defer customCleanup(t, rpn, "show_test")
_, err := rpn.ParseAndEvaluate("custom define show_test 100 Custom")
diff --git a/internal/rpn/metric_test.go b/internal/rpn/metric_test.go
index 69923cb..5a41f6f 100644
--- a/internal/rpn/metric_test.go
+++ b/internal/rpn/metric_test.go
@@ -832,7 +832,7 @@ func TestAtPrefixMetricParsing(t *testing.T) {
func TestAtPrefixIntegration(t *testing.T) {
// Test that @GB parses correctly through the full RPN pipeline
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Parse a standalone @ metric
result, err := rpn.ParseAndEvaluate("@GB")
@@ -880,7 +880,7 @@ func TestMetricAwareArithmetic(t *testing.T) {
for _, tt := range tests {
t.Run(tt.expr, func(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate(tt.expr)
if tt.wantErr {
if err == nil {
@@ -985,7 +985,7 @@ func TestMetricOperationsUnit(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
vars := NewVariables()
- ops := NewOperations(vars)
+ ops := NewOperations(vars, nil)
s := NewStack()
tc.setup(s)
@@ -1040,7 +1040,7 @@ func TestConvertSameCategory(t *testing.T) {
for _, tt := range tests {
t.Run(tt.expr, func(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate(tt.expr)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -1064,7 +1064,7 @@ func TestConvertSameCategory(t *testing.T) {
func TestConvertCoolAbsorbing(t *testing.T) {
reg := GetMetricRegistry()
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Cool to metric: 100 @GB convert → 100 GB
// With Cool absorption, 100 is treated as 100 in GB's space
@@ -1086,7 +1086,7 @@ func TestConvertCoolAbsorbing(t *testing.T) {
}
// Metric to Cool: 1hr @Cool convert → 3600 Cool
- rpn2 := NewRPN(NewVariables())
+ rpn2 := NewRPN(NewVariables(), nil)
result2, err := rpn2.ParseAndEvaluate("1hr @Cool convert")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -1107,7 +1107,7 @@ func TestConvertCoolAbsorbing(t *testing.T) {
func TestConvertIncompatible(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("100Mbps @hr convert")
if err == nil {
@@ -1121,7 +1121,7 @@ func TestConvertIncompatible(t *testing.T) {
func TestConvertInsufficientOperands(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Missing value (only target on stack)
_, err := rpn.ParseAndEvaluate("@Gbps convert")
@@ -1130,7 +1130,7 @@ func TestConvertInsufficientOperands(t *testing.T) {
}
// Missing target (only value on stack, no @X before convert)
- rpn2 := NewRPN(NewVariables())
+ rpn2 := NewRPN(NewVariables(), nil)
_, err = rpn2.ParseAndEvaluate("100Mbps convert")
if err == nil {
t.Error("expected error for missing target metric operand")
diff --git a/internal/rpn/operations.go b/internal/rpn/operations.go
index 989ce87..3a85ee5 100644
--- a/internal/rpn/operations.go
+++ b/internal/rpn/operations.go
@@ -38,10 +38,10 @@ var (
// NewOperations creates a new Operations instance with the given variable store.
// Does not create a ConstantsProvider internally; caller must use SetConstants.
// If no registry is provided, defaults to the global MetricRegistry.
-func NewOperations(vars VariableStore, reg ...MetricReader) *Operations {
+func NewOperations(vars VariableStore, reg MetricReader) *Operations {
r := MetricReader(GetMetricRegistry())
- if len(reg) > 0 && reg[0] != nil {
- r = reg[0]
+ if reg != nil {
+ r = reg
}
return &Operations{
vars: vars,
diff --git a/internal/rpn/operations_fastpower_test.go b/internal/rpn/operations_fastpower_test.go
index 06a79e0..cdd4c04 100644
--- a/internal/rpn/operations_fastpower_test.go
+++ b/internal/rpn/operations_fastpower_test.go
@@ -70,7 +70,7 @@ func TestFastPower(t *testing.T) {
stack := NewStack()
tt.prepare(stack)
- o := NewOperations(NewVariables())
+ o := NewOperations(NewVariables(), nil)
err := o.FastPower(stack)
if tt.wantErr {
diff --git a/internal/rpn/operations_hyper_test.go b/internal/rpn/operations_hyper_test.go
index 352e503..2a1607a 100644
--- a/internal/rpn/operations_hyper_test.go
+++ b/internal/rpn/operations_hyper_test.go
@@ -81,7 +81,7 @@ func TestHyperMetricAwareOperations(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate(tc.expr)
if tc.wantErr {
if err == nil {
@@ -162,7 +162,7 @@ func TestHyperCoolResultOperations(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate(tc.expr)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -198,7 +198,7 @@ func TestHyperErrorCases(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate(tc.expr)
if err == nil {
t.Fatal("expected error, got none")
diff --git a/internal/rpn/operations_metric_cmd_test.go b/internal/rpn/operations_metric_cmd_test.go
index e7307f7..ea9431d 100644
--- a/internal/rpn/operations_metric_cmd_test.go
+++ b/internal/rpn/operations_metric_cmd_test.go
@@ -11,7 +11,7 @@ import (
func TestMetricShow(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("100Mbps metric show")
if err != nil {
@@ -27,7 +27,7 @@ func TestMetricShow(t *testing.T) {
func TestMetricShowUniversal(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("42 metric show")
if err != nil {
@@ -43,7 +43,7 @@ func TestMetricShowUniversal(t *testing.T) {
func TestMetricShowEmptyStack(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("metric show")
if err == nil {
t.Error("expected error for empty stack")
@@ -52,7 +52,7 @@ func TestMetricShowEmptyStack(t *testing.T) {
func TestMetricList(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("metric list")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -67,7 +67,7 @@ func TestMetricList(t *testing.T) {
func TestMetricCategory(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("metric DataRate")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -82,7 +82,7 @@ func TestMetricCategory(t *testing.T) {
func TestMetricCategoryTime(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("metric Time")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -97,7 +97,7 @@ func TestMetricCategoryTime(t *testing.T) {
func TestMetricCategoryUnknown(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("metric Nope")
if err == nil {
t.Error("expected error for unknown category")
@@ -106,7 +106,7 @@ func TestMetricCategoryUnknown(t *testing.T) {
func TestMetricCategoryCustom(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Custom category exists but has no built-in metrics, so result should be empty
result, err := rpn.ParseAndEvaluate("metric Custom")
if err != nil {
@@ -118,7 +118,7 @@ func TestMetricCategoryCustom(t *testing.T) {
func TestMetricSetModeDecimal(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("metric decimal set")
if err != nil {
@@ -134,7 +134,7 @@ func TestMetricSetModeDecimal(t *testing.T) {
func TestMetricSetModeBinary(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("metric binary set")
if err != nil {
@@ -150,7 +150,7 @@ func TestMetricSetModeBinary(t *testing.T) {
func TestMetricSetModeToggle(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Default is SI
if rpn.GetPrefixMode() != SI {
@@ -172,7 +172,7 @@ func TestMetricSetModeToggle(t *testing.T) {
func TestMetricSetModeBinaryIncomplete(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("metric binary")
if err == nil {
t.Error("expected error for incomplete 'metric binary'")
@@ -181,7 +181,7 @@ func TestMetricSetModeBinaryIncomplete(t *testing.T) {
func TestMetricSetModeDecimalIncomplete(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("metric decimal")
if err == nil {
t.Error("expected error for incomplete 'metric decimal'")
@@ -190,7 +190,7 @@ func TestMetricSetModeDecimalIncomplete(t *testing.T) {
func TestMetricCompatibleSameCategory(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("100Mbps 1Gbps metric compatible")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -202,7 +202,7 @@ func TestMetricCompatibleSameCategory(t *testing.T) {
func TestMetricCompatibleDifferentCategory(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("100Mbps 2hr metric compatible")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -221,7 +221,7 @@ func TestMetricCompatibleDifferentCategory(t *testing.T) {
func TestMetricCompatibleWithUniversal(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
result, err := rpn.ParseAndEvaluate("100Mbps 42 metric compatible")
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -234,7 +234,7 @@ func TestMetricCompatibleWithUniversal(t *testing.T) {
func TestMetricCompatibleNotEnoughValues(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("100 metric compatible")
if err == nil {
t.Error("expected error for insufficient stack values")
@@ -243,7 +243,7 @@ func TestMetricCompatibleNotEnoughValues(t *testing.T) {
func TestMetricCompatibleEmptyStack(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
_, err := rpn.ParseAndEvaluate("metric compatible")
if err == nil {
t.Error("expected error for empty stack")
@@ -349,7 +349,7 @@ func TestPrefixMode(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
if tc.setMode == "iec" {
if _, err := rpn.ParseAndEvaluate("metric binary set"); err != nil {
@@ -383,7 +383,7 @@ func TestPrefixMode(t *testing.T) {
func TestCustomDefineAndList(t *testing.T) {
vars := NewVariables()
- rpn := NewRPN(vars)
+ rpn := NewRPN(vars, nil)
// Define a custom m