샘플
golang.org/x/text v0.42.0: encoding.Encoder
검증된 샘플 — golang golang.org/x/text v0.42.0: encoding.Encoder. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Encoder.String transcodes valid…
sha256:dd635ac30956af4d217601e8f5d50e769cd0b335fba31b2dd1edfbb33c5cd520
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify golang.org/x/text/encoding.Encoder in pkg:golang/golang.org/x/text@v0.42.0
- 심벌
-
- golang.org/x/text/encoding.Encoder
- 환경
- go 1.26.6
- 생성일
- 2026-09-15T23:15:35Z
컨트랙트
- 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
파일
- 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 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
}
오리진 시더
익명