- go.mod (1.24.2 + initial bubbletea/lipgloss) - Makefile (build, install to ~/.local/bin/gralculator, test, clean; ldflags version injection) - internal/version (ldflags-compatible String()) - main.go stub (version flag + placeholder) - internal/calc/ (Engine skeleton with Base, CycleBase, IsInteger, ErrConversionNotPossible, FormatForDisplay stub + basic tests for CERR path) - internal/ui/ (App model stub with Tab handling placeholder + lipgloss import for future rendering) This establishes the three-phase foundation. Next: flesh out engine (phase 2), then TUI spike (phase 3). Paper trail continues.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package calc
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewEngine_DefaultsToDEC(t *testing.T) {
|
|
e := NewEngine()
|
|
if e.CurrentBase() != BaseDEC {
|
|
t.Errorf("expected DEC, got %s", e.CurrentBase())
|
|
}
|
|
if !e.IsInteger() {
|
|
t.Error("0 should be integer")
|
|
}
|
|
}
|
|
|
|
func TestCycleBase_IntegerOK(t *testing.T) {
|
|
e := NewEngine()
|
|
e.value = 42 // integer
|
|
|
|
if err := e.CycleBase(); err != nil {
|
|
t.Fatalf("unexpected error cycling from integer: %v", err)
|
|
}
|
|
if e.CurrentBase() != BaseHEX {
|
|
t.Errorf("expected HEX after one cycle, got %s", e.CurrentBase())
|
|
}
|
|
}
|
|
|
|
func TestCycleBase_FractionalCERR(t *testing.T) {
|
|
e := NewEngine()
|
|
e.value = 23.0 / 6.0 // 3.8333...
|
|
|
|
err := e.CycleBase()
|
|
if !errors.Is(err, ErrConversionNotPossible) {
|
|
t.Fatalf("expected ErrConversionNotPossible, got %v", err)
|
|
}
|
|
if e.CurrentBase() != BaseDEC {
|
|
t.Error("base must not change on CERR")
|
|
}
|
|
}
|
|
|
|
// TODO (phase 2): more tests for FormatForDisplay (hex/bin/oct of integers),
|
|
// ops, clears, entry, combined fractional + multiple BASE presses, etc.
|