CodeSampleX

Exemplo

golang.org/x/text v0.31.0: charmap.CodePage437

Amostra verificada para golang golang.org/x/text v0.31.0: charmap.CodePage437. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:8a4f0ab3e18e6715e44d22afaaf3b8a9ca1af054ad2cac0d303f560516ce728f

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-10-11

Caso

HOW
Objetivo
verify golang.org/x/text/encoding/charmap.CodePage437 in pkg:golang/golang.org/x/text@v0.31.0
Pacotes
Símbolos
  • golang.org/x/text/encoding/charmap.CodePage437
Ambiente
go 1.26.6
Criado
2026-10-11T20:26:02Z

Contrato

  1. charmap.CodePage437 identifier string is IBM Code Page 437
  2. charmap.CodePage437.NewDecoder decodes Code Page 437 bytes and strings to UTF-8
  3. charmap.CodePage437.NewEncoder encodes UTF-8 text with Code Page 437 characters to bytes and strings
  4. charmap.CodePage437.NewEncoder returns an error when encoding runes unsupported in Code Page 437
  5. charmap.CodePage437 NewDecoder Reader and NewEncoder Writer transform byte streams

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.CodePage437 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.CodePage437

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:c38c68d9b6071345e801ea98aa1e48c895d123ca5cfb2224440e59a8990abbf8","contract":["charmap.CodePage437 identifier string is IBM Code Page 437","charmap.CodePage437.NewDecoder decodes Code Page 437 bytes and strings to UTF-8","charmap.CodePage437.NewEncoder encodes UTF-8 text with Code Page 437 characters to bytes and strings","charmap.CodePage437.NewEncoder returns an error when encoding runes unsupported in Code Page 437","charmap.CodePage437 NewDecoder Reader and NewEncoder Writer transform byte streams"],"goal":"verify golang.org/x/text/encoding/charmap.CodePage437 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.CodePage437"]},"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.CodePage437"],"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"

	"golang.org/x/text/encoding/charmap"
)

func main() {
	// Demonstrating golang.org/x/text/encoding/charmap.CodePage437
	fmt.Printf("Charmap: %s\n", charmap.CodePage437.String())

	// 1. Decoding Code Page 437 bytes to UTF-8
	decoder := charmap.CodePage437.NewDecoder()
	cp437Bytes := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x80, 0x82, 0x9b, 0x9c, 0xa0, 0xb0, 0xdb}
	decoded, err := decoder.Bytes(cp437Bytes)
	if err != nil {
		fmt.Printf("Decode error: %v\n", err)
		return
	}
	fmt.Printf("Decoded UTF-8: %s\n", string(decoded))

	// 2. Encoding UTF-8 back to Code Page 437
	encoder := charmap.CodePage437.NewEncoder()
	encoded, err := encoder.Bytes(decoded)
	if err != nil {
		fmt.Printf("Encode error: %v\n", err)
		return
	}
	fmt.Printf("Encoded CP437 bytes: %x\n", encoded)

	// 3. Handling unsupported runes in Code Page 437
	unsupportedRune := "€"
	_, err = encoder.Bytes([]byte(unsupportedRune))
	if err != nil {
		fmt.Printf("Expected error for unsupported rune '%s': %v\n", unsupportedRune, err)
	}

	// 4. Stream decoding via Reader
	reader := decoder.Reader(bytes.NewReader(cp437Bytes))
	streamDecoded, err := io.ReadAll(reader)
	if err != nil {
		fmt.Printf("Stream decode error: %v\n", err)
		return
	}
	fmt.Printf("Stream decoded: %s\n", string(streamDecoded))

	// 5. Stream encoding via Writer
	var buf bytes.Buffer
	writer := encoder.Writer(&buf)
	_, err = writer.Write(decoded)
	if err != nil {
		fmt.Printf("Stream encode error: %v\n", err)
		return
	}
	fmt.Printf("Stream encoded match: %v\n", bytes.Equal(buf.Bytes(), cp437Bytes))

	fmt.Println("CodePage437 demonstration complete.")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/text/encoding/charmap.CodePage437 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.CodePage437"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"io"
	"os"

	"golang.org/x/text/encoding/charmap"
)

