CodeSampleX

Пример

golang.org/x/text v0.16.0

Проверенный пример — golang golang.org/x/text v0.16.0. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден: cases.Title and cases.Upper apply…

sha256:c8ab656318f60ad8001c293b1aab5bdb7dc206f67d2e123302823beea958da09

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-14

Кейс

HOW
Цель
verify pkg:golang/golang.org/x/text@v0.16.0
Пакеты
Создан
2026-09-14T19:21:42Z

Контракт

  1. cases.Title and cases.Upper apply locale-sensitive title and uppercase transformations according to language tags
  2. language.Match and language.Parse parse BCP 47 tags and select best matching supported language
  3. norm.NFC and norm.NFD normalize unicode text into canonical composition and decomposition forms
  4. width.Fold transforms fullwidth characters into standard halfwidth ASCII equivalents
  5. runes.Map and transform.String transform rune sequences according to custom mapping functions

Файлы

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

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.16.0

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:2f90e9aa0fe79cfedc05177cb4686c22e73c33daba69b02abe69d029660b1d68","contract":["cases.Title and cases.Upper apply locale-sensitive title and uppercase transformations according to language tags","language.Match and language.Parse parse BCP 47 tags and select best matching supported language","norm.NFC and norm.NFD normalize unicode text into canonical composition and decomposition forms","width.Fold transforms fullwidth characters into standard halfwidth ASCII equivalents","runes.Map and transform.String transform rune sequences according to custom mapping functions"],"goal":"verify pkg:golang/golang.org/x/text@v0.16.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.16.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.16.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.16.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require golang.org/x/text v0.16.0
go.sum
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
main.go
package main

import (
	"fmt"
	"os"
	"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"
)

// CasingService demonstrates locale-sensitive text casing.
type CasingService struct {
	titleCaser cases.Caser
	upperCaser cases.Caser
}

// NewCasingService creates a CasingService configured for the specified language tag.
func NewCasingService(tag language.Tag) CasingService {
	return CasingService{
		titleCaser: cases.Title(tag),
		upperCaser: cases.Upper(tag),
	}
}

// ToTitle converts text to title case using the service's locale.
func (s CasingService) ToTitle(input string) string {
	return s.titleCaser.String(input)
}

// ToUpper converts text to upper case using the service's locale.
func (s CasingService) ToUpper(input string) string {
	return s.upperCaser.String(input)
}

// MatchBestLanguage matches user preference against supported server languages.
func MatchBestLanguage(preferred string, supported []language.Tag) language.Tag {
	matcher := language.NewMatcher(supported)
	userTag, _ := language.Parse(preferred)
	matchedTag, _, _ := matcher.Match(userTag)
	return matchedTag
}

// NormalizeText applies Unicode NFC or NFD normalization.
func NormalizeText(input string, form norm.Form) string {
	return form.String(input)
}

// NormalizeWidth converts fullwidth forms to standard ASCII/halfwidth width.
func NormalizeWidth(input string) string {
	return width.Fold.String(input)
}

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

func main() {
	enService := NewCasingService(language.AmericanEnglish)
	fmt.Printf("Title (EN): %s\n", enService.ToTitle("the lord of the rings"))

	trService := NewCasingService(language.Turkish)
	fmt.Printf("Upper (TR): %s\n", trService.ToUpper("istanbul"))

	supported := []language.Tag{language.English, language.French, language.German, language.Japanese}
	matched := MatchBestLanguage("fr-CA,fr;q=0.9,en;q=0.8", supported)
	fmt.Printf("Matched language: %s\n", matched)

	decomposed := "e\u0301"
	composed := NormalizeText(decomposed, norm.NFC)
	fmt.Printf("NFC Composed: %s\n", composed)

	fullwidth := "Hello 123!"
	halfwidth := NormalizeWidth(fullwidth)
	fmt.Printf("Width folded: %s\n", halfwidth)

	upperMapped, err := MapRunes("hello world", unicode.ToUpper)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Rune mapping error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Mapped runes: %s\n", upperMapped)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/text@v0.16.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.16.0"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"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"
)

func main() {
	// Assertion 1: cases.Title and cases.Upper apply locale-sensitive title and uppercase transformations according to language tags
	enTitle := cases.Title(language.AmericanEnglish).String("the lord of the rings")
	if enTitle != "The Lord Of The Rings" {
		fmt.Fprintf(os.Stderr, "FAIL: cases.Title mismatch: got %q\n", enTitle)
		os.Exit(1)
	}

	trUpper := cases.Upper(language.Turkish).String("istanbul")
	if trUpper != "İSTANBUL" {
		fmt.Fprintf(os.Stderr, "FAIL: cases.Upper Turkish mismatch: got %q\n", trUpper)
		os.Exit(1)
	}

	// Assertion 2: language.Match and language.Parse parse BCP 47 tags and select best matching supported language
	supported := []language.Tag{language.English, language.French, language.German}
	matcher := language.NewMatcher(supported)
	prefTag, err := language.Parse("fr")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: language.Parse failed: %v\n", err)
		os.Exit(1)
	}
	matchedTag, _, confidence := matcher.Match(prefTag)
	if matchedTag != language.French || confidence == language.No {
		fmt.Fprintf(os.Stderr, "FAIL: language.Match unexpected result: tag=%v, confidence=%v\n", matchedTag, confidence)
		os.Exit(1)
	}

	// Assertion 3: norm.NFC and norm.NFD normalize unicode text into canonical composition and decomposition forms
	decomposed := "e\u0301" // e + combining acute accent (len 3 in UTF-8)
	composed := norm.NFC.String(decomposed)
	if composed != "é" || len(composed) != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: norm.NFC composition failed: got %q (len %d)\n", composed, len(composed))
		os.Exit(1)
	}

	reDecomposed := norm.NFD.String(composed)
	if reDecomposed != decomposed || len(reDecomposed) != 3 {
		fmt.Fprintf(os.Stderr, "FAIL: norm.NFD decomposition failed: got %q (len %d)\n", reDecomposed, len(reDecomposed))
		os.Exit(1)
	}

	// Assertion 4: width.Fold transforms fullwidth characters into standard halfwidth ASCII equivalents
	fullwidth := "Hello 123!"
	folded := width.Fold.String(fullwidth)
	expectedFolded := "Hello 123!"
	if folded != expectedFolded {
		fmt.Fprintf(os.Stderr, "FAIL: width.Fold mismatch: got %q, expected %q\n", folded, expectedFolded)
		os.Exit(1)
	}

	// Assertion 5: runes.Map and transform.String transform rune sequences according to custom mapping functions
	mappingTransformer := runes.Map(func(r rune) rune {
		if unicode.IsLower(r) {
			return unicode.ToUpper(r)
		}
		return r
	})
	mappedResult, _, err := transform.String(mappingTransformer, "hello-world-123")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: transform.String with runes.Map returned error: %v\n", err)
		os.Exit(1)
	}
	if mappedResult != "HELLO-WORLD-123" {
		fmt.Fprintf(os.Stderr, "FAIL: runes.Map result mismatch: got %q\n", mappedResult)
		os.Exit(1)
	}

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

Исходный сидер

аноним