CodeSampleX

Exemplo

golang.org/x/text v0.3.2: charmap.ISO8859_1, charmap.Windows1252, unicode.UTF16

Amostra verificada para golang golang.org/x/text v0.3.2: charmap.ISO8859_1, charmap.Windows1252, unicode.UTF16. O contrato rodou em go 1.26 · linux…

sha256:9245e3657337eb9e3e7c90afb7b1a78fd0f3392565e16fed179fd7ff1d75cfe8

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 linux 24 · ubuntu · glibc 2.39 x64 go

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-09-05

Caso

HOW
Objetivo
verify pkg:golang/golang.org/x/text@v0.3.2
Pacotes
Símbolos
  • charmap.ISO8859_1
  • charmap.Windows1252
  • unicode.UTF16
  • unicode.UTF8
Criado
2026-09-05T04:28:11Z

Contrato

  1. charmap.Windows1252 encodes and decodes Windows-1252 single-byte characters including the Euro symbol
  2. charmap.ISO8859_1 encodes and decodes Latin-1 single-byte characters preserving accented letters
  3. unicode.UTF16 encodes Unicode text into UTF-16 byte sequences with byte order mark and decodes back
  4. unicode.BOMOverride wraps a UTF-8 decoder to detect and strip UTF-8 byte order marks

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 pkg:golang/golang.org/x/text@v0.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.3.2
Demonstrate these symbols/APIs:
  - charmap.ISO8859_1
  - charmap.Windows1252
  - unicode.UTF16
  - unicode.UTF8

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:c188c648b1379279a3017f8695df99c7429b02568a16a17534f46c56e50dd924","contract":["charmap.Windows1252 encodes and decodes Windows-1252 single-byte characters including the Euro symbol","charmap.ISO8859_1 encodes and decodes Latin-1 single-byte characters preserving accented letters","unicode.UTF16 encodes Unicode text into UTF-16 byte sequences with byte order mark and decodes back","unicode.BOMOverride wraps a UTF-8 decoder to detect and strip UTF-8 byte order marks"],"goal":"verify pkg:golang/golang.org/x/text@v0.3.2","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.3.2"],"schemaVersion":1,"symbols":["charmap.ISO8859_1","charmap.Windows1252","unicode.UTF16","unicode.UTF8"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/text@v0.3.2"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.3.2","symbols":["charmap.ISO8859_1","charmap.Windows1252","unicode.UTF16","unicode.UTF8"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require golang.org/x/text v0.3.2
go.sum
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
main.go
package main

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

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

