Sample
golang.org/x/text v0.31.0: japanese.ShiftJIS
Verified sample for golang golang.org/x/text v0.31.0: japanese.ShiftJIS. The contract ran on go 1.26 · linux debian/x64 · docker and passed.
sha256:d88e777f53472c608a02b99cb95bcd30810597795f1d97e50fdf7d46f6117d4e
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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 |
Case
HOW- Goal
- verify golang.org/x/text/encoding/japanese.ShiftJIS in pkg:golang/golang.org/x/text@v0.31.0
- Packages
- Symbols
-
- golang.org/x/text/encoding/japanese.ShiftJIS
- Environment
- go 1.26.6
- Created
- 2026-10-11T19:20:05Z
Contract
- japanese.ShiftJIS.NewEncoder encodes UTF-8 text and strings to Shift_JIS bytes
- japanese.ShiftJIS.NewDecoder decodes Shift_JIS bytes to UTF-8 text and strings
- japanese.ShiftJIS encoder and decoder round-trip Japanese kanji and kana strings losslessly
- japanese.ShiftJIS.NewDecoder Reader wraps an io.Reader to stream-decode Shift_JIS data into UTF-8
- japanese.ShiftJIS.NewEncoder Writer wraps an io.Writer to stream-encode UTF-8 data into Shift_JIS
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
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/encoding/japanese.ShiftJIS in pkg:golang/golang.org/x/text@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/text@v0.31.0
Demonstrate these symbols/APIs:
- golang.org/x/text/encoding/japanese.ShiftJIS
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.
{"case":{"caseId":"case:sha256:45d5cfc54039b3821802bda6f67578a4faf192184277475df2ad235c840d5c29","contract":["japanese.ShiftJIS.NewEncoder encodes UTF-8 text and strings to Shift_JIS bytes","japanese.ShiftJIS.NewDecoder decodes Shift_JIS bytes to UTF-8 text and strings","japanese.ShiftJIS encoder and decoder round-trip Japanese kanji and kana strings losslessly","japanese.ShiftJIS.NewDecoder Reader wraps an io.Reader to stream-decode Shift_JIS data into UTF-8","japanese.ShiftJIS.NewEncoder Writer wraps an io.Writer to stream-encode UTF-8 data into Shift_JIS"],"goal":"verify golang.org/x/text/encoding/japanese.ShiftJIS in pkg:golang/golang.org/x/text@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/text@v0.31.0"],"schemaVersion":1,"symbols":["golang.org/x/text/encoding/japanese.ShiftJIS"]},"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.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/text@v0.31.0","symbols":["golang.org/x/text/encoding/japanese.ShiftJIS"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require golang.org/x/text v0.31.0
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
package main
import (
"bytes"
"fmt"
"io"
"strings"
"golang.org/x/text/encoding/japanese"
)
func main() {
// Demonstrating golang.org/x/text/encoding/japanese.ShiftJIS
// ShiftJIS is the Shift_JIS encoding transformer between UTF-8 and Shift_JIS.
// 1. Encoding UTF-8 text to Shift_JIS bytes and strings
encoder := japanese.ShiftJIS.NewEncoder()
utf8Text := "こんにちは世界" // "Hello World" in Japanese
sjisBytes, err := encoder.Bytes([]byte(utf8Text))
if err != nil {
fmt.Printf("Encode error: %v\n", err)
return
}
fmt.Printf("Encoded Shift_JIS hex: % x\n", sjisBytes)
sjisStr, err := encoder.String("日本語")
if err != nil {
fmt.Printf("Encode string error: %v\n", err)
return
}
fmt.Printf("Encoded string byte length: %d\n", len(sjisStr))
// 2. Decoding Shift_JIS bytes to UTF-8
decoder := japanese.ShiftJIS.NewDecoder()
decodedBytes, err := decoder.Bytes(sjisBytes)
if err != nil {
fmt.Printf("Decode error: %v\n", err)
return
}
fmt.Printf("Decoded UTF-8 text: %s\n", string(decodedBytes))
decodedStr, err := decoder.String(sjisStr)
if err != nil {
fmt.Printf("Decode string error: %v\n", err)
return
}
fmt.Printf("Decoded string: %s\n", decodedStr)
// 3. Streaming decode with Reader
sjisReader := strings.NewReader(string(sjisBytes))
transformReader := decoder.Reader(sjisReader)
streamDecoded, err := io.ReadAll(transformReader)
if err != nil {
fmt.Printf("Reader stream error: %v\n", err)
return
}
fmt.Printf("Reader stream output: %s\n", string(streamDecoded))
// 4. Streaming encode with Writer
var buf bytes.Buffer
transformWriter := encoder.Writer(&buf)
_, err = transformWriter.Write([]byte("プログラミング"))
if err != nil {
fmt.Printf("Writer stream error: %v\n", err)
return
}
fmt.Printf("Writer stream buffer length: %d bytes\n", buf.Len())
// 5. Half-width Katakana support in Shift_JIS
hankakuText := "テスト"
hankakuEncoded, err := encoder.String(hankakuText)
if err != nil {
fmt.Printf("Half-width katakana encode error: %v\n", err)
return
}
hankakuDecoded, err := decoder.String(hankakuEncoded)
if err != nil {
fmt.Printf("Half-width katakana decode error: %v\n", err)
return
}
fmt.Printf("Half-width round-trip: %s\n", hankakuDecoded)
fmt.Println("golang.org/x/text/encoding/japanese.ShiftJIS demonstrated successfully.")
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/text/encoding/japanese.ShiftJIS in pkg:golang/golang.org/x/text@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/text@v0.31.0"
],
"symbols": [
"golang.org/x/text/encoding/japanese.ShiftJIS"
]
}
package main
import (
"bytes"
"fmt"
"io"
"os"
"golang.org/x/text/encoding/japanese"
)
func main() {
// Assertion 1: japanese.ShiftJIS.NewEncoder encodes UTF-8 text and strings to Shift_JIS bytes
{
encoder := japanese.ShiftJIS.NewEncoder()
if encoder == nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: NewEncoder returned nil\n")
os.Exit(1)
}
utf8Input := "こんにちは世界"
expectedSJIS := []byte{0x82, 0xb1, 0x82, 0xf1, 0x82, 0xc9, 0x82, 0xbf, 0x82, 0xcd, 0x90, 0xa2, 0x8a, 0x45}
encodedBytes, err := encoder.Bytes([]byte(utf8Input))
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: Bytes returned error: %v\n", err)
os.Exit(1)
}
if !bytes.Equal(encodedBytes, expectedSJIS) {
fmt.Fprintf(os.Stderr, "assertion 1 failed: encoded bytes do not match expected Shift_JIS\n")
os.Exit(1)
}
encodedStr, err := encoder.String("日本語")
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: String returned error: %v\n", err)
os.Exit(1)
}
expectedKanji := []byte{0x93, 0xfa, 0x96, 0x7b, 0x8c, 0xea}
if !bytes.Equal([]byte(encodedStr), expectedKanji) {
fmt.Fprintf(os.Stderr, "assertion 1 failed: encoded string bytes do not match expected Kanji Shift_JIS\n")
os.Exit(1)
}
}
// Assertion 2: japanese.ShiftJIS.NewDecoder decodes Shift_JIS bytes to UTF-8 text and strings
{
decoder := japanese.ShiftJIS.NewDecoder()
if decoder == nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: NewDecoder returned nil\n")
os.Exit(1)
}
sjisBytes := []byte{0x82, 0xb1, 0x82, 0xf1, 0x82, 0xc9, 0x82, 0xbf, 0x82, 0xcd, 0x90, 0xa2, 0x8a, 0x45}
expectedUTF8 := "こんにちは世界"
decodedBytes, err := decoder.Bytes(sjisBytes)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: Bytes returned error: %v\n", err)
os.Exit(1)
}
if string(decodedBytes) != expectedUTF8 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: decoded bytes do not match expected UTF-8 text\n")
os.Exit(1)
}
kanjiSJIS := string([]byte{0x93, 0xfa, 0x96, 0x7b, 0x8c, 0xea})
decodedStr, err := decoder.String(kanjiSJIS)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: String returned error: %v\n", err)
os.Exit(1)
}
if decodedStr != "日本語" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: decoded string does not match expected Kanji UTF-8 text\n")
os.Exit(1)
}
}
// Assertion 3: japanese.ShiftJIS encoder and decoder round-trip Japanese kanji and kana strings losslessly
{
encoder := japanese.ShiftJIS.NewEncoder()
decoder := japanese.ShiftJIS.NewDecoder()
testTexts := []string{
"English and ASCII 12345 !@#$",
"ひらがな カタカナ 漢字",
"半角カタカナ テスト 123",
"Shift_JIS 互換性テスト文字列",
}
for _, text := range testTexts {
encoded, err := encoder.String(text)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: encode error on %q: %v\n", text, err)
os.Exit(1)
}
decoded, err := decoder.String(encoded)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: decode error on %q: %v\n", text, err)
os.Exit(1)
}
if decoded != text {
fmt.Fprintf(os.Stderr, "assertion 3 failed: round-trip mismatch. Expected %q, got %q\n", text, decoded)
os.Exit(1)
}
}
}
// Assertion 4: japanese.ShiftJIS.NewDecoder Reader wraps an io.Reader to stream-decode Shift_JIS data into UTF-8
{
sjisInput := []byte{0x82, 0xb1, 0x82, 0xf1, 0x82, 0xc9, 0x82, 0xbf, 0x82, 0xcd, 0x90, 0xa2, 0x8a, 0x45}
rawReader := bytes.NewReader(sjisInput)
transformReader := japanese.ShiftJIS.NewDecoder().Reader(rawReader)
streamOutput, err := io.ReadAll(transformReader)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: io.ReadAll returned error: %v\n", err)
os.Exit(1)
}
expected := "こんにちは世界"
if string(streamOutput) != expected {
fmt.Fprintf(os.Stderr, "assertion 4 failed: stream output %q != expected %q\n", string(streamOutput), expected)
os.Exit(1)
}
}
// Assertion 5: japanese.ShiftJIS.NewEncoder Writer wraps an io.Writer to stream-encode UTF-8 data into Shift_JIS
{
utf8Input := []byte("こんにちは世界")
var buf bytes.Buffer
transformWriter := japanese.ShiftJIS.NewEncoder().Writer(&buf)
n, err := transformWriter.Write(utf8Input)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Write returned error: %v\n", err)
os.Exit(1)
}
if n != len(utf8Input) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Write count mismatch: wrote %d, expected %d\n", n, len(utf8Input))
os.Exit(1)
}
expectedSJIS := []byte{0x82, 0xb1, 0x82, 0xf1, 0x82, 0xc9, 0x82, 0xbf, 0x82, 0xcd, 0x90, 0xa2, 0x8a, 0x45}
if !bytes.Equal(buf.Bytes(), expectedSJIS) {
fmt.Fprintf(os.Stderr, "assertion 5 failed: stream encoded bytes do not match expected Shift_JIS\n")
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
Origin Seeder
anonymous