test: split 50-smoke.sx into per-section examples + add errors smoke
Break the monolithic examples/50-smoke.sx into 30 focused per-section examples,
filed into their category blocks (basic/types/comptime/memory/protocols/ffi),
each carrying only the top-level decls its section references (the protocols
section keeps the full preamble — its deps flow through UFCS method calls that
name-based extraction can't see). Outputs verified identical to the original
section blocks.
Add examples/1036-errors-failable-smoke.sx — an end-to-end error-handling example
(the E5.4 work): named + inferred error sets consumed via destructure, try (in
helpers), catch (bare-expr / match-body / diverging / no-binding), or
value-terminator, onfail+defer interleave, and error.X value + {} tag
interpolation.
Remove examples/50-smoke.sx. Suite: 324 passed, 0 failed.
This commit is contained in:
106
examples/0122-types-flags.sx
Normal file
106
examples/0122-types-flags.sx
Normal file
@@ -0,0 +1,106 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/math/math.sx";
|
||||
#import "modules/compiler.sx";
|
||||
#import "modules/test.sx";
|
||||
pkg :: #import "modules/testpkg";
|
||||
|
||||
Perms :: enum flags { read; write; execute; }
|
||||
|
||||
WindowFlags :: enum flags u32 { vsync :: 64; resizable :: 4; hidden :: 128; }
|
||||
|
||||
// --- Top-level functions ---
|
||||
|
||||
main :: () {
|
||||
|
||||
// ========================================================
|
||||
// 9. FLAGS
|
||||
// ========================================================
|
||||
print("=== 9. Flags ===\n");
|
||||
|
||||
// Combine flags
|
||||
perm : Perms = .read | .write;
|
||||
print("flags: {}\n", perm);
|
||||
|
||||
// Test flag
|
||||
if perm & .read { print("has-read: yes\n"); }
|
||||
if perm & .execute { print("has-exec: yes\n"); }
|
||||
|
||||
// Test flag negative
|
||||
pt : Perms = .write;
|
||||
if pt & .read {
|
||||
print("flags-neg: has-read\n");
|
||||
} else {
|
||||
print("flags-neg: no-read\n");
|
||||
}
|
||||
|
||||
// Single flag
|
||||
ps : Perms = .execute;
|
||||
print("flags-single: {}\n", ps);
|
||||
|
||||
// All flags
|
||||
pall : Perms = .read | .write | .execute;
|
||||
print("flags-all: {}\n", pall);
|
||||
|
||||
// Cast to int
|
||||
print("flags-raw: {}\n", cast(s64) perm);
|
||||
|
||||
// Flags with explicit values
|
||||
wf : WindowFlags = .vsync | .resizable;
|
||||
print("flags-explicit: {}\n", wf);
|
||||
print("flags-explicit-raw: {}\n", cast(s64) wf);
|
||||
|
||||
// --- Multi-target assignment (swap) ---
|
||||
print("--- swap ---\n");
|
||||
|
||||
// Variable swap
|
||||
{
|
||||
sa := 10;
|
||||
sb := 20;
|
||||
sa, sb = sb, sa;
|
||||
print("var swap: {} {}\n", sa, sb);
|
||||
}
|
||||
|
||||
// Array element swap
|
||||
{
|
||||
sarr : [3]s64 = .[1, 2, 3];
|
||||
sarr[0], sarr[2] = sarr[2], sarr[0];
|
||||
print("arr swap: {} {}\n", sarr[0], sarr[2]);
|
||||
}
|
||||
|
||||
// 3-way rotation
|
||||
{
|
||||
ra := 1;
|
||||
rb := 2;
|
||||
rc := 3;
|
||||
ra, rb, rc = rc, ra, rb;
|
||||
print("3-way: {} {} {}\n", ra, rb, rc);
|
||||
}
|
||||
|
||||
// --- Tuple destructuring ---
|
||||
print("--- destructure ---\n");
|
||||
|
||||
// Basic tuple destructuring
|
||||
{
|
||||
da, db := (10, 20);
|
||||
print("basic: {} {}\n", da, db);
|
||||
}
|
||||
|
||||
// Destructure from function return
|
||||
{
|
||||
dswap :: (a: s64, b: s64) -> (s64, s64) { (b, a); }
|
||||
dx, dy := dswap(1, 2);
|
||||
print("fn: {} {}\n", dx, dy);
|
||||
}
|
||||
|
||||
// Discard with _
|
||||
{
|
||||
_, dsecond := (100, 200);
|
||||
print("discard: {}\n", dsecond);
|
||||
}
|
||||
|
||||
// Three elements
|
||||
{
|
||||
da3, db3, dc3 := (1, 2, 3);
|
||||
print("triple: {} {} {}\n", da3, db3, dc3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user