Exemplo
golang.org/x/text v0.42.0: encoding.Encoder
Amostra verificada para golang golang.org/x/text v0.42.0: encoding.Encoder. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.
sha256:dd635ac30956af4d217601e8f5d50e769cd0b335fba31b2dd1edfbb33c5cd520
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-15 |
Caso
HOW- Objetivo
- verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0
- Pacotes
- Símbolos
-
- golang.org/x/text/encoding.Encoder
- Ambiente
- go 1.26.6
- Criado
- 2026-09-15T23:15:35Z
Contrato
- Encoder.String transcodes valid UTF-8 strings into the target character encoding
- Encoder.Bytes transcodes valid UTF-8 byte slices into target encoding bytes
- Encoder returns an error when encountering characters unrepresentable in the target encoding
- ReplaceUnsupported wraps Encoder to substitute unrepresentable characters with encoding replacement
- HTMLEscapeUnsupported wraps Encoder to replace unrepresentable characters with HTML decimal entities
- Encoder.Writer wraps an io.Writer to transcode streaming UTF-8 bytes to the target encoding
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código-fonte
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 golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/text@v0.42.0
Demonstrate these symbols/APIs:
- golang.org/x/text/encoding.Encoder
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:624274d8d8eb6c72b5887e0243779d8eb9c8ed5ecf5b4ff68e89a5a440fb9872","contract":["Encoder.String transcodes valid UTF-8 strings into the target character encoding","Encoder.Bytes transcodes valid UTF-8 byte slices into target encoding bytes","Encoder returns an error when encountering characters unrepresentable in the target encoding","ReplaceUnsupported wraps Encoder to substitute unrepresentable characters with encoding replacement","HTMLEscapeUnsupported wraps Encoder to replace unrepresentable characters with HTML decimal entities","Encoder.Writer wraps an io.Writer to transcode streaming UTF-8 bytes to the target encoding"],"goal":"verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.42.0"],"schemaVersion":1,"symbols":["golang.org/x/text/encoding.Encoder"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/text@v0.42.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.42.0","symbols":["golang.org/x/text/encoding.Encoder"],"verifierAdapter":"golang@1"}
module sample
go 1.26.0
require golang.org/x/text v0.42.0
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
package main
import (
"bytes"
"fmt"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
)
func main() {
// Standard ISO-8859-1 encoder
enc := charmap.ISO8859_1.NewEncoder()
// 1. Transform string
encodedStr, err := enc.String("Café")
if err != nil {
fmt.Printf("Encoding error: %v\n", err)
return
}
fmt.Printf("Encoded string bytes: % x\n", []byte(encodedStr))
// 2. Transform bytes
encodedBytes, err := enc.Bytes([]byte("Resumé"))
if err != nil {
fmt.Printf("Encoding error: %v\n", err)
return
}
fmt.Printf("Encoded bytes: % x\n", encodedBytes)
// 3. Handling unsupported characters with HTML escaping
htmlEnc := encoding.HTMLEscapeUnsupported(charmap.ISO8859_1.NewEncoder())
escaped, err := htmlEnc.String("Euro sign: €")
if err != nil {
fmt.Printf("HTML escape error: %v\n", err)
return
}
fmt.Printf("HTML escaped: %s\n", escaped)
// 4. Writer streaming
var buf bytes.Buffer
w := enc.Writer(&buf)
_, _ = w.Write([]byte("Naïve"))
fmt.Printf("Stream encoded: % x\n", buf.Bytes())
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/text@v0.42.0"
],
"symbols": [
"golang.org/x/text/encoding.Encoder"
]
}
package main
import (
"bytes"
"fmt"
"os"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
)
func main() {
if err := runContract(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: all contract assertions satisfied")
}
func runContract() error {
// 1. Encoder.String transcodes valid UTF-8 strings into the target character encoding
{
enc := charmap.ISO8859_1.NewEncoder()
res, err := enc.String("Café")
if err != nil {
return fmt.Errorf("Encoder.String returned unexpected error: %w", err)
}
expected := "Caf\xe9"
if res != expected {
return fmt.Errorf("Encoder.String got %q, want %q", res, expected)
}
}
// 2. Encoder.Bytes transcodes valid UTF-8 byte slices into target encoding bytes
{
enc := charmap.ISO8859_1.NewEncoder()
src := []byte("Naïve")
res, err := enc.Bytes(src)
if err != nil {
return fmt.Errorf("Encoder.Bytes returned unexpected error: %w", err)
}
expected := []byte{'N', 'a', 0xef, 'v', 'e'}
if !bytes.Equal(res, expected) {
return fmt.Errorf("Encoder.Bytes got %v, want %v", res, expected)
}
}
// 3. Encoder returns an error when encountering characters unrepresentable in the target encoding
{
enc := charmap.ISO8859_1.NewEncoder()
_, err := enc.String("Hello 日本語")
if err == nil {
return fmt.Errorf("Encoder.String expected error on unrepresentable runes, got nil")
}
}
// 4. ReplaceUnsupported wraps Encoder to substitute unrepresentable characters with encoding replacement
{
baseEnc := charmap.ISO8859_1.NewEncoder()
repEnc := encoding.ReplaceUnsupported(baseEnc)
res, err := repEnc.String("A 日本 B")
if err != nil {
return fmt.Errorf("ReplaceUnsupported Encoder returned unexpected error: %w", err)
}
// ISO-8859-1 replacement character is SUB (0x1a)
expected := "A \x1a\x1a B"
if res != expected {
return fmt.Errorf("ReplaceUnsupported Encoder got %q (%+v), want %q", res, []byte(res), expected)
}
}
// 5. HTMLEscapeUnsupported wraps Encoder to replace unrepresentable characters with HTML decimal entities
{
baseEnc := charmap.ISO8859_1.NewEncoder()
htmlEnc := encoding.HTMLEscapeUnsupported(baseEnc)
res, err := htmlEnc.String("Price: €5")
if err != nil {
return fmt.Errorf("HTMLEscapeUnsupported Encoder returned unexpected error: %w", err)
}
expected := "Price: €5"
if res != expected {
return fmt.Errorf("HTMLEscapeUnsupported Encoder got %q, want %q", res, expected)
}
}
// 6. Encoder.Writer wraps an io.Writer to transcode streaming UTF-8 bytes to the target encoding
{
enc := charmap.ISO8859_1.NewEncoder()
var buf bytes.Buffer
w := enc.Writer(&buf)
n, err := w.Write([]byte("Café"))
if err != nil {
return fmt.Errorf("Encoder.Writer Write returned unexpected error: %w", err)
}
if n == 0 {
return fmt.Errorf("Encoder.Writer Write wrote 0 bytes")
}
expected := []byte{'C', 'a', 'f', 0xe9}
if !bytes.Equal(buf.Bytes(), expected) {
return fmt.Errorf("Encoder.Writer output got %v, want %v", buf.Bytes(), expected)
}
}
return nil
}
Seeder de origem
anônimo