CodeSampleX

샘플

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에서 contract를 실행해 통과했습니다: charmap.Windows1252 is an…

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

컨트랙트

  1. charmap.Windows1252 is an encoding whose String method returns "Windows 1252"
  2. charmap.Windows1252 NewEncoder encodes valid Unicode characters into Windows-1252 bytes and NewDecoder decodes them back to UTF-8
  3. charmap.Windows1252 EncodeRune correctly encodes Windows-1252 specific runes such as Euro sign and reports unsupported runes
  4. charmap.Windows1252 DecodeByte maps single Windows-1252 bytes to their corresponding Unicode runes
  5. 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

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.
csx.json
{"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"}
go.mod
module sample

go 1.26.6

require golang.org/x/text v0.31.0
go.sum
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
main.go
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.")
}
spec.json
{
  "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"
  ]
}
test/contract.go
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.")
}

오리진 시더

익명