summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-22 12:19:11 +0300
committerPaul Buetow <paul@buetow.org>2026-05-22 12:19:11 +0300
commit9eef36a097be877388e059fd1183aaf9ab166ee4 (patch)
treebbe706a6cc58433f08113572758eb0cbd818cc09
parentd34ecb37e49a0203a6c4db1fe9ab76e305ae8a66 (diff)
fix(rpn): clean up metric subcommands per review feedback
- Remove dead 'i += 2' in metric binary/decimal set handlers (the increment is followed by immediate return, never used) - Clarify MetricShow always uses SI factor in display (prefixMode not yet wired into computations) - Add test for metric Custom category
-rw-r--r--internal/rpn/operations_metric_cmd.go2
-rw-r--r--internal/rpn/operations_metric_cmd_test.go12
-rw-r--r--internal/rpn/rpn_parse.go2
3 files changed, 13 insertions, 3 deletions
diff --git a/internal/rpn/operations_metric_cmd.go b/internal/rpn/operations_metric_cmd.go
index 9a09a67..57303a6 100644
--- a/internal/rpn/operations_metric_cmd.go
+++ b/internal/rpn/operations_metric_cmd.go
@@ -22,7 +22,7 @@ func (o *Operations) MetricShow(stack *Stack) (string, error) {
if m == nil || m.Category == Universal {
return "Cool (Universal)", nil
}
- factor := m.Factor(SI) // use SI for display
+ factor := m.Factor(SI) // display uses SI; prefixMode is not yet wired into computations
return fmt.Sprintf("%s, %s, base: %s, factor: %.0g", m.Name, m.Category, m.BaseUnit, factor), nil
}
diff --git a/internal/rpn/operations_metric_cmd_test.go b/internal/rpn/operations_metric_cmd_test.go
index 9b77439..a2bfcca 100644
--- a/internal/rpn/operations_metric_cmd_test.go
+++ b/internal/rpn/operations_metric_cmd_test.go
@@ -103,6 +103,18 @@ func TestMetricCategoryUnknown(t *testing.T) {
}
}
+func TestMetricCategoryCustom(t *testing.T) {
+ vars := NewVariables()
+ rpn := NewRPN(vars)
+ // Custom category exists but has no built-in metrics, so result should be empty
+ result, err := rpn.ParseAndEvaluate("metric Custom")
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ // Empty string is fine — no custom metrics registered by default
+ _ = result
+}
+
func TestMetricSetModeDecimal(t *testing.T) {
vars := NewVariables()
rpn := NewRPN(vars)
diff --git a/internal/rpn/rpn_parse.go b/internal/rpn/rpn_parse.go
index 5d5ef7d..bc25d52 100644
--- a/internal/rpn/rpn_parse.go
+++ b/internal/rpn/rpn_parse.go
@@ -368,14 +368,12 @@ func (r *RPN) evaluate(input string, tokens []string) (string, error) {
case "binary":
if i+2 < len(tokens) && tokens[i+2] == "set" {
r.prefixMode = IEC
- i += 2 // skip "binary" and "set"
return "prefix mode: IEC", nil
}
return "", fmt.Errorf("rpn: metric binary: use 'metric binary set'")
case "decimal":
if i+2 < len(tokens) && tokens[i+2] == "set" {
r.prefixMode = SI
- i += 2 // skip "decimal" and "set"
return "prefix mode: SI", nil
}
return "", fmt.Errorf("rpn: metric decimal: use 'metric decimal set'")