示例
golang.org/x/text v0.16.0
已验证示例 — golang golang.org/x/text v0.16.0. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: cases.Title and cases.Upper apply locale-sensitive title and…
sha256:c8ab656318f60ad8001c293b1aab5bdb7dc206f67d2e123302823beea958da09
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-14 |
案例
HOW- 目标
- verify pkg:golang/golang.org/x/text@v0.16.0
- 创建时间
- 2026-09-14T19:21:42Z
契约
- cases.Title and cases.Upper apply locale-sensitive title and uppercase transformations according to language tags
- language.Match and language.Parse parse BCP 47 tags and select best matching supported language
- norm.NFC and norm.NFD normalize unicode text into canonical composition and decomposition forms
- width.Fold transforms fullwidth characters into standard halfwidth ASCII equivalents
- runes.Map and transform.String transform rune sequences according to custom mapping functions
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
源代码
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/golang.org/x/text@v0.16.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/text@v0.16.0
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.
{"case":{"caseId":"case:sha256:2f90e9aa0fe79cfedc05177cb4686c22e73c33daba69b02abe69d029660b1d68","contract":["cases.Title and cases.Upper apply locale-sensitive title and uppercase transformations according to language tags","language.Match and language.Parse parse BCP 47 tags and select best matching supported language","norm.NFC and norm.NFD normalize unicode text into canonical composition and decomposition forms","width.Fold transforms fullwidth characters into standard halfwidth ASCII equivalents","runes.Map and transform.String transform rune sequences according to custom mapping functions"],"goal":"verify pkg:golang/golang.org/x/text@v0.16.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.16.0"],"schemaVersion":1},"contractCommand":["go","run","./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/golang.org/x/text@v0.16.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.16.0","verifierAdapter":"golang@1"}
module example.com/sample
go 1.22
require golang.org/x/text v0.16.0
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
package main
import (
"fmt"
"os"
"unicode"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"golang.org/x/text/width"
)
// CasingService demonstrates locale-sensitive text casing.
type CasingService struct {
titleCaser cases.Caser
upperCaser cases.Caser
}
// NewCasingService creates a CasingService configured for the specified language tag.
func NewCasingService(tag language.Tag) CasingService {
return CasingService{
titleCaser: cases.Title(tag),
upperCaser: cases.Upper(tag),
}
}
// ToTitle converts text to title case using the service's locale.
func (s CasingService) ToTitle(input string) string {
return s.titleCaser.String(input)
}
// ToUpper converts text to upper case using the service's locale.
func (s CasingService) ToUpper(input string) string {
return s.upperCaser.String(input)
}
// MatchBestLanguage matches user preference against supported server languages.
func MatchBestLanguage(preferred string, supported []language.Tag) language.Tag {
matcher := language.NewMatcher(supported)
userTag, _ := language.Parse(preferred)
matchedTag, _, _ := matcher.Match(userTag)
return matchedTag
}
// NormalizeText applies Unicode NFC or NFD normalization.
func NormalizeText(input string, form norm.Form) string {
return form.String(input)
}
// NormalizeWidth converts fullwidth forms to standard ASCII/halfwidth width.
func NormalizeWidth(input string) string {
return width.Fold.String(input)
}
// MapRunes applies a custom transformation to runes in the input string.
func MapRunes(input string, mapping func(rune) rune) (string, error) {
t := runes.Map(mapping)
result, _, err := transform.String(t, input)
return result, err
}
func main() {
enService := NewCasingService(language.AmericanEnglish)
fmt.Printf("Title (EN): %s\n", enService.ToTitle("the lord of the rings"))
trService := NewCasingService(language.Turkish)
fmt.Printf("Upper (TR): %s\n", trService.ToUpper("istanbul"))
supported := []language.Tag{language.English, language.French, language.German, language.Japanese}
matched := MatchBestLanguage("fr-CA,fr;q=0.9,en;q=0.8", supported)
fmt.Printf("Matched language: %s\n", matched)
decomposed := "e\u0301"
composed := NormalizeText(decomposed, norm.NFC)
fmt.Printf("NFC Composed: %s\n", composed)
fullwidth := "Hello 123!"
halfwidth := NormalizeWidth(fullwidth)
fmt.Printf("Width folded: %s\n", halfwidth)
upperMapped, err := MapRunes("hello world", unicode.ToUpper)
if err != nil {
fmt.Fprintf(os.Stderr, "Rune mapping error: %v\n", err)
os.Exit(1)
}
fmt.Printf("Mapped runes: %s\n", upperMapped)
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/text@v0.16.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/text@v0.16.0"
]
}
package main
import (
"fmt"
"os"
"unicode"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"golang.org/x/text/width"
)
func main() {
// Assertion 1: cases.Title and cases.Upper apply locale-sensitive title and uppercase transformations according to language tags
enTitle := cases.Title(language.AmericanEnglish).String("the lord of the rings")
if enTitle != "The Lord Of The Rings" {
fmt.Fprintf(os.Stderr, "FAIL: cases.Title mismatch: got %q\n", enTitle)
os.Exit(1)
}
trUpper := cases.Upper(language.Turkish).String("istanbul")
if trUpper != "İSTANBUL" {
fmt.Fprintf(os.Stderr, "FAIL: cases.Upper Turkish mismatch: got %q\n", trUpper)
os.Exit(1)
}
// Assertion 2: language.Match and language.Parse parse BCP 47 tags and select best matching supported language
supported := []language.Tag{language.English, language.French, language.German}
matcher := language.NewMatcher(supported)
prefTag, err := language.Parse("fr")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: language.Parse failed: %v\n", err)
os.Exit(1)
}
matchedTag, _, confidence := matcher.Match(prefTag)
if matchedTag != language.French || confidence == language.No {
fmt.Fprintf(os.Stderr, "FAIL: language.Match unexpected result: tag=%v, confidence=%v\n", matchedTag, confidence)
os.Exit(1)
}
// Assertion 3: norm.NFC and norm.NFD normalize unicode text into canonical composition and decomposition forms
decomposed := "e\u0301" // e + combining acute accent (len 3 in UTF-8)
composed := norm.NFC.String(decomposed)
if composed != "é" || len(composed) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: norm.NFC composition failed: got %q (len %d)\n", composed, len(composed))
os.Exit(1)
}
reDecomposed := norm.NFD.String(composed)
if reDecomposed != decomposed || len(reDecomposed) != 3 {
fmt.Fprintf(os.Stderr, "FAIL: norm.NFD decomposition failed: got %q (len %d)\n", reDecomposed, len(reDecomposed))
os.Exit(1)
}
// Assertion 4: width.Fold transforms fullwidth characters into standard halfwidth ASCII equivalents
fullwidth := "Hello 123!"
folded := width.Fold.String(fullwidth)
expectedFolded := "Hello 123!"
if folded != expectedFolded {
fmt.Fprintf(os.Stderr, "FAIL: width.Fold mismatch: got %q, expected %q\n", folded, expectedFolded)
os.Exit(1)
}
// Assertion 5: runes.Map and transform.String transform rune sequences according to custom mapping functions
mappingTransformer := runes.Map(func(r rune) rune {
if unicode.IsLower(r) {
return unicode.ToUpper(r)
}
return r
})
mappedResult, _, err := transform.String(mappingTransformer, "hello-world-123")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: transform.String with runes.Map returned error: %v\n", err)
os.Exit(1)
}
if mappedResult != "HELLO-WORLD-123" {
fmt.Fprintf(os.Stderr, "FAIL: runes.Map result mismatch: got %q\n", mappedResult)
os.Exit(1)
}
fmt.Println("PASS: pkg:golang/golang.org/x/text@v0.16.0 contract verified")
}
原始种子者
匿名