func main() {
	// Assertion 1: charmap.CodePage437 identifier string is IBM Code Page 437
	{
		name := charmap.CodePage437.String()
		expected := "IBM Code Page 437"
		if name != expected {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected charmap name %q, got %q\n", expected, name)
			os.Exit(1)
		}
	}

	// Assertion 2: charmap.CodePage437.NewDecoder decodes Code Page 437 bytes and strings to UTF-8
	{
		decoder := charmap.CodePage437.NewDecoder()
		if decoder == nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: NewDecoder returned nil\n")
			os.Exit(1)
		}

		cp437Input := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x80, 0x82, 0x9b, 0x9c, 0xa0, 0xb0, 0xdb, 0x21}
		expectedUTF8 := "Hello, Ç颣á░█!"

		decodedBytes, err := decoder.Bytes(cp437Input)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: Bytes returned error: %v\n", err)
			os.Exit(1)
		}
		if string(decodedBytes) != expectedUTF8 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: Bytes returned %q, expected %q\n", string(decodedBytes), expectedUTF8)
			os.Exit(1)
		}

		decodedStr, err := decoder.String(string(cp437Input))
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: String returned error: %v\n", err)
			os.Exit(1)
		}
		if decodedStr != expectedUTF8 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: String returned %q, expected %q\n", decodedStr, expectedUTF8)
			os.Exit(1)
		}
	}

	// Assertion 3: charmap.CodePage437.NewEncoder encodes UTF-8 text with Code Page 437 characters to bytes and strings
	{
		encoder := charmap.CodePage437.NewEncoder()
		if encoder == nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: NewEncoder returned nil\n")
			os.Exit(1)
		}

		utf8Input := "Hello, Ç颣á░█!"
		expectedCP437 := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x80, 0x82, 0x9b, 0x9c, 0xa0, 0xb0, 0xdb, 0x21}

		encodedBytes, err := encoder.Bytes([]byte(utf8Input))
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: Bytes returned error: %v\n", err)
			os.Exit(1)
		}
		if !bytes.Equal(encodedBytes, expectedCP437) {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: Bytes returned %x, expected %x\n", encodedBytes, expectedCP437)
			os.Exit(1)
		}

		encodedStr, err := encoder.String(utf8Input)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: String returned error: %v\n", err)
			os.Exit(1)
		}
		if encodedStr != string(expectedCP437) {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: String returned %x, expected %x\n", []byte(encodedStr), expectedCP437)
			os.Exit(1)
		}
	}

	// Assertion 4: charmap.CodePage437.NewEncoder returns an error when encoding runes unsupported in Code Page 437
	{
		encoder := charmap.CodePage437.NewEncoder()

		unsupportedBytes := []byte("Unsupported: € and 世界")
		_, err := encoder.Bytes(unsupportedBytes)
		if err == nil {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: expected error encoding unsupported runes, got nil\n")
			os.Exit(1)
		}

		_, err = encoder.String("€")
		if err == nil {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: expected error encoding unsupported rune via String, got nil\n")
			os.Exit(1)
		}
	}

	// Assertion 5: charmap.CodePage437 NewDecoder Reader and NewEncoder Writer transform byte streams
	{
		cp437Source := []byte{0x54, 0x65, 0x73, 0x74, 0x3a, 0x20, 0x80, 0x82, 0x9b, 0x9c, 0xa0, 0xb0, 0xdb}
		expectedDecoded := "Test: Ç颣á░█"

		// Stream reading with NewDecoder().Reader
		reader := charmap.CodePage437.NewDecoder().Reader(bytes.NewReader(cp437Source))
		readContent, err := io.ReadAll(reader)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Reader returned error: %v\n", err)
			os.Exit(1)
		}
		if string(readContent) != expectedDecoded {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Reader decoded %q, expected %q\n", string(readContent), expectedDecoded)
			os.Exit(1)
		}

		// Stream writing with NewEncoder().Writer
		var outBuf bytes.Buffer
		writer := charmap.CodePage437.NewEncoder().Writer(&outBuf)
		n, err := writer.Write([]byte(expectedDecoded))
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Writer returned error: %v\n", err)
			os.Exit(1)
		}
		if n != len(expectedDecoded) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Writer returned n=%d, expected %d\n", n, len(expectedDecoded))
			os.Exit(1)
		}
		if !bytes.Equal(outBuf.Bytes(), cp437Source) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Writer wrote %x, expected %x\n", outBuf.Bytes(), cp437Source)
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

Seeder de origem

anônimo