Sample
github.com/spf13/cast v1.10.0: ToBool, ToBoolE
Verified sample for golang github.com/spf13/cast v1.10.0: ToBool, ToBoolE. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:4f435db88c3ec103ae8ff8fa1d255f6bc6d5d04fb8bdf2b87cb28470247fe8e4
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-06 |
Case
HOW- Goal
- verify pkg:golang/github.com/spf13/cast@v1.10.0
- Packages
- Symbols
-
- cast.ToBool
- cast.ToBoolE
- Created
- 2026-09-06T16:29:49Z
Contract
- cast.ToBool preserves boolean values true and false
- cast.ToBool and cast.ToBoolE parse truthy and falsy strings into boolean values
- cast.ToBool converts numeric values 1 to true and 0 to false
- cast.ToBool returns false and cast.ToBoolE returns false with nil error for nil values
- cast.ToBool unwraps pointer values before converting their underlying values to bool
- cast.ToBool returns false and cast.ToBoolE returns an error for unsupported types and invalid strings
- ToBool converts the given value to a bool using cast.ToBool
Files
- PROMPT.md
- cast_bool.go
- contract_test.go
- csx.json
- go.mod
- go.sum
- spec.json
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:golang/github.com/spf13/cast@v1.10.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/spf13/cast@v1.10.0
Demonstrate these symbols/APIs:
- cast.ToBool
- cast.ToBoolE
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
package sample
import (
"github.com/spf13/cast"
)
// ToBool converts an arbitrary value to a boolean using cast.ToBool.
// It returns false if conversion cannot be performed.
func ToBool(v any) bool {
return cast.ToBool(v)
}
// ToBoolE converts an arbitrary value to a boolean using cast.ToBoolE,
// returning an error if conversion cannot be performed.
func ToBoolE(v any) (bool, error) {
return cast.ToBoolE(v)
}
package sample
import (
"testing"
"github.com/spf13/cast"
)
func TestToBool_Booleans(t *testing.T) {
if got := cast.ToBool(true); got != true {
t.Fatalf("cast.ToBool(true) = %v; want true", got)
}
if got := cast.ToBool(false); got != false {
t.Fatalf("cast.ToBool(false) = %v; want false", got)
}
}
func TestToBool_Strings(t *testing.T) {
truthy := []string{"true", "True", "TRUE", "t", "T", "1"}
for _, s := range truthy {
if got := cast.ToBool(s); got != true {
t.Fatalf("cast.ToBool(%q) = %v; want true", s, got)
}
val, err := cast.ToBoolE(s)
if err != nil || val != true {
t.Fatalf("cast.ToBoolE(%q) = (%v, %v); want (true, nil)", s, val, err)
}
}
falsy := []string{"false", "False", "FALSE", "f", "F", "0"}
for _, s := range falsy {
if got := cast.ToBool(s); got != false {
t.Fatalf("cast.ToBool(%q) = %v; want false", s, got)
}
val, err := cast.ToBoolE(s)
if err != nil || val != false {
t.Fatalf("cast.ToBoolE(%q) = (%v, %v); want (false, nil)", s, val, err)
}
}
}
func TestToBool_NumericValues(t *testing.T) {
if got := cast.ToBool(1); got != true {
t.Fatalf("cast.ToBool(1) = %v; want true", got)
}
if got := cast.ToBool(0); got != false {
t.Fatalf("cast.ToBool(0) = %v; want false", got)
}
if got := cast.ToBool(int8(1)); got != true {
t.Fatalf("cast.ToBool(int8(1)) = %v; want true", got)
}
if got := cast.ToBool(int8(0)); got != false {
t.Fatalf("cast.ToBool(int8(0)) = %v; want false", got)
}
if got := cast.ToBool(int16(1)); got != true {
t.Fatalf("cast.ToBool(int16(1)) = %v; want true", got)
}
if got := cast.ToBool(int16(0)); got != false {
t.Fatalf("cast.ToBool(int16(0)) = %v; want false", got)
}
if got := cast.ToBool(int32(1)); got != true {
t.Fatalf("cast.ToBool(int32(1)) = %v; want true", got)
}
if got := cast.ToBool(int32(0)); got != false {
t.Fatalf("cast.ToBool(int32(0)) = %v; want false", got)
}
if got := cast.ToBool(int64(1)); got != true {
t.Fatalf("cast.ToBool(int64(1)) = %v; want true", got)
}
if got := cast.ToBool(int64(0)); got != false {
t.Fatalf("cast.ToBool(int64(0)) = %v; want false", got)
}
if got := cast.ToBool(uint(1)); got != true {
t.Fatalf("cast.ToBool(uint(1)) = %v; want true", got)
}
if got := cast.ToBool(uint(0)); got != false {
t.Fatalf("cast.ToBool(uint(0)) = %v; want false", got)
}
if got := cast.ToBool(float32(1.0)); got != true {
t.Fatalf("cast.ToBool(float32(1.0)) = %v; want true", got)
}
if got := cast.ToBool(float32(0.0)); got != false {
t.Fatalf("cast.ToBool(float32(0.0)) = %v; want false", got)
}
if got := cast.ToBool(1.0); got != true {
t.Fatalf("cast.ToBool(1.0) = %v; want true", got)
}
if got := cast.ToBool(0.0); got != false {
t.Fatalf("cast.ToBool(0.0) = %v; want false", got)
}
}
func TestToBool_Nil(t *testing.T) {
if got := cast.ToBool(nil); got != false {
t.Fatalf("cast.ToBool(nil) = %v; want false", got)
}
val, err := cast.ToBoolE(nil)
if err != nil || val != false {
t.Fatalf("cast.ToBoolE(nil) = (%v, %v); want (false, nil)", val, err)
}
}
func TestToBool_Pointers(t *testing.T) {
bTrue := true
if got := cast.ToBool(&bTrue); got != true {
t.Fatalf("cast.ToBool(&bTrue) = %v; want true", got)
}
bFalse := false
if got := cast.ToBool(&bFalse); got != false {
t.Fatalf("cast.ToBool(&bFalse) = %v; want false", got)
}
sTrue := "true"
if got := cast.ToBool(&sTrue); got != true {
t.Fatalf("cast.ToBool(&sTrue) = %v; want true", got)
}
sFalse := "0"
if got := cast.ToBool(&sFalse); got != false {
t.Fatalf("cast.ToBool(&sFalse) = %v; want false", got)
}
nOne := 1
if got := cast.ToBool(&nOne); got != true {
t.Fatalf("cast.ToBool(&nOne) = %v; want true", got)
}
nZero := 0
if got := cast.ToBool(&nZero); got != false {
t.Fatalf("cast.ToBool(&nZero) = %v; want false", got)
}
}
func TestToBool_InvalidAndUnsupported(t *testing.T) {
invalidCases := []any{
"not_a_boolean",
[]int{1, 2, 3},
map[string]bool{"a": true},
struct{}{},
}
for _, c := range invalidCases {
if got := cast.ToBool(c); got != false {
t.Fatalf("cast.ToBool(%v) = %v; want false", c, got)
}
if _, err := cast.ToBoolE(c); err == nil {
t.Fatalf("cast.ToBoolE(%v) expected error, got nil", c)
}
}
}
func TestToBool_Helper(t *testing.T) {
cases := []struct {
input any
expected bool
}{
{"true", true},
{"false", false},
{1, true},
{0, false},
{nil, false},
}
for _, c := range cases {
if got := ToBool(c.input); got != c.expected {
t.Fatalf("ToBool(%v) = %v; want %v", c.input, got, c.expected)
}
val, err := ToBoolE(c.input)
if err != nil || val != c.expected {
t.Fatalf("ToBoolE(%v) = (%v, %v); want (%v, nil)", c.input, val, err, c.expected)
}
}
}
{"case":{"caseId":"case:sha256:99f25d337615aea7e278a885d075be124a63cf5c643fa20ee5bde16cbf314837","contract":["cast.ToBool preserves boolean values true and false","cast.ToBool and cast.ToBoolE parse truthy and falsy strings into boolean values","cast.ToBool converts numeric values 1 to true and 0 to false","cast.ToBool returns false and cast.ToBoolE returns false with nil error for nil values","cast.ToBool unwraps pointer values before converting their underlying values to bool","cast.ToBool returns false and cast.ToBoolE returns an error for unsupported types and invalid strings","ToBool converts the given value to a bool using cast.ToBool"],"goal":"verify pkg:golang/github.com/spf13/cast@v1.10.0","kind":"HOW","packages":["pkg:golang/github.com/spf13/cast@v1.10.0"],"schemaVersion":1,"symbols":["cast.ToBool","cast.ToBoolE"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/spf13/cast@v1.10.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/spf13/cast@v1.10.0","symbols":["cast.ToBool","cast.ToBoolE"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/spf13/cast v1.10.0
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/spf13/cast@v1.10.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/spf13/cast@v1.10.0"
],
"symbols": [
"cast.ToBool",
"cast.ToBoolE"
]
}
Origin Seeder
anonymous