mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-03 13:04:26 +00:00
- yapf_encode() / yapf_free_buffer(): encode to memory; yapf_save uses it - yapf.c also compiles as C++ - `yapf compare`: size and decode speed of the original format vs YAPF, with a lossless check - bindings with tested examples: C++ (header-only), C# (P/Invoke), Rust (crate, builds the C code), Go (cgo), Java (FFM API, Java 22+), Zig (@cImport), LuaJIT (FFI), TypeScript types for the JS port; Python now encodes in memory - docs/LANGUAGES.md and examples/ with measured results - KDE Dolphin thumbnail plugin (KF6, CMake) - README: honest status for Photoshop / VS Code / Figma (not run in the apps yet) and macOS (cross-compiled only), platform table Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
971 B
Go
46 lines
971 B
Go
package yapf
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestRoundtrip(t *testing.T) {
|
|
for ch := 1; ch <= 4; ch++ {
|
|
w, h := 97, 61
|
|
px := make([]byte, w*h*ch)
|
|
for i := range px {
|
|
px[i] = byte(i*7 ^ i>>5)
|
|
}
|
|
data, err := Encode(&Image{Width: w, Height: h, Channels: ch, Flags: FlagSRGB, Pixels: px})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
back, err := Decode(data)
|
|
if err != nil || !bytes.Equal(back.Pixels, px) {
|
|
t.Fatalf("roundtrip failed for %d channels", ch)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSampleReencodesIdentically(t *testing.T) {
|
|
file, err := os.ReadFile("../../other/YAPF.YAPF")
|
|
if err != nil {
|
|
t.Skip("sample not found")
|
|
}
|
|
img, err := Decode(file)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
again, _ := Encode(img)
|
|
if !bytes.Equal(again, file) {
|
|
t.Fatal("re-encoded sample differs from the C encoder's output")
|
|
}
|
|
}
|
|
|
|
func TestRejectsGarbage(t *testing.T) {
|
|
if _, err := Decode([]byte("not an image")); err == nil {
|
|
t.Fatal("garbage was accepted")
|
|
}
|
|
}
|