CodeSampleX

示例

golang.org/x/text v0.14.0

已验证示例 — golang golang.org/x/text v0.14.0. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: language.Parse and language.NewMatcher match requested BCP…

sha256:bf88b71e5836220f0ce9fe091d14625c576faa52621dbd75617912dc328b2052

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-27

案例

HOW
目标
verify pkg:golang/golang.org/x/text@v0.14.0
包
创建时间
2026-08-27T15:32:59Z

契约

  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. transform.String applies chained transformers to transform text across normalizations and casing

文件

  • 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.14.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.14.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:214000dc65dae7dfbd12946c7e195124bd3dc6cebbe6f996a88ddc3753945413","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","transform.String applies chained transformers to transform text across normalizations and casing"],"goal":"verify pkg:golang/golang.org/x/text@v0.14.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.14.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.14.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.14.0","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require golang.org/x/text v0.14.0
go.sum
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
main.go
package main

import (
	"fmt"
	"os"

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

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

// ConvertCase applies language-aware casing to input text.
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)
	default:
		return text
	}
}

// NormalizeText normalizes unicode text into the specified Form (NFC, NFD, NFKC, NFKD).
func NormalizeText(form norm.Form, input string) string {
	return form.String(input)
}

// FoldWidth transforms fullwidth runes into halfwidth equivalents.
func FoldWidth(input string) string {
	return width.Fold.String(input)
}

// TransformWithChain applies a chain of transformers (e.g. width fold + casing).
func TransformWithChain(input string, transformers ...transform.Transformer) (string, error) {
	chained := transform.Chain(transformers...)
	result, _, err := transform.String(chained, input)
	return result, err
}

func main() {
	// Language matching
	supported := []language.Tag{language.English, language.German, language.Turkish}
	matched, idx, conf := MatchLanguage(supported, language.MustParse("tr-TR"))
	fmt.Printf("Matched: %v (index %d, conf %v)\n", matched, idx, conf)

	// Turkish dotted/dotless i casing
	upperTr := ConvertCase(language.Turkish, "istanbul", "upper")
	lowerTr := ConvertCase(language.Turkish, "İSTANBUL", "lower")
	fmt.Printf("Turkish upper: %s, lower: %s\n", upperTr, lowerTr)

	// Unicode normalization
	composed := NormalizeText(norm.NFC, "e\u0301")
	fmt.Printf("NFC composed: %s\n", composed)

	// Width folding
	folded := FoldWidth("Hello 123!")
	fmt.Printf("Width folded: %s\n", folded)

	// Chained transformation
	tChain, err := TransformWithChain("hello", width.Fold, cases.Upper(language.English))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Transform error: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Chained transform: %s\n", tChain)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/golang.org/x/text@v0.14.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.14.0"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

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, language.Turkish}
	matcher := language.NewMatcher(supported)

	matchedTag, index, conf := matcher.Match(language.MustParse("de-AT"), language.MustParse("de"))
	if matchedTag != language.German || index != 1 || conf != language.Exact {
		fmt.Fprintf(os.Stderr, "FAIL assertion 1: language match expected German at index 1, got %v at index %d (conf=%v)\n", matchedTag, index, conf)
		os.Exit(1)
	}

	trTag, trIdx, confTr := matcher.Match(language.MustParse("tr"))
	if trTag != language.Turkish || trIdx != 3 || confTr != language.Exact {
		fmt.Fprintf(os.Stderr, "FAIL assertion 1: language match expected Turkish at index 3, got %v at index %d (conf=%v)\n", trTag, trIdx, confTr)
		os.Exit(1)
	}

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

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

	trTitle := cases.Title(language.Turkish).String("istanbul")
	enTitle := cases.Title(language.English).String("istanbul")
	if trTitle != "İstanbul" || enTitle != "Istanbul" {
		fmt.Fprintf(os.Stderr, "FAIL assertion 2: 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 := norm.NFC.String(decomposed)
	if composed != "é" || len(composed) != 2 {
		fmt.Fprintf(os.Stderr, "FAIL assertion 3: NFC expected 'é' (2 bytes), got '%s' (%d bytes)\n", composed, len(composed))
		os.Exit(1)
	}

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

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

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

	// Assertion 5: transform.String applies chained transformers to transform text across normalizations and casing
	chained := transform.Chain(width.Fold, cases.Upper(language.English))
	res, _, err := transform.String(chained, "golang")
	if err != nil || res != "GOLANG" {
		fmt.Fprintf(os.Stderr, "FAIL assertion 5: transform.Chain expected 'GOLANG', got '%s', err=%v\n", res, err)
		os.Exit(1)
	}

	fmt.Println("Contract passed: all assertions verified successfully.")
}

原始种子者

匿名