CodeSampleX

Exemple

golang.org/x/net v0.61.0: html.NewTokenizer

Échantillon vérifié pour golang golang.org/x/net v0.61.0: html.NewTokenizer. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:59bd069ef76ee03be7f285582a7c9b43f3b754561d2ab2ac6b0a081ef041873f

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-10-12

Cas

HOW
Objectif
verify golang.org/x/net/html.NewTokenizer in pkg:golang/golang.org/x/net@v0.61.0
Paquets
Symboles
  • golang.org/x/net/html.NewTokenizer
Créé
2026-10-12T07:38:29Z

Contrat

  1. html.NewTokenizer tokenizes HTML stream and identifies start tags, end tags, self-closing tags, and text tokens with their attributes

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Télécharger l’artefact source (tar.gz)

Code source

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/net/html.NewTokenizer in pkg:golang/golang.org/x/net@v0.61.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.61.0
Demonstrate these symbols/APIs:
  - golang.org/x/net/html.NewTokenizer

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:edfe4858330aef251b89c4b0e5a655c55768aa00d5542a6d9dd0f35eeb86581c","contract":["html.NewTokenizer tokenizes HTML stream and identifies start tags, end tags, self-closing tags, and text tokens with their attributes"],"goal":"verify golang.org/x/net/html.NewTokenizer in pkg:golang/golang.org/x/net@v0.61.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.61.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.NewTokenizer"]},"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/net@v0.61.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.61.0","symbols":["golang.org/x/net/html.NewTokenizer"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/net v0.61.0
go.sum
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
main.go
package main

import (
	"fmt"
	"io"
	"strings"

	"golang.org/x/net/html"
)

func main() {
	doc := `<div class="container"><p>Hello World</p><img src="example.png" alt="Test" /></div>`
	z := html.NewTokenizer(strings.NewReader(doc))

	for {
		tt := z.Next()
		if tt == html.ErrorToken {
			if z.Err() == io.EOF {
				break
			}
			fmt.Printf("Tokenizer error: %v\n", z.Err())
			return
		}

		tok := z.Token()
		switch tt {
		case html.StartTagToken:
			fmt.Printf("Start tag: <%s>, attrs: %v\n", tok.Data, tok.Attr)
		case html.TextToken:
			fmt.Printf("Text: %q\n", tok.Data)
		case html.EndTagToken:
			fmt.Printf("End tag: </%s>\n", tok.Data)
		case html.SelfClosingTagToken:
			fmt.Printf("Self-closing tag: <%s/>, attrs: %v\n", tok.Data, tok.Attr)
		}
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.NewTokenizer in pkg:golang/golang.org/x/net@v0.61.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.61.0"
  ],
  "symbols": [
    "golang.org/x/net/html.NewTokenizer"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"io"
	"os"
	"strings"

	"golang.org/x/net/html"
)

func main() {
	// Assertion: html.NewTokenizer tokenizes HTML stream and identifies start tags, end tags, self-closing tags, and text tokens with their attributes
	htmlSnippet := `<div class="content"><span id="title">Example</span><img src="example.png" alt="Sample" /></div>`
	z := html.NewTokenizer(strings.NewReader(htmlSnippet))

	type recordedToken struct {
		tokenType html.TokenType
		tagName   string
		textData  string
		attrMap   map[string]string
	}

	var recorded []recordedToken

	for {
		tt := z.Next()
		if tt == html.ErrorToken {
			if z.Err() == io.EOF {
				break
			}
			fmt.Fprintf(os.Stderr, "unexpected tokenizer error: %v\n", z.Err())
			os.Exit(1)
		}

		tok := z.Token()
		attrs := make(map[string]string)
		for _, a := range tok.Attr {
			attrs[a.Key] = a.Val
		}

		recorded = append(recorded, recordedToken{
			tokenType: tt,
			tagName:   tok.Data,
			textData:  tok.Data,
			attrMap:   attrs,
		})
	}

	if len(recorded) != 6 {
		fmt.Fprintf(os.Stderr, "expected 6 tokens, got %d\n", len(recorded))
		os.Exit(1)
	}

	// 1. Start tag: <div> with class="content"
	if recorded[0].tokenType != html.StartTagToken || recorded[0].tagName != "div" || recorded[0].attrMap["class"] != "content" {
		fmt.Fprintf(os.Stderr, "token 0 mismatch: %+v\n", recorded[0])
		os.Exit(1)
	}

	// 2. Start tag: <span> with id="title"
	if recorded[1].tokenType != html.StartTagToken || recorded[1].tagName != "span" || recorded[1].attrMap["id"] != "title" {
		fmt.Fprintf(os.Stderr, "token 1 mismatch: %+v\n", recorded[1])
		os.Exit(1)
	}

	// 3. Text tag: "Example"
	if recorded[2].tokenType != html.TextToken || recorded[2].textData != "Example" {
		fmt.Fprintf(os.Stderr, "token 2 mismatch: %+v\n", recorded[2])
		os.Exit(1)
	}

	// 4. End tag: </span>
	if recorded[3].tokenType != html.EndTagToken || recorded[3].tagName != "span" {
		fmt.Fprintf(os.Stderr, "token 3 mismatch: %+v\n", recorded[3])
		os.Exit(1)
	}

	// 5. Self-closing tag: <img /> with src="example.png" and alt="Sample"
	if recorded[4].tokenType != html.SelfClosingTagToken || recorded[4].tagName != "img" ||
		recorded[4].attrMap["src"] != "example.png" || recorded[4].attrMap["alt"] != "Sample" {
		fmt.Fprintf(os.Stderr, "token 4 mismatch: %+v\n", recorded[4])
		os.Exit(1)
	}

	// 6. End tag: </div>
	if recorded[5].tokenType != html.EndTagToken || recorded[5].tagName != "div" {
		fmt.Fprintf(os.Stderr, "token 5 mismatch: %+v\n", recorded[5])
		os.Exit(1)
	}

	// Also verify raw TagName / TagAttr methods
	zRaw := html.NewTokenizer(strings.NewReader(`<input type="text" name="user" />`))
	if tt := zRaw.Next(); tt != html.SelfClosingTagToken {
		fmt.Fprintf(os.Stderr, "expected SelfClosingTagToken, got %v\n", tt)
		os.Exit(1)
	}
	name, hasAttr := zRaw.TagName()
	if string(name) != "input" || !hasAttr {
		fmt.Fprintf(os.Stderr, "TagName mismatch: got %q, %v\n", string(name), hasAttr)
		os.Exit(1)
	}
	k, v, more := zRaw.TagAttr()
	if string(k) != "type" || string(v) != "text" || !more {
		fmt.Fprintf(os.Stderr, "TagAttr mismatch: got %q=%q, more=%v\n", string(k), string(v), more)
		os.Exit(1)
	}

	fmt.Println("Contract test passed successfully.")
}

Seeder d'origine

anonyme