commit e637af05f9dd6211844b9021d2cc0f3d72d29274
parent 8922a0afe937f65625bc7b448aeb4d38dd879900
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 6 May 2021 10:21:11 -0400
uuid: merge separate +test.ha file
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
4 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -724,15 +724,8 @@ unix_tty() {
}
uuid() {
- if [ $testing -eq 0 ]
- then
- gen_srcs uuid \
- uuid.ha
- else
- gen_srcs uuid \
- uuid.ha \
- +test.ha
- fi
+ gen_srcs uuid \
+ uuid.ha
gen_ssa uuid crypto::random strio fmt endian io bytes bufio strings strconv
}
diff --git a/stdlib.mk b/stdlib.mk
@@ -1926,8 +1926,7 @@ $(TESTCACHE)/unix/tty/unix_tty.ssa: $(testlib_unix_tty_srcs) $(testlib_rt) $(tes
# uuid
testlib_uuid_srcs= \
- $(STDLIB)/uuid/uuid.ha \
- $(STDLIB)/uuid/+test.ha
+ $(STDLIB)/uuid/uuid.ha
$(TESTCACHE)/uuid/uuid.ssa: $(testlib_uuid_srcs) $(testlib_rt) $(testlib_crypto_random) $(testlib_strio) $(testlib_fmt) $(testlib_endian) $(testlib_io) $(testlib_bytes) $(testlib_bufio) $(testlib_strings) $(testlib_strconv)
@printf 'HAREC \t$@\n'
diff --git a/uuid/+test.ha b/uuid/+test.ha
@@ -1,20 +0,0 @@
-@test fn decode() void = {
- let in = "3ded910c-8080-4bc8-af39-b6cccee36741";
- let id = match (decodestr(in)) {
- invalid => abort(),
- u: uuid => u,
- };
- assert(compare(id, [
- 0x3d, 0xed, 0x91, 0x0c, 0x80, 0x80, 0x4b, 0xc8,
- 0xaf, 0x39, 0xb6, 0xcc, 0xce, 0xe3, 0x67, 0x41,
- ]));
- assert(decodestr("hello world") is invalid);
-};
-
-@test fn encode() void = {
- let in: uuid = [
- 0x3d, 0xed, 0x91, 0x0c, 0x80, 0x80, 0x4b, 0xc8,
- 0xaf, 0x39, 0xb6, 0xcc, 0xce, 0xe3, 0x67, 0x41,
- ];
- assert(encodestr(in) == "3ded910c-8080-4bc8-af39-b6cccee36741");
-};
diff --git a/uuid/uuid.ha b/uuid/uuid.ha
@@ -97,6 +97,14 @@ export fn encodeuri(in: uuid) str = {
return strio::string(sink);
};
+@test fn encode() void = {
+ let in: uuid = [
+ 0x3d, 0xed, 0x91, 0x0c, 0x80, 0x80, 0x4b, 0xc8,
+ 0xaf, 0x39, 0xb6, 0xcc, 0xce, 0xe3, 0x67, 0x41,
+ ];
+ assert(encodestr(in) == "3ded910c-8080-4bc8-af39-b6cccee36741");
+};
+
// Decodes a UUID as a string from an [[io::stream]].
export fn decode(in: *io::stream) (uuid | invalid | io::error) = {
let u: uuid = [0...];
@@ -139,3 +147,16 @@ export fn decodestr(in: str) (uuid | invalid) = {
u: uuid => u,
};
};
+
+@test fn decode() void = {
+ let in = "3ded910c-8080-4bc8-af39-b6cccee36741";
+ let id = match (decodestr(in)) {
+ invalid => abort(),
+ u: uuid => u,
+ };
+ assert(compare(id, [
+ 0x3d, 0xed, 0x91, 0x0c, 0x80, 0x80, 0x4b, 0xc8,
+ 0xaf, 0x39, 0xb6, 0xcc, 0xce, 0xe3, 0x67, 0x41,
+ ]));
+ assert(decodestr("hello world") is invalid);
+};