aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/08-bit.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-16 12:11:18 +0100
committerlemon <lsof@mailbox.org>2025-11-16 12:11:18 +0100
commit111e71e1511b2abff9176bd6c714c8da796f770e (patch)
tree352b723c9144c844037447bd865a8366378df7a5 /test/08-bit.c
parentb0c0f2d2d885c5901de08ed08dba9fff079bf6e3 (diff)
basic automated testing
Diffstat (limited to 'test/08-bit.c')
-rw-r--r--test/08-bit.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/08-bit.c b/test/08-bit.c
new file mode 100644
index 0000000..5854cad
--- /dev/null
+++ b/test/08-bit.c
@@ -0,0 +1,64 @@
+/* EXPECT:
+expect 6, -4, 7, -1
+ 6, -4, 7, -1
+*/
+
+int xor(int a) {
+ return a ^ 3 | 555;
+}
+
+int cmp(float x, float y) {
+ return x < y && x > 0.f;
+}
+
+struct foo {
+ unsigned int x : 10;
+ unsigned y : 7;
+ short k:3;
+int : 0;
+ short a:15;
+ long long h:60;
+};
+
+int bitf(struct foo *q) {
+ extern void aeiou(int);
+ aeiou(q->h);
+ return q->x + q->y - q->k + q->a;
+}
+
+struct s1 {
+ short x : 3, y : 12;
+};
+struct s2 {
+ struct s1 a;
+};
+
+struct s2 bitfcopy2(struct s2 x) {
+ return (struct s2){x.a};
+}
+
+int main(int p) {
+ extern int printf(const char *, ...);
+
+ static struct foo foo;
+
+ foo.x = 5+p;
+ foo.k = 3;
+ foo.h += 7;
+ bitf(&foo);
+ foo.a = -1;
+ foo.a = xor(foo.a |= 3);
+ printf("expect %d, -4, 7, %d\n", 5+p, (short)((-1|3)^3|555));
+ printf(" %d, %d, %lld, %d\n", foo.x, foo.k+=1, foo.h, foo.a);
+
+ int x = 42,
+ *a = &x,
+ **b = &a,
+ ***c = &b,
+ ****d = &c,
+ *****e = &d,
+ ******f = &e;
+ return ******f;
+}
+
+void aeiou(int _){}