Пример
golang.org/x/text v0.31.0: charmap.Windows1252
Проверенный пример — golang golang.org/x/text v0.31.0: charmap.Windows1252. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:e24e7b3d1bdbc80d454f8aba21bd323e72593577c16c17c72b9deae4bbe6cb5c
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
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.Windows1252 in pkg:golang/golang.org/x/text@v0.31.0
- Пакеты
- Символы
-
- golang.org/x/text/encoding/charmap.Windows1252
- Окружение
- go 1.26.6
- Создан
- 2026-10-11T13:54:32Z
Контракт
- charmap.Windows1252 is an encoding whose String method returns "Windows 1252"
- charmap.Windows1252 NewEncoder encodes valid Unicode characters into Windows-1252 bytes and NewDecoder decodes them back to UTF-8
- charmap.Windows1252 EncodeRune correctly encodes Windows-1252 specific runes such as Euro sign and reports unsupported runes
- charmap.Windows1252 DecodeByte maps single Windows-1252 bytes to their corresponding Unicode runes
- charmap.Windows1252 NewDecoder Reader wraps an io.Reader and decodes Windows-1252 byte streams to UTF-8
Файлы
- 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.Windows1252 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.Windows1252
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:534cbd4bfcc2716e6664d4b9eb9e40fc91367f5c6b0758ba51142296cb886795","contract":["charmap.Windows1252 is an encoding whose String method returns \"Windows 1252\"","charmap.Windows1252 NewEncoder encodes valid Unicode characters into Windows-1252 bytes and NewDecoder decodes them back to UTF-8","charmap.Windows1252 EncodeRune correctly encodes Windows-1252 specific runes such as Euro sign and reports unsupported runes","charmap.Windows1252 DecodeByte maps single Windows-1252 bytes to their corresponding Unicode runes","charmap.Windows1252 NewDecoder Reader wraps an io.Reader and decodes Windows-1252 byte streams to UTF-8"],"goal":"verify golang.org/x/text/encoding/charmap.Windows1252 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.Windows1252"]},"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.Windows1252"],"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"
"strings"
"golang.org/x/text/encoding/charmap"
)
func main() {
// 1. Basic encoding and decoding with Windows1252
text := "Cost: 50 € (Special discount: © 2026)"
encoder := charmap.Windows1252.NewEncoder()
encodedBytes, err := encoder.Bytes([]byte(text))
if err != nil {
fmt.Printf("Encoding error: %v\n", err)
return
}
fmt.Printf("Encoded bytes length: %d\n", len(encodedBytes))
decoder := charmap.Windows1252.NewDecoder()
decodedText, err := decoder.String(string(encodedBytes))
if err != nil {
fmt.Printf("Decoding error: %v\n", err)
return
}
fmt.Printf("Decoded text: %s\n", decodedText)
// 2. Direct byte and rune conversion
euroRune := charmap.Windows1252.DecodeByte(0x80)
fmt.Printf("Byte 0x80 decoded as rune: %c (U+%04X)\n", euroRune, euroRune)
encodedEuro, ok := charmap.Windows1252.EncodeRune('€')
fmt.Printf("Rune '€' encoded to byte: 0x%02X (supported: %t)\n", encodedEuro, ok)
// 3. Streaming decoding using io.Reader
streamInput := []byte{0x50, 0x72, 0x69, 0x63, 0x65, 0x3a, 0x20, 0x80} // "Price: " + 0x80
reader := decoder.Reader(bytes.NewReader(streamInput))
streamOutput, err := io.ReadAll(reader)
if err != nil {
fmt.Printf("Stream read error: %v\n", err)
return
}
fmt.Printf("Stream decoded: %s\n", string(streamOutput))
// 4. Streaming encoding using io.Writer
var buf bytes.Buffer
writer := encoder.Writer(&buf)
_, err = io.Copy(writer, strings.NewReader("Euro symbol: €"))
if err != nil {
fmt.Printf("Stream write error: %v\n", err)
return
}
fmt.Printf("Stream encoded bytes: % x\n", buf.Bytes())
fmt.Println("golang.org/x/text/encoding/charmap.Windows1252 demonstrated successfully.")
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/text/encoding/charmap.Windows1252 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.Windows1252"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"strings"
"golang.org/x/text/encoding/charmap"
)
func main() {
// Assertion 1: charmap.Windows1252 is an encoding whose String method returns "Windows 1252"
{
name := charmap.Windows1252.String()
if name != "Windows 1252" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected 'Windows 1252', got %q\n", name)
os.Exit(1)
}
}
// Assertion 2: charmap.Windows1252 NewEncoder encodes valid Unicode characters into Windows-1252 bytes and NewDecoder decodes them back to UTF-8
{
encoder := charmap.Windows1252.NewEncoder()
decoder := charmap.Windows1252.NewDecoder()
if encoder == nil || decoder == nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: NewEncoder or NewDecoder returned nil\n")
os.Exit(1)
}
original := "Invoice total: 125 € — Copyright © 2026"
encoded, err := encoder.String(original)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: encode failed: %v\n", err)
os.Exit(1)
}
decoded, err := decoder.String(encoded)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: decode failed: %v\n", err)
os.Exit(1)
}
if decoded != original {
fmt.Fprintf(os.Stderr, "assertion 2 failed: round-trip mismatch: got %q, want %q\n", decoded, original)
os.Exit(1)
}
}
// Assertion 3: charmap.Windows1252 EncodeRune correctly encodes Windows-1252 specific runes such as Euro sign and reports unsupported runes
{
euroByte, ok := charmap.Windows1252.EncodeRune('€')
if !ok || euroByte != 0x80 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: EncodeRune('€') expected (0x80, true), got (0x%02X, %t)\n", euroByte, ok)
os.Exit(1)
}
copyByte, ok := charmap.Windows1252.EncodeRune('©')
if !ok || copyByte != 0xA9 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: EncodeRune('©') expected (0xA9, true), got (0x%02X, %t)\n", copyByte, ok)
os.Exit(1)
}
asciiByte, ok := charmap.Windows1252.EncodeRune('Z')
if !ok || asciiByte != 'Z' {
fmt.Fprintf(os.Stderr, "assertion 3 failed: EncodeRune('Z') expected ('Z', true), got (0x%02X, %t)\n", asciiByte, ok)
os.Exit(1)
}
_, ok = charmap.Windows1252.EncodeRune('한')
if ok {
fmt.Fprintf(os.Stderr, "assertion 3 failed: EncodeRune unsupported rune should return ok=false\n")
os.Exit(1)
}
}
// Assertion 4: charmap.Windows1252 DecodeByte maps single Windows-1252 bytes to their corresponding Unicode runes
{
r1 := charmap.Windows1252.DecodeByte(0x80)
if r1 != '€' {
fmt.Fprintf(os.Stderr, "assertion 4 failed: DecodeByte(0x80) expected '€', got %c\n", r1)
os.Exit(1)
}
r2 := charmap.Windows1252.DecodeByte(0xA9)
if r2 != '©' {
fmt.Fprintf(os.Stderr, "assertion 4 failed: DecodeByte(0xA9) expected '©', got %c\n", r2)
os.Exit(1)
}
r3 := charmap.Windows1252.DecodeByte('A')
if r3 != 'A' {
fmt.Fprintf(os.Stderr, "assertion 4 failed: DecodeByte('A') expected 'A', got %c\n", r3)
os.Exit(1)
}
}
// Assertion 5: charmap.Windows1252 NewDecoder Reader wraps an io.Reader and decodes Windows-1252 byte streams to UTF-8
{
raw := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x80}
wrappedReader := charmap.Windows1252.NewDecoder().Reader(bytes.NewReader(raw))
decoded, err := io.ReadAll(wrappedReader)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: io.ReadAll failed: %v\n", err)
os.Exit(1)
}
if string(decoded) != "Hello €" {
fmt.Fprintf(os.Stderr, "assertion 5 failed: expected 'Hello €', got %q\n", string(decoded))
os.Exit(1)
}
var buf bytes.Buffer
wrappedWriter := charmap.Windows1252.NewEncoder().Writer(&buf)
_, err = io.Copy(wrappedWriter, strings.NewReader("Hello €"))
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: io.Copy failed: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(buf.Bytes(), raw) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: writer output mismatch: got %v, want %v\n", buf.Bytes(), raw)
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
Исходный сидер
аноним