summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 10:38:40 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 10:38:40 +0300
commit86ae9edf6fb68e027557f467a3d585f0365f9c64 (patch)
treeb77354d8d16865f70e805fef8ba534b8ba0c478e /internal
parent0cf4e039384ace9b822316583f2ce63c9a4dfd39 (diff)
refactor(rpn): move dead Value type to test file
Value struct and its methods (NewNumberValue, NewBoolValue, IsBool, IsNumber, Bool, Float64, Number, String) are defined in number.go but never called in production code — only used in number_value_test.go. Move the Value type and all its methods into the test file so they don't pollute the production package.
Diffstat (limited to 'internal')
-rw-r--r--internal/rpn/number.go71
-rw-r--r--internal/rpn/number_value_test.go74
2 files changed, 74 insertions, 71 deletions
diff --git a/internal/rpn/number.go b/internal/rpn/number.go
index 5e27dae..a188edf 100644
--- a/internal/rpn/number.go
+++ b/internal/rpn/number.go
@@ -407,75 +407,4 @@ func (s *Symbol) IsBool() bool { return false }
func (s *Symbol) IsString() bool { return false }
func (s *Symbol) Metric() *Metric { return GetCoolMetric() }
-// Value represents a variant type that can hold either a number (float64) or a boolean.
-//
-// When used in arithmetic operations, boolean values are automatically coerced:
-// - true -> 1
-// - false -> 0
-//
-// This allows boolean results from comparison operations to be used directly in
-// arithmetic expressions (e.g., "5 3 == 1 +" where "5 3 ==" produces false=0,
-// and "0 + 1" produces 1).
-type Value struct {
- isBool bool
- boolVal bool
- numVal float64
-}
-
-// NewNumberValue creates a new Value containing a float64 number.
-func NewNumberValue(n float64) Value {
- return Value{isBool: false, numVal: n}
-}
-
-// NewBoolValue creates a new Value containing a boolean.
-func NewBoolValue(b bool) Value {
- return Value{isBool: true, boolVal: b}
-}
-
-// IsBool returns true if the value is a boolean.
-func (v Value) IsBool() bool {
- return v.isBool
-}
-
-// IsNumber returns true if the value is a number.
-func (v Value) IsNumber() bool {
- return !v.isBool
-}
-
-// Bool returns the boolean value, or false if the value is not a boolean.
-func (v Value) Bool() bool {
- return v.boolVal
-}
-// Float64 returns the float64 value.
-// If the value is a boolean, true returns 1 and false returns 0.
-// If the value is a number, it returns the numeric value directly.
-func (v Value) Float64() float64 {
- if v.isBool {
- if v.boolVal {
- return 1
- }
- return 0
- }
- return v.numVal
-}
-
-// Number returns the float64 value.
-// If the value is a boolean, this returns 0 (the numeric value is not used for booleans).
-// Deprecated: Use Float64 instead.
-func (v Value) Number() float64 {
- return v.numVal
-}
-
-// String returns the string representation of the value.
-// For booleans, it returns "true" or "false".
-// For numbers, it returns the formatted float64 value.
-func (v Value) String() string {
- if v.isBool {
- if v.boolVal {
- return "true"
- }
- return "false"
- }
- return fmt.Sprintf("%.10g", v.numVal)
-}
diff --git a/internal/rpn/number_value_test.go b/internal/rpn/number_value_test.go
index 51385bb..8f43ab7 100644
--- a/internal/rpn/number_value_test.go
+++ b/internal/rpn/number_value_test.go
@@ -4,10 +4,84 @@
package rpn
import (
+ "fmt"
"math/big"
"testing"
)
+// Value represents a variant type that can hold either a number (float64) or a boolean.
+//
+// When used in arithmetic operations, boolean values are automatically coerced:
+// - true -> 1
+// - false -> 0
+//
+// This allows boolean results from comparison operations to be used directly in
+// arithmetic expressions (e.g., "5 3 == 1 +" where "5 3 ==" produces false=0,
+// and "0 + 1" produces 1).
+type Value struct {
+ isBool bool
+ boolVal bool
+ numVal float64
+}
+
+// NewNumberValue creates a new Value containing a float64 number.
+func NewNumberValue(n float64) Value {
+ return Value{isBool: false, numVal: n}
+}
+
+// NewBoolValue creates a new Value containing a boolean.
+func NewBoolValue(b bool) Value {
+ return Value{isBool: true, boolVal: b}
+}
+
+// IsBool returns true if the value is a boolean.
+func (v Value) IsBool() bool {
+ return v.isBool
+}
+
+// IsNumber returns true if the value is a number.
+func (v Value) IsNumber() bool {
+ return !v.isBool
+}
+
+// Bool returns the boolean value, or false if the value is not a boolean.
+func (v Value) Bool() bool {
+ return v.boolVal
+}
+
+// Float64 returns the float64 value.
+// If the value is a boolean, true returns 1 and false returns 0.
+// If the value is a number, it returns the numeric value directly.
+func (v Value) Float64() float64 {
+ if v.isBool {
+ if v.boolVal {
+ return 1
+ }
+ return 0
+ }
+ return v.numVal
+}
+
+// Number returns the float64 value.
+// If the value is a boolean, this returns 0 (the numeric value is not used for booleans).
+// Deprecated: Use Float64 instead.
+func (v Value) Number() float64 {
+ return v.numVal
+}
+
+// String returns the string representation of the value.
+// For booleans, it returns "true" or "false".
+// For numbers, it returns the formatted float64 value.
+func (v Value) String() string {
+ if v.isBool {
+ if v.boolVal {
+ return "true"
+ }
+ return "false"
+ }
+ return fmt.Sprintf("%.10g", v.numVal)
+}
+
func TestNewNumberValue(t *testing.T) {
v := NewNumberValue(42.5)
if !v.IsNumber() {