aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-07 04:50:50 +0000
committerGravatar Peter McGoron 2023-02-07 04:50:50 +0000
commite0599bad23f3847d00ce38809d0bec6d8b692a6d (patch)
tree00130f41a8435d62826741e812879c13e05ee049
parentencode (diff)
fixing precedence issue in test
-rw-r--r--README.md12
-rw-r--r--test_creole.c36
2 files changed, 18 insertions, 30 deletions
diff --git a/README.md b/README.md
index ac53f79..d8de334 100644
--- a/README.md
+++ b/README.md
@@ -6,12 +6,12 @@ Each creole line consists of pseudo-UTF-8 characters. The first byte
is an unsigned number between 0 and 127 (the high bit is clear). Each
suceeding pseudo-UTF-8 character is encoded as follows:
-* `110xxxxx 10xxxxxx`
-* `1110xxxx 10xxxxxx 10xxxxxx`
-* `11110xxx 10xxxxxx 10xxxxxx 10xxxxxx`
-* `111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
-* `1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
-* `11111110 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
+* `110HHHHx 10xxxxxx`
+* `1110HHHH 10xxxxxx 10xxxxxx`
+* `11110HHH 10Hxxxxx 10xxxxxx 10xxxxxx`
+* `111110HH 10HHxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
+* `1111110H 10HHHxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
+* `11111110 10HHHHxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx`
The first four bytes determine the type:
diff --git a/test_creole.c b/test_creole.c
index 22a18b1..0c58780 100644
--- a/test_creole.c
+++ b/test_creole.c
@@ -81,11 +81,9 @@ TEST encode_byte_seq(struct seq *s) {
unsigned char buf[7];
for (;;) {
- /*
printf("0x%X ", i);
bprintb(s->minbuf, s->encode_to);
printf("\n");
- */
ASSERT_EQ(creole_encode(i, s->encode_to, s->high_bits,
buf), 1);
@@ -151,6 +149,7 @@ SUITE(pseudo_utf8_encode_all) {
for (s.high_bits = 0; s.high_bits < 16; s.high_bits++) {
memset(s.maxbuf, 0xBF, sizeof(s.maxbuf));
+ memset(s.minbuf, 0x80, sizeof(s.minbuf));
s.max = 0x7F;
s.encode_to = 2;
s.maxbuf[0] = s.minbuf[0] = 0xC0 | (s.high_bits << 1);
@@ -158,54 +157,43 @@ SUITE(pseudo_utf8_encode_all) {
s.minbuf[1] = 0x80;
RUN_TEST1(encode_byte_seq, &s);
+ memset(s.minbuf, 0x80, sizeof(s.minbuf));
s.max = 0xFFF;
s.encode_to = 3;
s.minbuf[0] = 0xE0 | s.high_bits;
s.maxbuf[0] = 0xE0 | s.high_bits;
s.minbuf[1] = 0x80;
- s.minbuf[2] = 0x80;
RUN_TEST1(encode_byte_seq, &s);
+ memset(s.minbuf, 0x80, sizeof(s.minbuf));
s.max = 0x1FFFF;
s.encode_to = 4;
s.maxbuf[0] = s.minbuf[0] = 0xF0 | (s.high_bits >> 1);
- s.minbuf[1] = 0x80 | (s.high_bits & 0x1 << 5);
- s.maxbuf[1] = 0x9F | (s.high_bits & 0x1 << 5);
- s.minbuf[2] = 0x80;
- s.minbuf[3] = 0x80;
+ s.minbuf[1] = 0x80 | ((s.high_bits & 0x1) << 5);
+ s.maxbuf[1] = 0x9F | ((s.high_bits & 0x1) << 5);
RUN_TEST1(encode_byte_seq, &s);
+ memset(s.minbuf, 0x80, sizeof(s.minbuf));
s.max = 0x3FFFFF;
s.encode_to = 5;
s.maxbuf[0] = s.minbuf[0] = 0xF8 | (s.high_bits >> 2);
- s.minbuf[1] = 0x80 | (s.high_bits & 0x3 << 4);
- s.maxbuf[1] = 0x8F | (s.high_bits & 0x3 << 4);
- s.minbuf[2] = 0x80;
- s.minbuf[3] = 0x80;
- s.minbuf[4] = 0x80;
- RUN_TEST1(encode_byte_seq, &s);
+ s.minbuf[1] = 0x80 | ((s.high_bits & 0x3) << 4);
+ s.maxbuf[1] = 0x8F | ((s.high_bits & 0x3) << 4);
+ memset(s.minbuf, 0x80, sizeof(s.minbuf));
s.max = 0x7FFFFFF;
s.encode_to = 6;
s.maxbuf[0] = s.minbuf[0] = 0xFC | (s.high_bits >> 3);
- s.minbuf[1] = 0x80 | (s.high_bits & 0x7 << 3);
- s.maxbuf[1] = 0x87 | (s.high_bits & 0x7 << 3);
- s.minbuf[2] = 0x80;
- s.minbuf[3] = 0x80;
- s.minbuf[4] = 0x80;
- s.minbuf[5] = 0x80;
+ s.minbuf[1] = 0x80 | ((s.high_bits & 0x7) << 3);
+ s.maxbuf[1] = 0x87 | ((s.high_bits & 0x7) << 3);
RUN_TEST1(encode_byte_seq, &s);
+ memset(s.minbuf, 0x80, sizeof(s.minbuf));
s.max = 0xFFFFFFFF;
s.encode_to = 7;
s.maxbuf[0] = s.minbuf[0] = 0xFE;
s.minbuf[1] = 0x80 | (s.high_bits << 2);
s.maxbuf[1] = 0x83 | (s.high_bits << 2);
- s.minbuf[2] = 0x80;
- s.minbuf[3] = 0x80;
- s.minbuf[4] = 0x80;
- s.minbuf[5] = 0x80;
- s.minbuf[6] = 0x80;
RUN_TEST1(encode_byte_seq, &s);
}
}