Add iso646.h and corresponding tests

This commit is contained in:
Peter Limkilde Svendsen
2024-11-10 16:19:15 +01:00
parent a45c7b26d9
commit 56d05e2cdc
5 changed files with 148 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// Copied from musl
#ifndef _ISO646_H
#define _ISO646_H
#ifndef __cplusplus
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif
#endif
+1
View File
@@ -21,6 +21,7 @@ EXPECT_NAMES=\
fcntl/fcntl \
fnmatch \
futimens \
iso646 \
libgen \
locale \
math \
+33
View File
@@ -0,0 +1,33 @@
0 and 0: 0
1 and 0: 0
0 and 1: 0
1 and 1: 1
0 and_eq 0: 0
1 and_eq 0: 0
0 and_eq 1: 0
1 and_eq 1: 1
a bitand b: 8
a bitor b: 14
compl a: 245
not 0: 1
not 1: 0
0 not_eq 0: 0
1 not_eq 0: 1
0 not_eq 1: 0
1 not_eq 1: 1
0 or 0: 0
1 or 0: 1
0 or 1: 1
1 or 1: 1
0 or_eq 0: 0
1 or_eq 0: 1
0 or_eq 1: 1
1 or_eq 1: 1
0 xor 0: 0
1 xor 0: 1
0 xor 1: 1
1 xor 1: 0
0 xor_eq 0: 0
1 xor_eq 0: 1
0 xor_eq 1: 1
1 xor_eq 1: 0
+92
View File
@@ -0,0 +1,92 @@
#include <iso646.h>
#include <stdint.h>
#include <stdio.h>
#include "test_helpers.h"
int main() {
uint8_t a_bits = 0xa; // 0b0000_1010
uint8_t b_bits = 0xc; // 0b0000_1100
uint8_t c_bits;
int c_bool;
printf("0 and 0: %d\n", 0 and 0);
printf("1 and 0: %d\n", 1 and 0);
printf("0 and 1: %d\n", 0 and 1);
printf("1 and 1: %d\n", 1 and 1);
c_bool = 0;
c_bool and_eq 0;
printf("0 and_eq 0: %d\n", c_bool);
c_bool = 1;
c_bool and_eq 0;
printf("1 and_eq 0: %d\n", c_bool);
c_bool = 0;
c_bool and_eq 1;
printf("0 and_eq 1: %d\n", c_bool);
c_bool = 1;
c_bool and_eq 1;
printf("1 and_eq 1: %d\n", c_bool);
c_bits = a_bits bitand b_bits;
printf("a bitand b: %d\n", c_bits);
c_bits = a_bits bitor b_bits;
printf("a bitor b: %d\n", c_bits);
c_bits = compl a_bits;
printf("compl a: %d\n", c_bits);
printf("not 0: %d\n", not 0);
printf("not 1: %d\n", not 1);
c_bool = 0;
c_bool not_eq 0;
printf("0 not_eq 0: %d\n", c_bool);
c_bool = 1;
c_bool not_eq 0;
printf("1 not_eq 0: %d\n", c_bool);
c_bool = 0;
c_bool not_eq 1;
printf("0 not_eq 1: %d\n", c_bool);
c_bool = 1;
c_bool not_eq 1;
printf("1 not_eq 1: %d\n", c_bool);
printf("0 or 0: %d\n", 0 or 0);
printf("1 or 0: %d\n", 1 or 0);
printf("0 or 1: %d\n", 0 or 1);
printf("1 or 1: %d\n", 1 or 1);
c_bool = 0;
c_bool or_eq 0;
printf("0 or_eq 0: %d\n", c_bool);
c_bool = 1;
c_bool or_eq 0;
printf("1 or_eq 0: %d\n", c_bool);
c_bool = 0;
c_bool or_eq 1;
printf("0 or_eq 1: %d\n", c_bool);
c_bool = 1;
c_bool or_eq 1;
printf("1 or_eq 1: %d\n", c_bool);
printf("0 xor 0: %d\n", 0 xor 0);
printf("1 xor 0: %d\n", 1 xor 0);
printf("0 xor 1: %d\n", 0 xor 1);
printf("1 xor 1: %d\n", 1 xor 1);
c_bool = 0;
c_bool xor_eq 0;
printf("0 xor_eq 0: %d\n", c_bool);
c_bool = 1;
c_bool xor_eq 0;
printf("1 xor_eq 0: %d\n", c_bool);
c_bool = 0;
c_bool xor_eq 1;
printf("0 xor_eq 1: %d\n", c_bool);
c_bool = 1;
c_bool xor_eq 1;
printf("1 xor_eq 1: %d\n", c_bool);
}