summaryrefslogtreecommitdiff
path: root/internal
AgeCommit message (Collapse)Author
2026-04-11Refactor number.go Float64() to return errorsPaul Buetow
- Float64() now returns (float64, error) instead of just float64 - All arithmetic methods (Add, Sub, Mul, Div, Pow, Mod, Compare) return errors - IsString() and IsSymbol() added to Number interface - Float and Rat now implement IsString() and IsSymbol() - StringNum and Symbol updated to implement complete Number interface - IsZero() updated to use val, _ := Float64() pattern - ToFloat() updated to ignore error from Float64()}
2026-04-11Refactor number.go to return errors instead of panickingPaul Buetow
- Changed Number interface methods to return errors instead of panicking - Float64() now returns (float64, error) - Add, Sub, Mul, Pow, Compare, Bool() now return (Number, error) or (int, error) - StringNum and Symbol now return errors for unsupported operations - Added IsString() and IsSymbol() to Number interface - Removed unused arithmetic.go file - Updated operations.go, boolean_ops.go, hyper.go to handle errors - Added constants registry (internal/rpn/constants.go) with built-in math constants - Added constants_test.go with comprehensive unit tests - Updated README.md with constants documentation
2026-03-26increment versionv0.4.1Paul Buetow
2026-03-26fix modulePaul Buetow
2026-03-26chore: bump version to v0.4.0Paul Buetow
- Extracted RPN assignment handlers to fix SRP violation - Fixed error handling in test files - Removed unused StackOperations struct - Moved integration tests to ./integrationtests folder - Various code quality improvements
2026-03-26refactor: remove unused StackOperations structPaul Buetow
This struct provided stack manipulation operator implementations but was never used in the codebase. All stack operations are implemented directly in the Operations struct in operations.go.
2026-03-26fix: remove unused variable assignments in test filesPaul Buetow
- internal/repl/repl_test.go: Remove unused state variable assignments - internal/rpn/rpn_test.go: Remove unused result/err variable assignments These changes address golangci-lint 'ineffectual assignment' warnings.
2026-03-26fix: address code quality issues from golangci-lintPaul Buetow
- Fix error handling in test files by explicitly ignoring error returns - Remove trailing punctuation from error message in rpn_parse.go Test file changes: - cli_test.go: Use _ = os.Remove() in Cleanup function - concurrent_test.go: Use _, _ = runRPN() in concurrent goroutines Code change: - rpn_parse.go: Changed error message to end with 'colon' instead of ':'
2026-03-26refactor: Extract RPN assignment handlers to fix SRP violationPaul Buetow
Created specialized handlers for each assignment operator type: - handleAssignRight (for := operator) - handleAssignLeft (for =: operator) - handleStandardAssign (for = operator) The assignmentHandler uses the Strategy pattern to delegate to specialized handlers based on the assignment operator found in the input. Each handler has a single, well-defined responsibility, addressing the SRP violation in the previous monolithic handleAssignment method. All tests pass and code quality is maintained.
2026-03-26fix: Register < operator and fix > operator mappingPaul Buetow
2026-03-26fix: Handle boolean operators == and != correctlyPaul Buetow
2026-03-26feat: Add integration tests for variable assignments and fix RPN parser bugsPaul Buetow
2026-03-25rpn: fix x =: stack-based variable assignmentPaul Buetow
2026-03-25rpn: Add unit test for exact user scenario with x =: incremental assignmentPaul Buetow
2026-03-25rpn: Add unit test for user scenario with x =: taking value from stackPaul Buetow
2026-03-25rpn: Fix incremental assignment with x =: (take value from stack)Paul Buetow
2026-03-25rpn: Add test for incremental assignment with =: operatorPaul Buetow
2026-03-25rpn: Fix := and =: operators semanticsPaul Buetow
2026-03-25rpn: Fix =: operator pop order for REPL modePaul Buetow
2026-03-25rpn: Fix AssignLeft/AssignRight to handle StringNum correctlyPaul Buetow
2026-03-25rpn: Add := and =: assignment operators with = synonymPaul Buetow
2026-03-25code-quality: Various improvements to code quality and thread safetyPaul Buetow
2026-03-25Rename calculator package to percPaul Buetow
Renamed internal/calculator directory to internal/perc, updated package name from 'calculator' to 'perc', and updated all import references.
2026-03-25Fix Ln operation and add comprehensive testsPaul Buetow
- Fixed Ln operation to handle Value conversion before math.Log using Float64() which handles boolean conversion (true → 1, false → 0) - Added TestLnWithBoolean and TestLnEdgeCases tests for comprehensive coverage - Refactored operations.go into separate files (arithmetic.go, boolean_ops.go, hyper.go, stack.go, variable.go) - Removed unused toNumber function from number.go - Added Float64() method to Value struct for boolean conversion
2026-03-25refactor: Refactor RPN to use Number interface uniformly for stack valuesPaul Buetow
This commit refactors the internal/rpn package to use the Number interface instead of the old Value struct for stack values. Key changes: 1. Updated Number interface to include IsBool() and Bool() methods for boolean value support 2. Modified Float and Rat types to support boolean mode with: - isBool and boolVal fields - Float64() returns 1 for true, 0 for false - String() returns 'true' or 'false' for boolean values 3. Updated Stack to use []Number instead of []Value 4. Updated all operations to use the Number interface methods directly - Add, Sub, Mul, Div, Pow, Mod now use Float64() for values 5. Updated tests to use NewNumber() with mode parameter instead of NewNumberValue(), and use Float64() instead of Number() Benefits: - Simplified code - no need for toNumber() and NewNumberValue() wrappers - Better type safety - stack values are Number interface instances - Boolean-to-number coercion works correctly in all operations
2026-03-25refactor: Update GetCurrentStack to return []Value instead of []float64Paul Buetow
- Changed GetCurrentStack() to return []Value to preserve value types - Updated test to use Value.Number() method for comparison - Boolean values are now correctly preserved in stack inspection This ensures that boolean values returned from comparison operators (gt, lt, etc.) are preserved when inspecting the stack.
2026-03-25refactor: Split internal/rpn/rpn.go into separate files for better SRPPaul Buetow
Created new files for better separation of concerns: - internal/rpn/mode.go: CalculationMode enum - internal/rpn/rpn_state.go: RPN struct and state management - internal/rpn/rpn_ops.go: Operator execution and evaluation - internal/rpn/rpn_parse.go: Parsing and assignment handling Original rpn.go now contains only the RPN struct and constructor. Benefits: - Better Single Responsibility Principle (SRP) - Improved code organization and readability - Easier to maintain and test individual components
2026-03-25docs: Add SPDX license headers to remaining .go filesPaul Buetow
- Added SPDX header to cmd/gt/cli_test.go - Added SPDX header to internal/rpn/boolean_test.go All 27 .go source files now have SPDX license headers with MIT license and copyright notice for Paul Buetow (c) 2026.
2026-03-25chore: Bump version to v0.3.0Paul Buetow
- Added boolean operators (gt, lt, gte, lte, eq, neq) - Implemented boolean-to-number coercion in arithmetic - Added comprehensive tests for boolean operators This is a minor version bump (new features).
2026-03-25feat: Implement boolean operators and mixed boolean-numeric arithmeticPaul Buetow
- Added boolean operators: GT, LT, GTE, LTE, EQ, NEQ - Registered as: gt, lt, gte, lte, eq, neq - Also registered symbols: >, <, >=, <=, ==, != - Added boolean literal support: - true and false are now recognized as boolean values - Can be used in expressions like: true 2 *, 0 false + - Fixed boolean formatting: - Show command now displays booleans as 'true'/'false' - Single result output uses Value.String() instead of toNumber() - Created boolean_test.go with comprehensive tests: - TestBooleanOperators: Tests all 6 boolean operators - TestBooleanToNumberCoercion: Tests automatic coercion in arithmetic - TestMixedBooleanNumericArithmetic: Tests mixed boolean-numeric arithmetic - TestBooleanShowFormat: Tests Show command displays booleans correctly All tests pass and the binary builds correctly.
2026-03-25ci: Add boolean-coercion tests and bump version to v0.2.2Paul Buetow
- Updated internal/version.go to v0.2.2 - Added boolean_coercion_test.go with tests for boolean-to-number coercion - Note: Boolean operators (> < == != etc.) not yet implemented (task 3cc6a147) Tests use NewBoolValue() which requires direct Value manipulation - CI workflow already runs all tests with go test ./... - Added coverage check (60% minimum) in .github/workflows/ci.yml When boolean operators are implemented, the boolean_coercion_test.go can be re-enabled with tests using comparison operators.
2026-03-25ci: Update Magefile to include shortcuts for build, test, lint, and releasePaul Buetow
- Added Lint target: runs golangci-lint for code quality checks - Added Release target: builds and packages releases (requires goreleaser) Also fixed errcheck linting issue: - Check error return from o.vars.SetVariable in AssignVariable All mage targets work: build, run, test, testRPN, rpn, install, lint, release, repl, uninstall
2026-03-25refactor: Update Show command to format boolean values correctlyPaul Buetow
- Changed Show to use val.String() instead of NewNumber(toNumber(val), o.mode) - Boolean values now display as 'true'/'false' instead of '1'/'0' - Number values preserve their numeric formatting The Show command now correctly handles mixed boolean-numeric stacks, displaying booleans as 'true'/'false' and numbers with appropriate precision.
2026-03-25docs: Add SPDX license headers to all .go source filesPaul Buetow
- Added 'SPDX-License-Identifier: MIT' and 'Copyright (c) 2026 Paul Buetow' headers - Files updated: 24 .go files across cmd/gt/, internal/calculator/, internal/repl/, internal/rpn/ The MIT license from LICENSE file is reflected in all source files.
2026-03-25docs: Update README.md and godoc for Boolean-to-Number coercionPaul Buetow
- Added documentation section to README.md explaining automatic coercion - Included usage examples: '5 3 == 1 +', '0 false +', 'true 2 *', '9 3 > 4 5 < +' - Updated Value type godoc to explain coercion behavior (true→1, false→0) - toNumber() function already had good documentation The coercion allows boolean results to be used directly in arithmetic operations, enabling expressions like '5 3 == 1 +' where '5 3 ==' produces false=0, then '0 + 1' produces 1.
2026-03-25refactor: Add error wrapping with %w where appropriatePaul Buetow
- Updated operator registration in rpn/operations.go: - registerStandardOperator now wraps handler errors with operator name context - registerCommandOperator now wraps handler errors with operator name context - registerHyperOperator now wraps handler errors with operator name context - Updated Parse() in calculator/calculator.go: - Now wraps registry.parse() errors with context about the input - Returns a more descriptive error when parsing fails All tests pass and the binary builds and runs correctly.
2026-03-25fix: Handle Value types correctly in RPN operationsPaul Buetow
- Updated HyperMultiply, HyperSubtract, HyperDivide, HyperPower, HyperModulo to use []Value and toNumber() for Value-to-float64 conversions - Updated HyperLog2, HyperLog10, HyperLn to use []Value and toNumber() - Fixed rpn.go: - Stack.Push() now uses NewNumberValue() for float64 values - GetCurrentStack() converts []Value to []float64 - show() output uses toNumber() for Value formatting - Variable handling uses NewNumberValue() when pushing - Fixed test files (operations_test.go): - Updated all Stack.Push() calls to use NewNumberValue() - Updated Pop() comparisons to use .Number() method - Fixed format specifiers for Errorf() calls All tests pass and the binary builds and runs correctly.
2026-03-25refactor: Consolidate REPL command descriptions to single sourcePaul Buetow
- Removed duplicate getCommandDescription function from completer.go - Added package-level getCommandDescription in repl.go as single source of truth - Updated defaultGetCommandDescription to delegate to getCommandDescription - Created minimal completer.go that uses getCommandDescription for test compatibility Command descriptions are now defined only once, eliminating duplication between the original completer.go and defaultGetCommandDescription in repl.go. The refactoring maintains: - Backward compatibility (tests still work) - Consistent descriptions across the codebase - Single source of truth for command descriptions
2026-03-25docs: Add comprehensive Go documentation for REPL functionsPaul Buetow
- Enhanced NewREPL documentation with detailed parameter descriptions - Enhanced RunREPL documentation clarifying it's a convenience wrapper - Improved executor documentation explaining backward compatibility and testing usage - Enhanced defaultExecutor documentation with input processing details and panic recovery - Enhanced defaultCompleter documentation with tab-completion behavior details - Enhanced defaultGetCommandDescription documentation with command description details - Improved TTYChecker methods (IsTTY, EnsureTTY) documentation - Improved SignalHandler.Start method documentation All exported and non-exported functions in the REPL package now have comprehensive documentation comments that describe their purpose, parameters, and return values.
2026-03-25cmd/gt: add comprehensive package documentationPaul Buetow
- Enhanced Package gt documentation with detailed usage examples for percentage calculations and RPN expressions - Added architecture overview section - Enhanced Package internal documentation with version format, build instructions, and usage examples - All tests pass and application builds correctly
2026-03-24test: Improve defaultExecutor and defaultCompleter test coveragePaul Buetow
- Add TestDefaultExecutorCodePaths to test all code paths in defaultExecutor - Improve TestDefaultCompleter to test with multiple input prefixes - Add comprehensive test for unknown commands, built-in commands, and edge cases
2026-03-24refactor: Move RPNState and related declarations to top of repl.goPaul Buetow
- Move RPNState type definition before any functions - Move rpnState and rpnStateOnce variable declarations before any functions - Keep REPL struct and NewREPL constructor at the top (as per Go best practices) - Update getRPNState comment to be more descriptive This change follows Go best practices where constants, global variables, and type definitions should be at the top of the file before functions.
2026-03-24feat: Add RPN mode, rational number support, and improve REPLPaul Buetow
- Add RPN (Reverse Polish Notation) calculator with stack-based operations - Support precise rational number calculations using *big.Rat - Implement chain of responsibility pattern for command handling - Add auto-completion for built-in commands - Add history persistence with configurable max entries - Support standard operators: +, -, *, /, ^, %, lg, log, ln - Support hyper operators: [+], [-], [*], [/], [^], [%], [lg], [log], [ln] - Support stack manipulation: dup, swap, pop, show - Support variable assignments and management - Add rat mode for switching between float64 and rational calculations - Refactor calculator to return Calculation struct with formatting - Add proper version support (v0.3.0) All changes follow Go best practices with comprehensive test coverage.
2026-03-24Update version to v0.3.0Paul Buetow
2026-03-24Remove code duplication between EvalOperator and handleOperator in rpn packagePaul Buetow
- Added executeOperator helper method to handle both standard and hyper operators - Updated handleOperator, EvalOperator, and ResultStack to use executeOperator - Removed handleHyperOperatorWithRegistry method (no longer needed) - Consolidated duplicate operator handling logic into single helper This improves code maintainability by following DRY principle - operator handling logic is now in one place (executeOperator). All tests pass including hyper operator tests. 1 file changed, 23 insertions(+), 28 deletions(-).
2026-03-24Refactor calculator.Parse to make RPN vs percentage parsing boundaries explicitPaul Buetow
- Removed parseRPNFallback from strategy registry - Parse() now only handles percentage calculations (no RPN fallback) - ParseRPN() is now a separate, explicit function for RPN expressions - Added clear documentation explaining Parse() only handles percentages - Removed TestParseRPNFallthrough test (tested implicit RPN fallback) This makes the codebase easier to understand and maintain by having clear boundaries between percentage and RPN parsing. All tests pass. 2 files changed, 1 deletion(-).
2026-03-23Add panic recovery to REPL executor for better resiliencePaul Buetow
Added defer-recover mechanism to the executor function to catch unexpected panics. When a panic occurs, a user-friendly error message is displayed and the REPL can continue to function. This improves the robustness of the REPL when handling unexpected errors.
2026-03-23Refactor rpn.handleOperator to use operator registry instead of switch statementPaul Buetow
Created OperatorRegistry with HandleStandardOperator and HandleHyperOperator methods. Operators are now registered at RPN initialization instead of being handled in switch statements. This makes the code more maintainable and extensible.
2026-03-23Refactor calculator.Parse to use registration pattern for parsing strategiesPaul Buetow
Created ParsingStrategy type and strategyRegistry struct to manage parsing strategies. All parsing strategies are now registered in a registry and executed in sequence. This makes the parsing logic more maintainable and extensible.
2026-03-23Code quality audit fixes from comprehensive auditPaul Buetow
- Error wrapping improvements across multiple files - Thread-safe singleton initialization using sync.Once - Proper error handling for file close operations - Removed speculative complexity in history management - Fixed operator interface design Audit report: COMPLETE_AUDIT_REPORT.md