Starting on UI. Coverage no longer 100% :c

This commit is contained in:
Madison Rye Progress
2026-03-18 22:05:07 -07:00
parent bbc87afee1
commit bbbcebc79c
10 changed files with 313 additions and 73 deletions

View File

@ -1,6 +1,7 @@
package state
import (
"errors"
"regexp"
"testing"
@ -31,8 +32,9 @@ func TestHistory(t *testing.T) {
})
Convey("You can load a game from its saved history", func() {
history := "g(2,2)i(0,0)oxoxi(1,0)xoxoi(0,1)ooooi(1,1)xxxxfRmDcLUrldu"
s := UnmarshalAll(history)
history := "g(2,2)i(0,0)oxoxi(1,0)xoxoi(0,1)ooooi(1,1)xxxx\n# Here we goooo~\nfRmDcLUrldut(1773881959)"
s, err := UnmarshalAll(history)
So(err, ShouldBeNil)
Convey("It sets the history", func() {
So(s.History(), ShouldEqual, history)
@ -53,5 +55,44 @@ func TestHistory(t *testing.T) {
So(s.String(), ShouldEqual, "X. \n \no .\n....\n")
})
})
Convey("Errors are handled during loading", func() {
Convey("It raises errors if acting on an uninitialized state", func() {
s, err := UnmarshalAll("m")
So(err, ShouldResemble, errors.New("tried to act on an uninitialized state (index 0)"))
So(s, ShouldBeNil)
})
Convey("It raises errors if trying to initialize an initialized state", func() {
s, err := UnmarshalAll("g(1,1)g(1,1)")
So(err, ShouldResemble, errors.New("initialization step in invalid location (index 6)"))
So(s, ShouldBeNil)
})
Convey("It raises errors in reading points", func() {
s, err := UnmarshalAll("g(1")
So(err, ShouldResemble, errors.New("point.X never ended? (index 3)"))
So(s, ShouldBeNil)
s, err = UnmarshalAll("g(a,1)")
So(err, ShouldResemble, errors.New("invalid character in point.X: a (index 2)"))
So(s, ShouldBeNil)
s, err = UnmarshalAll("g(1,1)i(0,1")
So(err, ShouldResemble, errors.New("point.Y never ended? (index 11)"))
So(s, ShouldBeNil)
s, err = UnmarshalAll("g(1,a)")
So(err, ShouldResemble, errors.New("invalid character in point.Y: a (index 4)"))
So(s, ShouldBeNil)
})
Convey("It only accepts valid steps", func() {
history := "g(2,2)i(0,0)oxoxi(1,0)xoxoi(0,1)ooooi(1,1)xxxxz"
s, err := UnmarshalAll(history)
So(err, ShouldResemble, errors.New("invalid step in history: z (index 46)"))
So(s, ShouldBeNil)
})
})
})
}