CodeSampleX

Exemple

golang.org/x/text v0.18.0

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

sha256:c9668da4de26d9cb77a8f541405f71a06c6cd6c5092ef73a6213f4c71b31ea5e

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 alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-27

Cas

HOW
Objectif
verify pkg:golang/golang.org/x/text@v0.18.0
Paquets
Créé
2026-08-27T15:36:11Z

Contrat

  1. language.Parse and language.NewMatcher match requested BCP 47 language tags against supported preferences
  2. cases.Title, cases.Upper and cases.Lower apply language-aware case transformations
  3. norm.NFC, norm.NFD and norm.NFKD perform canonical and compatibility Unicode normalization
  4. width.Fold normalizes fullwidth characters to standard halfwidth ASCII forms
  5. runes.Map transforms individual runes with custom mapping rules
  6. transform.Chain and runes.Remove strip diacritic marks from decomposed unicode text

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/main.go
  • textutil.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 pkg:golang/golang.org/x/text@v0.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.18.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:39b69f0e381950abe971b7b023cc73d64e9c770ea12597ff89c37462745df9d6","contract":["language.Parse and language.NewMatcher match requested BCP 47 language tags against supported preferences","cases.Title, cases.Upper and cases.Lower apply language-aware case transformations","norm.NFC, norm.NFD and norm.NFKD perform canonical and compatibility Unicode normalization","width.Fold normalizes fullwidth characters to standard halfwidth ASCII forms","runes.Map transforms individual runes with custom mapping rules","transform.Chain and runes.Remove strip diacritic marks from decomposed unicode text"],"goal":"verify pkg:golang/golang.org/x/text@v0.18.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.18.0"],"schemaVersion":1},"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.18.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.18.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/text v0.18.0
go.sum
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/text@v0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.18.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/main.go
package main

import (
	"fmt"
	"os"

	"example.com/sample"
	"golang.org/x/text/language"
	"golang.org/x/text/unicode/norm"
)

