CodeSampleX

샘플

golang.org/x/text v0.16.0: language.NewMatcher

검증된 샘플 — golang golang.org/x/text v0.16.0: language.NewMatcher. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: language.NewMatcher returns a…

sha256:0f4caa5eed9aec6bb8320826a90ba662494e2b525700951817d909579c79b78e

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

검증 실행 환경

환경 컨트랙트 단계 실행일
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-15

케이스

HOW
목표
verify golang.org/x/text/language.NewMatcher in pkg:golang/golang.org/x/text@v0.16.0
패키지
심벌
  • golang.org/x/text/language.NewMatcher
환경
go 1.26.6
생성일
2026-09-15T04:27:57Z

컨트랙트

  1. language.NewMatcher returns a non-nil Matcher for a slice of supported language tags
  2. Matcher.Match returns the exact tag, matching index, and Exact confidence for an identical supported language
  3. Matcher.Match matches regional variants to the supported base language with High confidence
  4. Matcher.Match evaluates preference order across multiple user language tags and selects the highest priority supported tag
  5. Matcher.Match falls back to the default first tag with No confidence when no requested languages match
  6. language.NewMatcher accepts functional options such as language.PreferSameScript

파일

  • 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 golang.org/x/text/language.NewMatcher in 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
Demonstrate these symbols/APIs:
  - golang.org/x/text/language.NewMatcher

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:d22ae6d0f410b770bf005685ba6893293e2d4ef18984236933e3aa64ad97a792","contract":["language.NewMatcher returns a non-nil Matcher for a slice of supported language tags","Matcher.Match returns the exact tag, matching index, and Exact confidence for an identical supported language","Matcher.Match matches regional variants to the supported base language with High confidence","Matcher.Match evaluates preference order across multiple user language tags and selects the highest priority supported tag","Matcher.Match falls back to the default first tag with No confidence when no requested languages match","language.NewMatcher accepts functional options such as language.PreferSameScript"],"goal":"verify golang.org/x/text/language.NewMatcher in pkg:golang/golang.org/x/text@v0.16.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.16.0"],"schemaVersion":1,"symbols":["golang.org/x/text/language.NewMatcher"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","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","symbols":["golang.org/x/text/language.NewMatcher"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

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"

	"golang.org/x/text/language"
)

func main() {
	supported := []language.Tag{
		language.English,
		language.German,
		language.French,
		language.Japanese,
	}

	matcher := language.NewMatcher(supported)

	tag, index, conf := matcher.Match(language.German)
	fmt.Printf("Query German: matched %s (index %d, conf %v)\n", tag, index, conf)

	tag, index, conf = matcher.Match(language.BritishEnglish)
	fmt.Printf("Query British English: matched %s (index %d, conf %v)\n", tag, index, conf)

	tag, index, conf = matcher.Match(language.Spanish, language.French)
	fmt.Printf("Query [Spanish, French]: matched %s (index %d, conf %v)\n", tag, index, conf)

	tag, index, conf = matcher.Match(language.Russian)
	fmt.Printf("Query Russian (unsupported): fallback %s (index %d, conf %v)\n", tag, index, conf)

	customMatcher := language.NewMatcher(supported, language.PreferSameScript(true))
	tag, index, conf = customMatcher.Match(language.AmericanEnglish)
	fmt.Printf("Custom matcher American English: matched %s (index %d, conf %v)\n", tag, index, conf)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/text/language.NewMatcher in pkg:golang/golang.org/x/text@v0.16.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.16.0"
  ],
  "symbols": [
    "golang.org/x/text/language.NewMatcher"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/text/language"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: all contract assertions passed")
}

func runContractTests() error {
	supported := []language.Tag{
		language.English,  // index 0: default fallback
		language.German,   // index 1
		language.French,   // index 2
		language.Japanese, // index 3
	}

	// 1. language.NewMatcher returns a non-nil Matcher for a slice of supported language tags
	matcher := language.NewMatcher(supported)
	if matcher == nil {
		return fmt.Errorf("expected non-nil Matcher from language.NewMatcher")
	}

	// 2. Matcher.Match returns the exact tag, matching index, and Exact confidence for an identical supported language
	tag, index, conf := matcher.Match(language.German)
	if tag != language.German {
		return fmt.Errorf("expected tag %v, got %v", language.German, tag)
	}
	if index != 1 || supported[index] != language.German {
		return fmt.Errorf("expected index 1 (German), got %d", index)
	}
	if conf != language.Exact {
		return fmt.Errorf("expected Exact confidence for German, got %v", conf)
	}

	// 3. Matcher.Match matches regional variants to the supported base language with High confidence
	tag, index, conf = matcher.Match(language.BritishEnglish)
	if index != 0 || supported[index] != language.English {
		return fmt.Errorf("expected index 0 (English) for BritishEnglish, got %d", index)
	}
	base, _ := tag.Base()
	if base.String() != "en" {
		return fmt.Errorf("expected base language 'en' for BritishEnglish match, got %v", base)
	}
	if conf < language.High {
		return fmt.Errorf("expected at least High confidence for BritishEnglish, got %v", conf)
	}

	// 4. Matcher.Match evaluates preference order across multiple user language tags and selects the highest priority supported tag
	tag, index, conf = matcher.Match(language.Spanish, language.French)
	if tag != language.French {
		return fmt.Errorf("expected French tag, got %v", tag)
	}
	if index != 2 || supported[index] != language.French {
		return fmt.Errorf("expected index 2 for French, got %d", index)
	}
	if conf != language.Exact {
		return fmt.Errorf("expected Exact confidence for French, got %v", conf)
	}

	// 5. Matcher.Match falls back to the default first tag with No confidence when no requested languages match
	tag, index, conf = matcher.Match(language.Russian)
	if index != 0 || supported[index] != language.English {
		return fmt.Errorf("expected index 0 fallback to default first tag (English), got %d", index)
	}
	if conf != language.No {
		return fmt.Errorf("expected No confidence for unsupported language fallback, got %v", conf)
	}

	// 6. language.NewMatcher accepts functional options such as language.PreferSameScript
	optMatcher := language.NewMatcher(supported, language.PreferSameScript(true))
	if optMatcher == nil {
		return fmt.Errorf("expected non-nil Matcher when configured with PreferSameScript")
	}
	_, idxOpt, confOpt := optMatcher.Match(language.AmericanEnglish)
	if idxOpt != 0 || confOpt < language.High {
		return fmt.Errorf("expected match index 0 with High confidence, got index %d, conf %v", idxOpt, confOpt)
	}

	return nil
}

오리진 시더

익명