Files
sx/examples/0106-types-compound-assign-global.sx
agra 4e942b5373 test: migrate examples to XXXX-category-name layout + split expected streams
Rename all example tests/companions to the XXXX-category-test-name scheme
(per-category 100-blocks: basic 0010, types 0100, ... errors 1000,
diagnostics 1100, ffi 1200, ffi-objc 1300, ffi-jni 1400, vectors 1500,
platform 1600). Companions and dir/C fixtures move in lockstep with their
parent test; #import/#source/#include paths rewritten to match.

Expected output now lives in examples/expected/ (a sibling dir of the
tests) split into three streams per the new convention:
  <name>.exit / <name>.stdout / <name>.stderr  (+ optional <name>.ir)

run_examples.sh rewritten: scans examples/ and issues/ for an
expected/<name>.exit marker, captures stdout and stderr separately (no
more 2>&1), compares each stream + exit + optional IR snapshot.

Behavior validated unchanged: every renamed test reproduces its prior
merged output + exit (diffs limited to file paths/basenames embedded in
diagnostics + traces, which correctly reflect the new names). Suite:
292 passed, 0 failed. 50-smoke.sx split + issue relocation + docs follow
in subsequent commits.
2026-06-01 19:05:15 +03:00

56 lines
1.1 KiB
Plaintext

// Test: compound assignment operators on global variables
// Ensures += -= *= /= %= &= |= ^= <<= >>= all do load-modify-store
#import "modules/std.sx";
g_add : s64 = 10;
g_sub : s64 = 10;
g_mul : s64 = 10;
g_div : s64 = 100;
g_mod : s64 = 10;
g_and : s64 = 0xff;
g_or : s64 = 0x0f;
g_xor : s64 = 0xff;
g_shl : s64 = 1;
g_shr : s64 = 256;
main :: () -> void {
// += repeated: should accumulate, not reset
g_add += 1;
g_add += 1;
g_add += 1;
print("add: {}\n", g_add); // 13
g_sub -= 3;
g_sub -= 2;
print("sub: {}\n", g_sub); // 5
g_mul *= 2;
g_mul *= 3;
print("mul: {}\n", g_mul); // 60
g_div /= 5;
g_div /= 4;
print("div: {}\n", g_div); // 5
g_mod %= 3;
print("mod: {}\n", g_mod); // 1
g_and &= 0x0f;
print("and: {}\n", g_and); // 15
g_or |= 0xf0;
print("or: {}\n", g_or); // 255
g_xor ^= 0x0f;
print("xor: {}\n", g_xor); // 240
g_shl <<= 4;
g_shl <<= 2;
print("shl: {}\n", g_shl); // 64
g_shr >>= 3;
g_shr >>= 2;
print("shr: {}\n", g_shr); // 8
}