test: group examples into per-category folders

Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
This commit is contained in:
agra
2026-06-21 14:41:34 +03:00
parent 6d1409bc1f
commit 66bdc70bf1
3357 changed files with 456 additions and 363 deletions

View File

@@ -0,0 +1,37 @@
// The sx library ships SQLite: `#import "vendors/sqlite/sqlite.sx"`
// resolves through the stdlib search paths, compiles the vendored
// amalgamation as a `#import c` unit (cached), and the bindings just
// work — no system dependency, no flags. Pins the vendored version
// (an OS libsqlite3 of another version must never shadow the unit)
// and a typed round trip.
#import "modules/std.sx";
sq :: #import "vendors/sqlite/sqlite.sx";
main :: () -> i32 {
v := sq.sqlite_version();
if v != "3.53.2" {
print("unexpected sqlite version: {}\n", v);
return 1;
}
db, oe := sq.Sqlite.open(":memory:");
if oe { print("open failed\n"); return 1; }
ee := false;
db.exec("CREATE TABLE t (name TEXT, n INTEGER); INSERT INTO t VALUES ('a', 1), ('b', 2)") catch { ee = true; };
if ee { print("exec failed: {}\n", db.errmsg()); db.close(); return 1; }
st, pe := db.prepare("SELECT name, n FROM t WHERE n > ?1 ORDER BY n");
if pe { print("prepare failed\n"); db.close(); return 1; }
st.bind_int64(1, 1) catch { ee = true; };
rc, se := st.step();
serr := false;
if se { serr = true; }
if serr or ee { print("step failed\n"); st.finalize(); db.close(); return 1; }
if rc == sq.SQLITE_ROW {
print("row: {} {}\n", st.column_text(0), st.column_int64(1));
}
st.finalize();
db.close();
print("vendored sqlite {} ok\n", v);
0
}

View File

@@ -0,0 +1,35 @@
// The sx library ships stb_image: `#import "vendors/stb_image/
// stb_image.sx"` resolves through the stdlib search paths and the
// implementation compiles through the object cache. Decodes a 2x2
// 24-bit BMP built in memory — fully deterministic: dimensions,
// channel count, and the top-left pixel (blue) are pinned.
#import "modules/std.sx";
stb :: #import "vendors/stb_image/stb_image.sx";
main :: () -> i32 {
// BITMAPFILEHEADER (14) + BITMAPINFOHEADER (40) + 2 rows of
// 2 BGR pixels padded to 4-byte rows (8 each) = 70 bytes.
// Bottom row: red, green; top row: blue, white (BMP is bottom-up).
bmp : [70]u8 = .{
66, 77, 70, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0,
40, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 24, 0,
0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 255, 0, 255, 0, 0, 0,
255, 0, 0, 255, 255, 255, 0, 0,
};
w : i32 = 0;
h : i32 = 0;
ch : i32 = 0;
img := stb.stbi_load_from_memory(@bmp[0], 70, @w, @h, @ch, 3);
if xx img == 0 {
print("decode failed\n");
return 1;
}
p : [*]u8 = xx img;
print("decoded {}x{} ({} channels)\n", w, h, ch);
print("top-left pixel: {} {} {}\n", p[0], p[1], p[2]);
stb.stbi_image_free(xx img);
0
}

View File

@@ -0,0 +1,36 @@
// The sx library ships stb_truetype: `#import "vendors/stb_truetype/
// stb_truetype.sx"` resolves through the stdlib search paths and the
// implementation compiles through the object cache. Loads the system
// Helvetica collection and pins INVARIANTS only (font versions vary
// across macOS releases): init succeeds, the pixel-height scale is
// positive, the ascender is positive and the descender negative.
#import "modules/std.sx";
fs :: #import "modules/std/fs.sx";
tt :: #import "vendors/stb_truetype/stb_truetype.sx";
main :: () -> i32 {
data := fs.read_file("/System/Library/Fonts/Helvetica.ttc");
if data == null {
print("font missing\n");
return 1;
}
bytes := data!;
off := tt.stbtt_GetFontOffsetForIndex(bytes.ptr, 0);
print("font offset >= 0: {}\n", off >= 0);
info : *void = xx context.allocator.alloc_bytes(256);
ok := tt.stbtt_InitFont(info, bytes.ptr, off);
print("init ok: {}\n", ok != 0);
px : f32 = 32.0;
scale := tt.stbtt_ScaleForPixelHeight(info, px);
print("scale > 0: {}\n", scale > 0.0);
ascent : i32 = 0;
descent : i32 = 0;
linegap : i32 = 0;
tt.stbtt_GetFontVMetrics(info, @ascent, @descent, @linegap);
print("ascent > 0, descent < 0: {} {}\n", ascent > 0, descent < 0);
0
}

View File

@@ -0,0 +1,28 @@
// The sx library ships kb_text_shape: `#import "vendors/kb_text_shape/
// kb_text_shape.sx"` resolves through the stdlib search paths and the
// ~30k-line implementation compiles through the object cache (decls
// come from the curated c/kbts_api.h). Pins INVARIANTS only: a shape
// context constructs, the system Helvetica loads as a shaping font,
// and teardown is clean.
#import "modules/std.sx";
fs :: #import "modules/std/fs.sx";
kb :: #import "vendors/kb_text_shape/kb_text_shape.sx";
main :: () -> i32 {
data := fs.read_file("/System/Library/Fonts/Helvetica.ttc");
if data == null {
print("font missing\n");
return 1;
}
bytes := data!;
ctx := kb.kbts_CreateShapeContext(xx 0, xx 0);
print("context created: {}\n", xx ctx != 0);
font := kb.kbts_ShapePushFontFromMemory(ctx, xx bytes.ptr, xx bytes.len, 0);
print("font pushed: {}\n", xx font != 0);
kb.kbts_DestroyShapeContext(ctx);
print("context destroyed\n");
0
}

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,2 @@
row: b 2
vendored sqlite 3.53.2 ok

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,2 @@
decoded 2x2 (3 channels)
top-left pixel: 0 0 255

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,4 @@
font offset >= 0: true
init ok: true
scale > 0: true
ascent > 0, descent < 0: true true

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,3 @@
context created: true
font pushed: true
context destroyed