func main() {
	// 1. Windows-1252 encoding and decoding
	w1252Encoder := charmap.Windows1252.NewEncoder()
	w1252Decoder := charmap.Windows1252.NewDecoder()

	euroText := "Price: 10 €"
	w1252Bytes, err := w1252Encoder.String(euroText)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Windows1252 encode error: %v\n", err)
		os.Exit(1)
	}
	decoded1252, err := w1252Decoder.String(w1252Bytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Windows1252 decode error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Windows-1252 decoded: %s\n", decoded1252)

	// 2. ISO 8859-1 (Latin-1) encoding and decoding
	latinEncoder := charmap.ISO8859_1.NewEncoder()
	latinDecoder := charmap.ISO8859_1.NewDecoder()

	accentedText := "café naïve"
	latinBytes, err := latinEncoder.Bytes([]byte(accentedText))
	if err != nil {
		fmt.Fprintf(os.Stderr, "ISO-8859-1 encode error: %v\n", err)
		os.Exit(1)
	}
	decodedLatin, err := latinDecoder.Bytes(latinBytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ISO-8859-1 decode error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("ISO-8859-1 decoded: %s\n", string(decodedLatin))

	// 3. UTF-16 with BOM
	u16 := unicode.UTF16(unicode.LittleEndian, unicode.UseBOM)
	u16Encoder := u16.NewEncoder()
	u16Decoder := u16.NewDecoder()

	u16Bytes, err := u16Encoder.Bytes([]byte("Hello, World!"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "UTF-16 encode error: %v\n", err)
		os.Exit(1)
	}
	decodedU16, err := u16Decoder.Bytes(u16Bytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "UTF-16 decode error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("UTF-16 decoded: %s\n", string(decodedU16))

	// 4. UTF-8 with BOM removal
	utf8BomDecoder := unicode.BOMOverride(unicode.UTF8.NewDecoder())
	bomReader := transform.NewReader(bytes.NewReader([]byte("\xEF\xBB\xBFUTF-8 with BOM")), utf8BomDecoder)
	strippedText, err := io.ReadAll(bomReader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "BOM override read error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("UTF-8 BOM stripped: %s\n", string(strippedText))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/text@v0.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.3.2"
  ],
  "symbols": [
    "charmap.ISO8859_1",
    "charmap.Windows1252",
    "unicode.UTF16",
    "unicode.UTF8"
  ]
}
test/contract.go
package main

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

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

func main() {
	// Assertion 1: charmap.Windows1252 encodes and decodes Windows-1252 single-byte characters including the Euro symbol
	w1252Encoder := charmap.Windows1252.NewEncoder()
	w1252Decoder := charmap.Windows1252.NewDecoder()

	src1252 := "Euro symbol: €"
	encoded1252, err := w1252Encoder.String(src1252)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Windows1252 encode error: %v\n", err)
		os.Exit(1)
	}
	// In Windows-1252, € is encoded as single byte 0x80
	if encoded1252[len(encoded1252)-1] != 0x80 {
		fmt.Fprintf(os.Stderr, "FAIL: expected trailing Euro byte 0x80, got %02x\n", encoded1252[len(encoded1252)-1])
		os.Exit(1)
	}
	decoded1252, err := w1252Decoder.String(encoded1252)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Windows1252 decode error: %v\n", err)
		os.Exit(1)
	}
	if decoded1252 != src1252 {
		fmt.Fprintf(os.Stderr, "FAIL: Windows1252 decoded mismatch: got %q, want %q\n", decoded1252, src1252)
		os.Exit(1)
	}

	// Assertion 2: charmap.ISO8859_1 encodes and decodes Latin-1 single-byte characters preserving accented letters
	latinEncoder := charmap.ISO8859_1.NewEncoder()
	latinDecoder := charmap.ISO8859_1.NewDecoder()

	srcLatin := "café naïve"
	encodedLatin, err := latinEncoder.Bytes([]byte(srcLatin))
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ISO8859_1 encode error: %v\n", err)
		os.Exit(1)
	}
	// In ISO 8859-1: 'é' is 0xE9, 'ï' is 0xEF
	// "café naïve": 10 bytes
	if len(encodedLatin) != 10 || encodedLatin[3] != 0xE9 || encodedLatin[7] != 0xEF {
		fmt.Fprintf(os.Stderr, "FAIL: expected ISO8859_1 byte length 10 with 0xE9 at [3] and 0xEF at [7], got len=%d bytes=%v\n", len(encodedLatin), encodedLatin)
		os.Exit(1)
	}
	decodedLatin, err := latinDecoder.Bytes(encodedLatin)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ISO8859_1 decode error: %v\n", err)
		os.Exit(1)
	}
	if string(decodedLatin) != srcLatin {
		fmt.Fprintf(os.Stderr, "FAIL: ISO8859_1 decoded mismatch: got %q, want %q\n", string(decodedLatin), srcLatin)
		os.Exit(1)
	}

	// Assertion 3: unicode.UTF16 encodes Unicode text into UTF-16 byte sequences with byte order mark and decodes back
	u16 := unicode.UTF16(unicode.LittleEndian, unicode.UseBOM)
	u16Encoder := u16.NewEncoder()
	u16Decoder := u16.NewDecoder()

	srcU16 := "Go Text"
	encodedU16, err := u16Encoder.Bytes([]byte(srcU16))
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UTF16 encode error: %v\n", err)
		os.Exit(1)
	}
	// Little-endian BOM is 0xFF, 0xFE followed by 7 UTF-16 code units (14 bytes) -> total 16 bytes
	if len(encodedU16) != 16 || encodedU16[0] != 0xFF || encodedU16[1] != 0xFE {
		fmt.Fprintf(os.Stderr, "FAIL: expected LittleEndian BOM 0xFF 0xFE and length 16, got len=%d bytes=%02x %02x\n", len(encodedU16), encodedU16[0], encodedU16[1])
		os.Exit(1)
	}
	decodedU16, err := u16Decoder.Bytes(encodedU16)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UTF16 decode error: %v\n", err)
		os.Exit(1)
	}
	if string(decodedU16) != srcU16 {
		fmt.Fprintf(os.Stderr, "FAIL: UTF16 decoded mismatch: got %q, want %q\n", string(decodedU16), srcU16)
		os.Exit(1)
	}

	// Assertion 4: unicode.BOMOverride wraps a UTF-8 decoder to detect and strip UTF-8 byte order marks
	utf8WithBOM := []byte("\xEF\xBB\xBFHello Unicode")
	bomOverrideDecoder := unicode.BOMOverride(unicode.UTF8.NewDecoder())
	reader := transform.NewReader(bytes.NewReader(utf8WithBOM), bomOverrideDecoder)
	strippedOutput, err := io.ReadAll(reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: BOMOverride read error: %v\n", err)
		os.Exit(1)
	}
	if string(strippedOutput) != "Hello Unicode" {
		fmt.Fprintf(os.Stderr, "FAIL: BOMOverride expected 'Hello Unicode', got %q\n", string(strippedOutput))
		os.Exit(1)
	}

	// Verify that text without BOM passes through untouched
	plainUTF8 := []byte("Plain UTF-8 text")
	plainReader := transform.NewReader(bytes.NewReader(plainUTF8), unicode.BOMOverride(unicode.UTF8.NewDecoder()))
	plainOutput, err := io.ReadAll(plainReader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: plain UTF8 read error: %v\n", err)
		os.Exit(1)
	}
	if string(plainOutput) != "Plain UTF-8 text" {
		fmt.Fprintf(os.Stderr, "FAIL: plain UTF8 expected 'Plain UTF-8 text', got %q\n", string(plainOutput))
		os.Exit(1)
	}

	fmt.Println("PASS: pkg:golang/golang.org/x/text@v0.3.2 encoding contract verified")
}

Seeder de origem

anônimo