샘플
golang.org/x/text v0.31.0: charmap.ISO8859_1
검증된 샘플 — golang golang.org/x/text v0.31.0: charmap.ISO8859_1. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: charmap.ISO8859_1 has encoding name…
sha256:8254fa1e73515931ca59846d8308f92e3f88190d83d3842ad0eacc1983d9587a
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-10-11 |
케이스
HOW- 목표
- verify golang.org/x/text/encoding/charmap.ISO8859_1 in pkg:golang/golang.org/x/text@v0.31.0
- 심벌
-
- golang.org/x/text/encoding/charmap.ISO8859_1
- 환경
- go 1.26.6
- 생성일
- 2026-10-11T16:32:41Z
컨트랙트
- charmap.ISO8859_1 has encoding name "ISO 8859-1"
- charmap.ISO8859_1 NewEncoder encodes ASCII and Latin-1 Unicode strings into ISO-8859-1 byte slices
- charmap.ISO8859_1 NewDecoder decodes ISO-8859-1 byte slices into UTF-8 strings
- charmap.ISO8859_1 EncodeRune and DecodeByte map valid code points accurately
- charmap.ISO8859_1 detects out-of-repertoire runes and returns errors or replacement byte
- charmap.ISO8859_1 streaming Reader and Writer correctly transform data streams
파일
- 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/charmap.ISO8859_1 in pkg:golang/golang.org/x/text@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/text@v0.31.0
Demonstrate these symbols/APIs:
- golang.org/x/text/encoding/charmap.ISO8859_1
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:cddb5af13bbd37ba45bce576c6fae28da6468b9821617ca0d6616fc02abefdff","contract":["charmap.ISO8859_1 has encoding name \"ISO 8859-1\"","charmap.ISO8859_1 NewEncoder encodes ASCII and Latin-1 Unicode strings into ISO-8859-1 byte slices","charmap.ISO8859_1 NewDecoder decodes ISO-8859-1 byte slices into UTF-8 strings","charmap.ISO8859_1 EncodeRune and DecodeByte map valid code points accurately","charmap.ISO8859_1 detects out-of-repertoire runes and returns errors or replacement byte","charmap.ISO8859_1 streaming Reader and Writer correctly transform data streams"],"goal":"verify golang.org/x/text/encoding/charmap.ISO8859_1 in pkg:golang/golang.org/x/text@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.31.0"],"schemaVersion":1,"symbols":["golang.org/x/text/encoding/charmap.ISO8859_1"]},"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.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.31.0","symbols":["golang.org/x/text/encoding/charmap.ISO8859_1"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require golang.org/x/text v0.31.0
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
package main
import (
"bytes"
"fmt"
"io"
"golang.org/x/text/encoding/charmap"
)
func main() {
// Demonstrating golang.org/x/text/encoding/charmap.ISO8859_1
fmt.Printf("Encoding name: %s\n", charmap.ISO8859_1.String())
// 1. Encoding a UTF-8 string to ISO-8859-1 bytes
encoder := charmap.ISO8859_1.NewEncoder()
text := "Café & Résumé (ASCII + Latin-1)"
encodedBytes, err := encoder.Bytes([]byte(text))
if err != nil {
fmt.Printf("Encoding error: %v\n", err)
return
}
fmt.Printf("Encoded length: %d bytes (raw bytes: %x)\n", len(encodedBytes), encodedBytes)
// 2. Decoding ISO-8859-1 bytes back to UTF-8
decoder := charmap.ISO8859_1.NewDecoder()
decodedText, err := decoder.String(string(encodedBytes))
if err != nil {
fmt.Printf("Decoding error: %v\n", err)
return
}
fmt.Printf("Decoded string: %s\n", decodedText)
// 3. Single rune encoding and byte decoding
r := 'é' // U+00E9
b, ok := charmap.ISO8859_1.EncodeRune(r)
if ok {
fmt.Printf("Rune '%c' encoded to byte 0x%02x\n", r, b)
}
decodedRune := charmap.ISO8859_1.DecodeByte(b)
fmt.Printf("Byte 0x%02x decoded to rune '%c'\n", b, decodedRune)
// 4. Handling unsupported runes outside ISO-8859-1 repertoire
euroRune := '€' // U+20AC is not in ISO 8859-1
euroByte, ok := charmap.ISO8859_1.EncodeRune(euroRune)
fmt.Printf("Euro rune '%c' in ISO-8859-1: ok=%v, byte=0x%02x\n", euroRune, ok, euroByte)
// 5. Streaming conversion using Reader and Writer
isoStream := []byte("Streamed: El Ni\xf1o")
reader := decoder.Reader(bytes.NewReader(isoStream))
streamedResult, err := io.ReadAll(reader)
if err != nil {
fmt.Printf("Stream read error: %v\n", err)
return
}
fmt.Printf("Streamed decoded text: %s\n", string(streamedResult))
var outBuf bytes.Buffer
writer := encoder.Writer(&outBuf)
_, err = writer.Write([]byte("Written stream: Voilà!"))
if err != nil {
fmt.Printf("Stream write error: %v\n", err)
return
}
fmt.Printf("Buffer output length: %d bytes (raw: %x)\n", outBuf.Len(), outBuf.Bytes())
fmt.Println("golang.org/x/text/encoding/charmap.ISO8859_1 demonstration complete.")
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/text/encoding/charmap.ISO8859_1 in pkg:golang/golang.org/x/text@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/text@v0.31.0"
],
"symbols": [
"golang.org/x/text/encoding/charmap.ISO8859_1"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"golang.org/x/text/encoding/charmap"
)
func main() {
// Assertion 1: charmap.ISO8859_1 has encoding name "ISO 8859-1"
{
name := charmap.ISO8859_1.String()
if name != "ISO 8859-1" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected name 'ISO 8859-1', got '%s'\n", name)
os.Exit(1)
}
}
// Assertion 2: charmap.ISO8859_1 NewEncoder encodes ASCII and Latin-1 Unicode strings into ISO-8859-1 byte slices
{
encoder := charmap.ISO8859_1.NewEncoder()
if encoder == nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: NewEncoder returned nil\n")
os.Exit(1)
}
utf8Input := "Café 100%"
expectedBytes := []byte{0x43, 0x61, 0x66, 0xe9, 0x20, 0x31, 0x30, 0x30, 0x25}
encodedBytes, err := encoder.Bytes([]byte(utf8Input))
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: Bytes returned error: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(encodedBytes, expectedBytes) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected %x, got %x\n", expectedBytes, encodedBytes)
os.Exit(1)
}
encodedStr, err := encoder.String(utf8Input)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: String returned error: %v\n", err)
os.Exit(1)
}
if encodedStr != string(expectedBytes) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: String output mismatch\n")
os.Exit(1)
}
}
// Assertion 3: charmap.ISO8859_1 NewDecoder decodes ISO-8859-1 byte slices into UTF-8 strings
{
decoder := charmap.ISO8859_1.NewDecoder()
if decoder == nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: NewDecoder returned nil\n")
os.Exit(1)
}
isoBytes := []byte{0x43, 0x61, 0x66, 0xe9, 0x20, 0x31, 0x30, 0x30, 0x25}
expectedUTF8 := "Café 100%"
decodedBytes, err := decoder.Bytes(isoBytes)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: Bytes returned error: %v\n", err)
os.Exit(1)
}
if string(decodedBytes) != expectedUTF8 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %s, got %s\n", expectedUTF8, string(decodedBytes))
os.Exit(1)
}
decodedStr, err := decoder.String(string(isoBytes))
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: String returned error: %v\n", err)
os.Exit(1)
}
if decodedStr != expectedUTF8 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %s, got %s\n", expectedUTF8, decodedStr)
os.Exit(1)
}
}
// Assertion 4: charmap.ISO8859_1 EncodeRune and DecodeByte map valid code points accurately
{
testCases := []struct {
r rune
b byte
}{
{'A', 0x41},
{'~', 0x7e},
{'©', 0xa9},
{'é', 0xe9},
{'ü', 0xfc},
{'ÿ', 0xff},
}
for _, tc := range testCases {
b, ok := charmap.ISO8859_1.EncodeRune(tc.r)
if !ok {
fmt.Fprintf(os.Stderr, "assertion 4 failed: EncodeRune('%c') reported ok=false\n", tc.r)
os.Exit(1)
}
if b != tc.b {
fmt.Fprintf(os.Stderr, "assertion 4 failed: EncodeRune('%c') expected 0x%02x, got 0x%02x\n", tc.r, tc.b, b)
os.Exit(1)
}
decRune := charmap.ISO8859_1.DecodeByte(tc.b)
if decRune != tc.r {
fmt.Fprintf(os.Stderr, "assertion 4 failed: DecodeByte(0x%02x) expected '%c', got '%c'\n", tc.b, tc.r, decRune)
os.Exit(1)
}
}
}
// Assertion 5: charmap.ISO8859_1 detects out-of-repertoire runes and returns errors or replacement byte
{
euro := '€' // U+20AC is not in ISO 8859-1
b, ok := charmap.ISO8859_1.EncodeRune(euro)
if ok {
fmt.Fprintf(os.Stderr, "assertion 5 failed: EncodeRune('%c') should report ok=false\n", euro)
os.Exit(1)
}
if b != 0x1a {
fmt.Fprintf(os.Stderr, "assertion 5 failed: EncodeRune('%c') replacement byte expected 0x1a, got 0x%02x\n", euro, b)
os.Exit(1)
}
encoder := charmap.ISO8859_1.NewEncoder()
_, err := encoder.Bytes([]byte("Price: 10€"))
if err == nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected error encoding out-of-repertoire rune '€'\n")
os.Exit(1)
}
}
// Assertion 6: charmap.ISO8859_1 streaming Reader and Writer correctly transform data streams
{
isoBytes := []byte{0xe9, 0xfc} // "éü" in ISO-8859-1
reader := charmap.ISO8859_1.NewDecoder().Reader(bytes.NewReader(isoBytes))
streamedUTF8, err := io.ReadAll(reader)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Reader read error: %v\n", err)
os.Exit(1)
}
if string(streamedUTF8) != "éü" {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Reader output expected 'éü', got '%s'\n", string(streamedUTF8))
os.Exit(1)
}
var buf bytes.Buffer
writer := charmap.ISO8859_1.NewEncoder().Writer(&buf)
n, err := writer.Write([]byte("éü"))
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Writer write error: %v\n", err)
os.Exit(1)
}
if n != len([]byte("éü")) {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Writer returned n=%d, expected %d\n", n, len([]byte("éü")))
os.Exit(1)
}
if !bytes.Equal(buf.Bytes(), isoBytes) {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Writer output expected %x, got %x\n", isoBytes, buf.Bytes())
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
오리진 시더
익명