CodeSampleX

샘플

golang.org/x/net v0.47.0: atom.Atom

검증된 샘플 — golang golang.org/x/net v0.47.0: atom.Atom. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: atom.Atom zero value atom.Atom(0) maps to…

sha256:bb4f0964e178884d8ed7820f2cb42541aa489f6286b1785f3dc6cc27b9efda79

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

케이스

HOW
목표
verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.47.0
패키지
심벌
  • golang.org/x/net/html/atom.Atom
생성일
2026-10-11T06:28:02Z

컨트랙트

  1. atom.Atom zero value atom.Atom(0) maps to empty string ""
  2. atom.Atom constants have non-zero integer codes whose String() returns their lowercase tag or attribute name
  3. atom.Lookup resolves valid HTML tag byte slices to non-zero atom.Atom and returns atom.Atom(0) for unknown or uppercase tags
  4. html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags
  5. atom.Atom supports direct integer equality comparison between element DataAtom and atom constants

파일

  • PROMPT.md
  • atom_sample.go
  • csx.json
  • go.mod
  • go.sum
  • 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/atom.Atom in pkg:golang/golang.org/x/net@v0.47.0
Kind: HOW

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

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

import (
	"strings"

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

// IsKnownAtom checks if the atom is a non-zero known atom.
func IsKnownAtom(a atom.Atom) bool {
	return a != 0
}

// AtomName returns the string representation of an atom.
func AtomName(a atom.Atom) string {
	return a.String()
}

// ResolveAtom resolves a byte slice to an Atom using atom.Lookup.
func ResolveAtom(tag []byte) atom.Atom {
	return atom.Lookup(tag)
}

// MatchDataAtom checks if an HTML node's DataAtom matches the expected atom.
func MatchDataAtom(n *html.Node, expected atom.Atom) bool {
	if n == nil {
		return false
	}
	return n.DataAtom == expected
}

// FindFirstByAtom finds the first descendant ElementNode matching the given atom.
func FindFirstByAtom(n *html.Node, target atom.Atom) *html.Node {
	if n == nil {
		return nil
	}
	if n.Type == html.ElementNode && n.DataAtom == target {
		return n
	}
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		if found := FindFirstByAtom(c, target); found != nil {
			return found
		}
	}
	return nil
}

// ParseHTML parses an HTML document and returns the root Node.
func ParseHTML(htmlContent string) (*html.Node, error) {
	return html.Parse(strings.NewReader(htmlContent))
}
csx.json
{"case":{"caseId":"case:sha256:30bd424c836d5e8abd4f6d4dc1645294834084a12a0df9a29ea446111a30f54d","contract":["atom.Atom zero value atom.Atom(0) maps to empty string \"\"","atom.Atom constants have non-zero integer codes whose String() returns their lowercase tag or attribute name","atom.Lookup resolves valid HTML tag byte slices to non-zero atom.Atom and returns atom.Atom(0) for unknown or uppercase tags","html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags","atom.Atom supports direct integer equality comparison between element DataAtom and atom constants"],"goal":"verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.47.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.47.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html/atom.Atom"]},"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.47.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.47.0","symbols":["golang.org/x/net/html/atom.Atom"],"verifierAdapter":"golang@1"}
go.mod
module example.com/atomsample

go 1.26.6

