CodeSampleX

サンプル

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

検証済みサンプル — golang golang.org/x/net v0.51.0: html.NewTokenizer. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: html.NewTokenizer tokenizes HTML…

sha256:9a95fd15235c1ad701efad5d427e96dbdb8b0bfc6ad40fca61611682bc45be2d

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

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
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-07

ケース

HOW
ゴール
verify golang.org/x/net/html.NewTokenizer in pkg:golang/golang.org/x/net@v0.51.0
パッケージ
シンボル
  • golang.org/x/net/html.NewTokenizer
作成日
2026-09-07T01:15:26Z

コントラクト

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

ファイル

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

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.51.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:d8fe40970d6df181ebc873f231217336c7d0ddfb267290270b4acf0fe06e2a66","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.51.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.51.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.51.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.51.0","symbols":["golang.org/x/net/html.NewTokenizer"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require golang.org/x/net v0.51.0
go.sum
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
main.go
package main

import (
	"fmt"
	"io"
	"log"
	"strings"

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

func main() {
	rawHTML := `<div class="container"><a href="https://example.com">Link</a><img src="test.png" alt="Test" /></div>`

	fmt.Println("--- Tokenizer Demo ---")
	z := html.NewTokenizer(strings.NewReader(rawHTML))
	for {
		tt := z.Next()
		if tt == html.ErrorToken {
			err := z.Err()
			if err == io.EOF {
				break
			}
			log.Fatalf("tokenizer error: %v", err)
		}

		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.51.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.51.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 1: html.NewTokenizer tokenizes HTML stream and identifies start tags, end tags, self-closing tags, and text tokens with their attributes
	{
		input := `<div id="main"><p class="text">Hello, World!</p><img src="example.png" alt="Image" /><!-- comment --></div>`
		z := html.NewTokenizer(strings.NewReader(input))

		type tokenRecord struct {
			tokType html.TokenType
			tag     string
			data    string
			attrs   map[string]string
		}

		var tokens []tokenRecord
		for {
			tt := z.Next()
			if tt == html.ErrorToken {
				if z.Err() == io.EOF {
					break
				}
				fmt.Fprintf(os.Stderr, "assertion 1 failed: 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
			}

			tokens = append(tokens, tokenRecord{
				tokType: tt,
				tag:     tok.Data,
				data:    tok.Data,
				attrs:   attrs,
			})
		}

		if len(tokens) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected tokens, got none\n")
			os.Exit(1)
		}

		// Verify StartTagToken <div id="main">
		if tokens[0].tokType != html.StartTagToken || tokens[0].tag != "div" || tokens[0].attrs["id"] != "main" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected first token %+v\n", tokens[0])
			os.Exit(1)
		}

		// Verify StartTagToken <p class="text">
		if tokens[1].tokType != html.StartTagToken || tokens[1].tag != "p" || tokens[1].attrs["class"] != "text" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected second token %+v\n", tokens[1])
			os.Exit(1)
		}

		// Verify TextToken "Hello, World!"
		if tokens[2].tokType != html.TextToken || tokens[2].data != "Hello, World!" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected text token %+v\n", tokens[2])
			os.Exit(1)
		}

		// Verify EndTagToken </p>
		if tokens[3].tokType != html.EndTagToken || tokens[3].tag != "p" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected end tag token %+v\n", tokens[3])
			os.Exit(1)
		}

		// Verify SelfClosingTagToken <img ... />
		if tokens[4].tokType != html.SelfClosingTagToken || tokens[4].tag != "img" || tokens[4].attrs["src"] != "example.png" || tokens[4].attrs["alt"] != "Image" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected self-closing tag token %+v\n", tokens[4])
			os.Exit(1)
		}

		// Verify CommentToken
		if tokens[5].tokType != html.CommentToken || tokens[5].data != " comment " {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected comment token %+v\n", tokens[5])
			os.Exit(1)
		}

		// Verify EndTagToken </div>
		if tokens[6].tokType != html.EndTagToken || tokens[6].tag != "div" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected final end tag token %+v\n", tokens[6])
			os.Exit(1)
		}

		// Also verify low-level TagName and TagAttr methods on tokenizer
		z2 := html.NewTokenizer(strings.NewReader(`<input type="text" name="user" required />`))
		if tt := z2.Next(); tt != html.SelfClosingTagToken {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected SelfClosingTagToken, got %v\n", tt)
			os.Exit(1)
		}
		tagName, hasAttr := z2.TagName()
		if string(tagName) != "input" || !hasAttr {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: TagName expected 'input', true; got %q, %v\n", string(tagName), hasAttr)
			os.Exit(1)
		}
		key, val, more := z2.TagAttr()
		if string(key) != "type" || string(val) != "text" || !more {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: first TagAttr mismatch\n")
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed.")
}

オリジンシーダー

匿名