CodeSampleX

Exemple

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

Échantillon vérifié pour golang golang.org/x/text v0.31.0: charmap.ISO8859_7. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:b9c4868264fe1c873360e13daa9ea5e1a9a5be11490749b4fddb5fe7ae3ff7aa

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify golang.org/x/text/encoding/charmap.ISO8859_7 in pkg:golang/golang.org/x/text@v0.31.0
Paquets
Symboles
  • golang.org/x/text/encoding/charmap.ISO8859_7
Créé
2026-10-11T20:57:43Z

Contrat

  1. charmap.ISO8859_7 is non-nil and identifies as ISO 8859-7
  2. charmap.ISO8859_7 decoder converts valid ISO 8859-7 bytes into UTF-8 text
  3. charmap.ISO8859_7 encoder converts UTF-8 Greek and ASCII text into ISO 8859-7 bytes
  4. charmap.ISO8859_7 encoder rejects characters outside the Greek repertoire
  5. charmap.ISO8859_7 DecodeByte and EncodeRune operate directly on single runes and bytes

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.ISO8859_7 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_7

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:887ada9bb31b8cd500ec7ec129d2abceb554063acfa27498d9c6da6b886e1503","contract":["charmap.ISO8859_7 is non-nil and identifies as ISO 8859-7","charmap.ISO8859_7 decoder converts valid ISO 8859-7 bytes into UTF-8 text","charmap.ISO8859_7 encoder converts UTF-8 Greek and ASCII text into ISO 8859-7 bytes","charmap.ISO8859_7 encoder rejects characters outside the Greek repertoire","charmap.ISO8859_7 DecodeByte and EncodeRune operate directly on single runes and bytes"],"goal":"verify golang.org/x/text/encoding/charmap.ISO8859_7 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_7"]},"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.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.31.0","symbols":["golang.org/x/text/encoding/charmap.ISO8859_7"],"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=
iso8859_7.go
package sample

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

// GetCharmap returns the charmap.ISO8859_7 character map encoding.
func GetCharmap() *charmap.Charmap {
	return charmap.ISO8859_7
}

// DecodeString decodes ISO-8859-7 encoded bytes into a UTF-8 string.
func DecodeString(src string) (string, error) {
	return charmap.ISO8859_7.NewDecoder().String(src)
}

// EncodeString encodes a UTF-8 string into ISO-8859-7 encoded string.
func EncodeString(src string) (string, error) {
	return charmap.ISO8859_7.NewEncoder().String(src)
}

// DecodeByte translates an 8-bit ISO-8859-7 byte directly to its corresponding rune.
func DecodeByte(b byte) rune {
	return charmap.ISO8859_7.DecodeByte(b)
}

// EncodeRune translates a rune to its ISO-8859-7 byte.
// Returns the encoded byte and true if in repertoire, or replacement byte and false otherwise.
func EncodeRune(r rune) (byte, bool) {
	return charmap.ISO8859_7.EncodeRune(r)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/text/encoding/charmap.ISO8859_7 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_7"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"sample"
)

func main() {
	// Assertion 1: charmap.ISO8859_7 is non-nil and identifies as ISO 8859-7
	cm := sample.GetCharmap()
	if cm == nil {
		fmt.Fprintf(os.Stderr, "FAIL: charmap.ISO8859_7 is nil\n")
		os.Exit(1)
	}
	if cm.String() != "ISO 8859-7" {
		fmt.Fprintf(os.Stderr, "FAIL: unexpected charmap name: got %q, want %q\n", cm.String(), "ISO 8859-7")
		os.Exit(1)
	}

	// Assertion 2: charmap.ISO8859_7 decoder converts valid ISO 8859-7 bytes into UTF-8 text
	// 0xC1 = 'Α' (Greek Capital Alpha, U+0391)
	// 0xE1 = 'α' (Greek Small Alpha, U+03B1)
	// 0xF9 = 'ω' (Greek Small Omega, U+03C9)
	raw := string([]byte{'H', 'e', 'l', 'l', 'o', ' ', 0xC1, 0xE1, 0xF9})
	expected := "Hello Ααω"
	decoded, err := sample.DecodeString(raw)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: DecodeString returned error: %v\n", err)
		os.Exit(1)
	}
	if decoded != expected {
		fmt.Fprintf(os.Stderr, "FAIL: DecodeString mismatch: got %q, want %q\n", decoded, expected)
		os.Exit(1)
	}

	// Assertion 3: charmap.ISO8859_7 encoder converts UTF-8 Greek and ASCII text into ISO 8859-7 bytes
	encoded, err := sample.EncodeString(expected)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: EncodeString returned error: %v\n", err)
		os.Exit(1)
	}
	if encoded != raw {
		fmt.Fprintf(os.Stderr, "FAIL: EncodeString mismatch: got %q, want %q\n", encoded, raw)
		os.Exit(1)
	}

	// Assertion 4: charmap.ISO8859_7 encoder rejects characters outside the Greek repertoire
	_, err = sample.EncodeString("Hello 世界")
	if err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: EncodeString expected error for non-repertoire characters, got nil\n")
		os.Exit(1)
	}

	// Assertion 5: charmap.ISO8859_7 DecodeByte and EncodeRune operate directly on single runes and bytes
	if r := sample.DecodeByte(0xC1); r != 'Α' {
		fmt.Fprintf(os.Stderr, "FAIL: DecodeByte(0xC1) mismatch: got %U, want %U\n", r, 'Α')
		os.Exit(1)
	}
	bAlpha, okAlpha := sample.EncodeRune('Α')
	if !okAlpha || bAlpha != 0xC1 {
		fmt.Fprintf(os.Stderr, "FAIL: EncodeRune('Α') mismatch: got (%02x, %v), want (0xC1, true)\n", bAlpha, okAlpha)
		os.Exit(1)
	}
	bAscii, okAscii := sample.EncodeRune('Z')
	if !okAscii || bAscii != 'Z' {
		fmt.Fprintf(os.Stderr, "FAIL: EncodeRune('Z') mismatch: got (%02x, %v), want ('Z', true)\n", bAscii, okAscii)
		os.Exit(1)
	}
	bInvalid, okInvalid := sample.EncodeRune('한')
	if okInvalid || bInvalid != 0x1A {
		fmt.Fprintf(os.Stderr, "FAIL: EncodeRune unsupported rune mismatch: got (%02x, %v), want (0x1A, false)\n", bInvalid, okInvalid)
		os.Exit(1)
	}

	fmt.Println("PASS: golang.org/x/text/encoding/charmap.ISO8859_7 contract verified")
}

Seeder d'origine

anonyme