package snake import java.nio.file.{Files, Paths} /** Loads shared fixtures from ../fixtures/.json. * Typed decoders (point, direction, status, action, state, opt) arrive with the model (Task 11). */ object Fixtures: private val dir = Paths.get(sys.props.getOrElse("user.dir", ".")).resolve("..").resolve("fixtures").normalize def load(name: String): ujson.Value = ujson.read(Files.readString(dir.resolve(s"$name.json"))) /** The cases array of a fixture. */ def cases(name: String): Seq[ujson.Value] = load(name)("cases").arr.toSeq /** Decode a nullable JSON value into an Option. */ def opt[A](v: ujson.Value)(f: ujson.Value => A): Option[A] = if v.isNull then None else Some(f(v))