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 で contract を実行し、成功しました.

sha256:9dc9c13862457dc002dd056443d4bcfd47a1adf1fbc41cc367233f05df5a62e6

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.")
}

オリジンシーダー

匿名