require golang.org/x/net v0.47.0
go.sum
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.47.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.47.0"
  ],
  "symbols": [
    "golang.org/x/net/html/atom.Atom"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	sample "example.com/atomsample"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

func main() {
	// Assertion 1: atom.Atom zero value maps to empty string ""
	var zeroAtom atom.Atom
	if zeroAtom != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected zero atom to be 0, got %v\n", zeroAtom)
		os.Exit(1)
	}
	if zeroAtom.String() != "" {
		fmt.Fprintf(os.Stderr, "FAIL: expected zeroAtom.String() == \"\", got %q\n", zeroAtom.String())
		os.Exit(1)
	}
	if sample.IsKnownAtom(zeroAtom) {
		fmt.Fprintf(os.Stderr, "FAIL: sample.IsKnownAtom(zeroAtom) returned true for zero atom\n")
		os.Exit(1)
	}

	// Assertion 2: atom.Atom constants have non-zero integer codes whose String() returns their lowercase tag or attribute name
	atoms := []struct {
		a    atom.Atom
		name string
	}{
		{atom.Div, "div"},
		{atom.Span, "span"},
		{atom.A, "a"},
		{atom.P, "p"},
		{atom.Body, "body"},
		{atom.Table, "table"},
		{atom.Input, "input"},
	}
	for _, tc := range atoms {
		if tc.a == 0 {
			fmt.Fprintf(os.Stderr, "FAIL: expected non-zero atom for %s\n", tc.name)
			os.Exit(1)
		}
		if tc.a.String() != tc.name {
			fmt.Fprintf(os.Stderr, "FAIL: expected atom %s.String() == %q, got %q\n", tc.name, tc.name, tc.a.String())
			os.Exit(1)
		}
		if sample.AtomName(tc.a) != tc.name {
			fmt.Fprintf(os.Stderr, "FAIL: expected sample.AtomName(%s) == %q, got %q\n", tc.name, tc.name, sample.AtomName(tc.a))
			os.Exit(1)
		}
		if !sample.IsKnownAtom(tc.a) {
			fmt.Fprintf(os.Stderr, "FAIL: expected sample.IsKnownAtom(%s) == true\n", tc.name)
			os.Exit(1)
		}
	}

	// Assertion 3: atom.Lookup resolves valid HTML tag byte slices to non-zero atom.Atom and returns atom.Atom(0) for unknown or uppercase tags
	if lookupDiv := sample.ResolveAtom([]byte("div")); lookupDiv != atom.Div {
		fmt.Fprintf(os.Stderr, "FAIL: ResolveAtom(\"div\") expected atom.Div, got %v\n", lookupDiv)
		os.Exit(1)
	}
	if lookupUpper := sample.ResolveAtom([]byte("DIV")); lookupUpper != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: ResolveAtom(\"DIV\") expected 0, got %v\n", lookupUpper)
		os.Exit(1)
	}
	if lookupUnknown := sample.ResolveAtom([]byte("custom-element-tag")); lookupUnknown != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: ResolveAtom(\"custom-element-tag\") expected 0, got %v\n", lookupUnknown)
		os.Exit(1)
	}
	if lookupEmpty := sample.ResolveAtom([]byte("")); lookupEmpty != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: ResolveAtom(\"\") expected 0, got %v\n", lookupEmpty)
		os.Exit(1)
	}

	// Assertion 4: html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags
	rawHTML := `<!DOCTYPE html><html><body><div id="wrapper"><span class="highlight">Text</span><custom-widget>Custom</custom-widget></div></body></html>`
	doc, err := sample.ParseHTML(rawHTML)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ParseHTML failed: %v\n", err)
		os.Exit(1)
	}

	divNode := sample.FindFirstByAtom(doc, atom.Div)
	if divNode == nil {
		fmt.Fprintf(os.Stderr, "FAIL: FindFirstByAtom(atom.Div) returned nil\n")
		os.Exit(1)
	}
	if divNode.DataAtom != atom.Div {
		fmt.Fprintf(os.Stderr, "FAIL: expected divNode.DataAtom == atom.Div, got %v\n", divNode.DataAtom)
		os.Exit(1)
	}
	if divNode.Data != "div" {
		fmt.Fprintf(os.Stderr, "FAIL: expected divNode.Data == \"div\", got %q\n", divNode.Data)
		os.Exit(1)
	}

	spanNode := sample.FindFirstByAtom(divNode, atom.Span)
	if spanNode == nil {
		fmt.Fprintf(os.Stderr, "FAIL: FindFirstByAtom(atom.Span) returned nil\n")
		os.Exit(1)
	}
	if spanNode.DataAtom != atom.Span {
		fmt.Fprintf(os.Stderr, "FAIL: expected spanNode.DataAtom == atom.Span, got %v\n", spanNode.DataAtom)
		os.Exit(1)
	}

	// Check custom tag has DataAtom == 0
	var customNode *html.Node
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n.Type == html.ElementNode && n.Data == "custom-widget" {
			customNode = n
			return
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(doc)
	if customNode == nil {
		fmt.Fprintf(os.Stderr, "FAIL: custom-widget node not found\n")
		os.Exit(1)
	}
	if customNode.DataAtom != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected customNode.DataAtom == 0, got %v\n", customNode.DataAtom)
		os.Exit(1)
	}

	// Assertion 5: atom.Atom supports direct integer equality comparison between element DataAtom and atom constants
	if !sample.MatchDataAtom(divNode, atom.Div) {
		fmt.Fprintf(os.Stderr, "FAIL: MatchDataAtom(divNode, atom.Div) returned false\n")
		os.Exit(1)
	}
	if sample.MatchDataAtom(divNode, atom.Span) {
		fmt.Fprintf(os.Stderr, "FAIL: MatchDataAtom(divNode, atom.Span) returned true\n")
		os.Exit(1)
	}

	fmt.Println("PASS: golang.org/x/net/html/atom.Atom contract passed")
}

오리진 시더

익명