CodeSampleX

Beispiel

golang.org/x/text v0.34.0: collate.Collator.CompareString

Verifiziertes Beispiel für golang golang.org/x/text v0.34.0: collate.Collator.CompareString. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker und…

sha256:ee75ccc65583f5ef7ccb58614f53e203c7cdcf5baf5ecada5f57f5d83c2b276c

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-26

Fall

HOW
Ziel
verify collate.Collator.CompareString in pkg:golang/golang.org/x/text@v0.34.0
Pakete
Symbole
  • collate.Collator.CompareString
Umgebung
go 1.26
Erstellt
2026-08-26T06:11:49Z

Contract

  1. collate.New initialized with language.English returns 0 when CompareString is called on identical strings
  2. collate.New initialized with language.English returns -1 for 'apple' vs 'banana' and 1 for 'zebra' vs 'apple'
  3. collate.New with collate.IgnoreCase returns 0 when CompareString is called on 'golang' and 'GOLANG'
  4. collate.New with collate.Loose returns 0 when CompareString is called on 'resume' and 'résumé'
  5. collate.New with collate.Numeric returns -1 when CompareString is called on 'item2' and 'item12'
  6. collate.New initialized with language.Swedish returns 1 when CompareString compares 'ö' and 'z'

Dateien

  • PROMPT.md
  • contract_test.go
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json

Quellartefakt herunterladen (tar.gz)

Quelltext

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 collate.Collator.CompareString in pkg:golang/golang.org/x/text@v0.34.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/text@v0.34.0
Demonstrate these symbols/APIs:
  - collate.Collator.CompareString
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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.
contract_test.go
package sample

import (
	"testing"

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

func TestCompareStringIdentical(t *testing.T) {
	c := collate.New(language.English)
	if res := c.CompareString("hello", "hello"); res != 0 {
		t.Fatalf("expected 0 for identical strings, got %d", res)
	}
}

func TestCompareStringLexicographicalOrder(t *testing.T) {
	c := collate.New(language.English)
	if res := c.CompareString("apple", "banana"); res != -1 {
		t.Fatalf("expected -1 for apple < banana, got %d", res)
	}
	if res := c.CompareString("zebra", "apple"); res != 1 {
		t.Fatalf("expected 1 for zebra > apple, got %d", res)
	}
}

func TestCompareStringIgnoreCase(t *testing.T) {
	cDefault := collate.New(language.English)
	if res := cDefault.CompareString("golang", "GOLANG"); res == 0 {
		t.Fatalf("expected non-zero without IgnoreCase, got %d", res)
	}

	cIgnore := collate.New(language.English, collate.IgnoreCase)
	if res := cIgnore.CompareString("golang", "GOLANG"); res != 0 {
		t.Fatalf("expected 0 with IgnoreCase, got %d", res)
	}
}

func TestCompareStringLoose(t *testing.T) {
	cDefault := collate.New(language.English)
	if res := cDefault.CompareString("resume", "résumé"); res == 0 {
		t.Fatalf("expected non-zero without Loose, got %d", res)
	}

	cLoose := collate.New(language.English, collate.Loose)
	if res := cLoose.CompareString("resume", "résumé"); res != 0 {
		t.Fatalf("expected 0 with Loose option, got %d", res)
	}
}

func TestCompareStringNumeric(t *testing.T) {
	cDefault := collate.New(language.English)
	if res := cDefault.CompareString("item2", "item12"); res != 1 {
		t.Fatalf("expected 1 without Numeric (lexicographical '2' > '1'), got %d", res)
	}

	cNumeric := collate.New(language.English, collate.Numeric)
	if res := cNumeric.CompareString("item2", "item12"); res != -1 {
		t.Fatalf("expected -1 with Numeric option ('item2' < 'item12'), got %d", res)
	}
}

func TestCompareStringLocaleSpecificSwedish(t *testing.T) {
	cSwedish := collate.New(language.Swedish)
	if res := cSwedish.CompareString("ö", "z"); res != 1 {
		t.Fatalf("expected 1 (ö > z in Swedish collation), got %d", res)
	}
}
csx.json
{"case":{"caseId":"case:sha256:08dfa28e35d906b6de03044cde18b92da6298c47cdd4d8e13ee65b3e590dcd5c","contract":["collate.New initialized with language.English returns 0 when CompareString is called on identical strings","collate.New initialized with language.English returns -1 for 'apple' vs 'banana' and 1 for 'zebra' vs 'apple'","collate.New with collate.IgnoreCase returns 0 when CompareString is called on 'golang' and 'GOLANG'","collate.New with collate.Loose returns 0 when CompareString is called on 'resume' and 'résumé'","collate.New with collate.Numeric returns -1 when CompareString is called on 'item2' and 'item12'","collate.New initialized with language.Swedish returns 1 when CompareString compares 'ö' and 'z'"],"goal":"verify collate.Collator.CompareString in pkg:golang/golang.org/x/text@v0.34.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.34.0"],"schemaVersion":1,"symbols":["collate.Collator.CompareString"]},"contractCommand":["go","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","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/text@v0.34.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.34.0","symbols":["collate.Collator.CompareString"],"verifierAdapter":"golang@1"}
go.mod
module sample-851534276

go 1.24.0

require golang.org/x/text v0.34.0
go.sum
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
sample.go
package sample

import (
	"golang.org/x/text/collate"
	"golang.org/x/text/language"
)

// CompareStrings compares two strings using the specified language tag and collation options.
func CompareStrings(tag language.Tag, a, b string, opts ...collate.Option) int {
	c := collate.New(tag, opts...)
	return c.CompareString(a, b)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify collate.Collator.CompareString in pkg:golang/golang.org/x/text@v0.34.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/text@v0.34.0"
  ],
  "symbols": [
    "collate.Collator.CompareString"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}

Ursprungs-Seeder

anonym