CodeSampleX

Пример

github.com/huandu/xstrings v1.3.3: Center, Partition, Reverse

Проверенный пример — golang github.com/huandu/xstrings v1.3.3: Center, Partition, Reverse. Контракт выполнен на go 1.26 · linux alpine/x64 · docker и пройден.

sha256:9dc9c13862457dc002dd056443d4bcfd47a1adf1fbc41cc367233f05df5a62e6

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

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

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

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

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

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

Кейс

HOW
Цель
verify pkg:golang/github.com/huandu/xstrings@v1.3.3
Пакеты
Символы
  • xstrings.Center
  • xstrings.Partition
  • xstrings.Reverse
  • xstrings.Translate
Создан
2026-08-28T09:21:48Z

Контракт

  1. xstrings.Reverse reverses a string by runes
  2. xstrings.Translate replaces characters defined in from pattern with characters defined in to pattern
  3. xstrings.Partition splits a string by separator into head, match, and tail parts
  4. xstrings.Center centers a string with padding characters when string length is smaller than target length

Файлы

  • 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/github.com/huandu/xstrings@v1.3.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/huandu/xstrings@v1.3.3
Demonstrate these symbols/APIs:
  - xstrings.Center
  - xstrings.Partition
  - xstrings.Reverse
  - xstrings.Translate

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:1c7c2b0e261da94f27547538a731fad0c9d8817bf869f26a1426cceccf9dadb7","contract":["xstrings.Reverse reverses a string by runes","xstrings.Translate replaces characters defined in from pattern with characters defined in to pattern","xstrings.Partition splits a string by separator into head, match, and tail parts","xstrings.Center centers a string with padding characters when string length is smaller than target length"],"goal":"verify pkg:golang/github.com/huandu/xstrings@v1.3.3","kind":"HOW","packages":["pkg:golang/github.com/huandu/xstrings@v1.3.3"],"schemaVersion":1,"symbols":["xstrings.Center","xstrings.Partition","xstrings.Reverse","xstrings.Translate"]},"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/github.com/huandu/xstrings@v1.3.3"],"schemaVersion":1,"subject":"pkg:golang/github.com/huandu/xstrings@v1.3.3","symbols":["xstrings.Center","xstrings.Partition","xstrings.Reverse","xstrings.Translate"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require github.com/huandu/xstrings v1.3.3
go.sum
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
main.go
package main

import (
	"fmt"

	"github.com/huandu/xstrings"
)

func main() {
	reversed := xstrings.Reverse("Hello, World!")
	translated := xstrings.Translate("hello world", "a-z", "A-Z")
	head, match, tail := xstrings.Partition("user@example.com", "@")
	centered := xstrings.Center("Golang", 12, "=")

	fmt.Printf("reversed: %s\n", reversed)
	fmt.Printf("translated: %s\n", translated)
	fmt.Printf("partition: head=%q match=%q tail=%q\n", head, match, tail)
	fmt.Printf("centered: %s\n", centered)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/huandu/xstrings@v1.3.3",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/huandu/xstrings@v1.3.3"
  ],
  "symbols": [
    "xstrings.Center",
    "xstrings.Partition",
    "xstrings.Reverse",
    "xstrings.Translate"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/huandu/xstrings"
)

func main() {
	if got := xstrings.Reverse("Hello, World!"); got != "!dlroW ,olleH" {
		fmt.Fprintf(os.Stderr, "Reverse failed: got %q, want %q\n", got, "!dlroW ,olleH")
		os.Exit(1)
	}
	if got := xstrings.Reverse("안녕하세요"); got != "요세하녕안" {
		fmt.Fprintf(os.Stderr, "Reverse utf8 failed: got %q, want %q\n", got, "요세하녕안")
		os.Exit(1)
	}

	if got := xstrings.Translate("hello", "aeiou", "12345"); got != "h2ll4" {
		fmt.Fprintf(os.Stderr, "Translate mapping failed: got %q, want %q\n", got, "h2ll4")
		os.Exit(1)
	}
	if got := xstrings.Translate("hello", "a-z", "A-Z"); got != "HELLO" {
		fmt.Fprintf(os.Stderr, "Translate range failed: got %q, want %q\n", got, "HELLO")
		os.Exit(1)
	}

	if head, match, tail := xstrings.Partition("user@example.com", "@"); head != "user" || match != "@" || tail != "example.com" {
		fmt.Fprintf(os.Stderr, "Partition match failed: got (%q, %q, %q), want (\"user\", \"@\", \"example.com\")\n", head, match, tail)
		os.Exit(1)
	}
	if head, match, tail := xstrings.Partition("no_separator_here", "@"); head != "no_separator_here" || match != "" || tail != "" {
		fmt.Fprintf(os.Stderr, "Partition no-match failed: got (%q, %q, %q), want (\"no_separator_here\", \"\", \"\")\n", head, match, tail)
		os.Exit(1)
	}

	if got := xstrings.Center("hello", 11, " "); got != "   hello   " {
		fmt.Fprintf(os.Stderr, "Center spaces failed: got %q, want %q\n", got, "   hello   ")
		os.Exit(1)
	}
	if got := xstrings.Center("Golang", 12, "="); got != "===Golang===" {
		fmt.Fprintf(os.Stderr, "Center custom pad failed: got %q, want %q\n", got, "===Golang===")
		os.Exit(1)
	}

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

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

аноним