func main() {
	// Assertion 1: language.Parse and language.NewMatcher match requested BCP 47 language tags against supported preferences
	supported := []language.Tag{language.English, language.German, language.French}
	matchedTag, index, conf := sample.MatchLanguage(supported, language.MustParse("de-AT"), language.MustParse("de"))
	if matchedTag != language.German || index != 1 || conf != language.Exact {
		fmt.Fprintf(os.Stderr, "Assertion 1 failed: language match expected German at index 1, got %v at index %d (conf=%v)\n", matchedTag, index, conf)
		os.Exit(1)
	}

	// Assertion 2: cases.Title, cases.Upper and cases.Lower apply language-aware case transformations
	trUpper := sample.ConvertCase(language.Turkish, "istanbul", "upper")
	enUpper := sample.ConvertCase(language.English, "istanbul", "upper")
	if trUpper != "İSTANBUL" || enUpper != "ISTANBUL" {
		fmt.Fprintf(os.Stderr, "Assertion 2 failed: Upper expected tr='İSTANBUL', en='ISTANBUL', got tr='%s', en='%s'\n", trUpper, enUpper)
		os.Exit(1)
	}

	trLower := sample.ConvertCase(language.Turkish, "ISTANBUL", "lower")
	enLower := sample.ConvertCase(language.English, "ISTANBUL", "lower")
	if trLower != "ıstanbul" || enLower != "istanbul" {
		fmt.Fprintf(os.Stderr, "Assertion 2 failed: Lower expected tr='ıstanbul', en='istanbul', got tr='%s', en='%s'\n", trLower, enLower)
		os.Exit(1)
	}

	trTitle := sample.ConvertCase(language.Turkish, "istanbul", "title")
	enTitle := sample.ConvertCase(language.English, "istanbul", "title")
	if trTitle != "İstanbul" || enTitle != "Istanbul" {
		fmt.Fprintf(os.Stderr, "Assertion 2 failed: Title expected tr='İstanbul', en='Istanbul', got tr='%s', en='%s'\n", trTitle, enTitle)
		os.Exit(1)
	}

	// Assertion 3: norm.NFC, norm.NFD and norm.NFKD perform canonical and compatibility Unicode normalization
	decomposed := "e\u0301" // e + combining acute accent
	composed := sample.NormalizeText(norm.NFC, decomposed)
	if composed != "é" || len(composed) != 2 {
		fmt.Fprintf(os.Stderr, "Assertion 3 failed: NFC expected 'é' (2 bytes), got '%s' (%d bytes)\n", composed, len(composed))
		os.Exit(1)
	}

	if sample.NormalizeText(norm.NFD, "é") != decomposed {
		fmt.Fprintf(os.Stderr, "Assertion 3 failed: NFD did not match decomposed form\n")
		os.Exit(1)
	}

	if sample.NormalizeText(norm.NFKD, "fi") != "fi" {
		fmt.Fprintf(os.Stderr, "Assertion 3 failed: NFKD ligature decomposition failed\n")
		os.Exit(1)
	}

	// Assertion 4: width.Fold normalizes fullwidth characters to standard halfwidth ASCII forms
	fullwidth := "Hello 123!"
	folded := sample.FoldWidth(fullwidth)
	if folded != "Hello 123!" {
		fmt.Fprintf(os.Stderr, "Assertion 4 failed: width.Fold expected 'Hello 123!', got '%s'\n", folded)
		os.Exit(1)
	}

	// Assertion 5: runes.Map transforms individual runes with custom mapping rules
	rot13Map := func(r rune) rune {
		if r >= 'a' && r <= 'z' {
			return 'a' + (r-'a'+13)%26
		}
		if r >= 'A' && r <= 'Z' {
			return 'A' + (r-'A'+13)%26
		}
		return r
	}
	rot13Result, err := sample.MapRunes(rot13Map, "Hello World!")
	if err != nil || rot13Result != "Uryyb Jbeyq!" {
		fmt.Fprintf(os.Stderr, "Assertion 5 failed: MapRunes expected 'Uryyb Jbeyq!', got '%s' (err=%v)\n", rot13Result, err)
		os.Exit(1)
	}

	// Assertion 6: transform.Chain and runes.Remove strip diacritic marks from decomposed unicode text
	stripped, err := sample.RemoveDiacritics("Café résumé naïve")
	if err != nil || stripped != "Cafe resume naive" {
		fmt.Fprintf(os.Stderr, "Assertion 6 failed: RemoveDiacritics expected 'Cafe resume naive', got '%s' (err=%v)\n", stripped, err)
		os.Exit(1)
	}

	fmt.Println("Contract passed: all assertions verified successfully.")
}
textutil.go
package sample

import (
	"unicode"

	"golang.org/x/text/cases"
	"golang.org/x/text/language"
	"golang.org/x/text/runes"
	"golang.org/x/text/transform"
	"golang.org/x/text/unicode/norm"
	"golang.org/x/text/width"
)

// MatchLanguage selects the best matching language tag from supported tags.
func MatchLanguage(supported []language.Tag, requested ...language.Tag) (language.Tag, int, language.Confidence) {
	matcher := language.NewMatcher(supported)
	return matcher.Match(requested...)
}

// ConvertCase applies locale-sensitive casing.
func ConvertCase(tag language.Tag, text string, mode string) string {
	switch mode {
	case "upper":
		return cases.Upper(tag).String(text)
	case "lower":
		return cases.Lower(tag).String(text)
	case "title":
		return cases.Title(tag).String(text)
	case "fold":
		return cases.Fold().String(text)
	default:
		return text
	}
}

// NormalizeText normalizes unicode string to the given form.
func NormalizeText(form norm.Form, input string) string {
	return form.String(input)
}

// FoldWidth normalizes fullwidth characters to standard halfwidth ASCII forms.
func FoldWidth(input string) string {
	return width.Fold.String(input)
}

// MapRunes applies a rune transformation mapping using runes.Map and transform.String.
func MapRunes(mapping func(rune) rune, input string) (string, error) {
	t := runes.Map(mapping)
	result, _, err := transform.String(t, input)
	return result, err
}

// RemoveDiacritics strips non-spacing marks (accents) after NFD decomposition.
func RemoveDiacritics(input string) (string, error) {
	t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
	result, _, err := transform.String(t, input)
	return result, err
}

Seeder d'origine

anonyme