[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED] std: add to_string method to Pk_Version, and a pretty-printe
From: |
Jose E. Marchesi |
Subject: |
[COMMITTED] std: add to_string method to Pk_Version, and a pretty-printer |
Date: |
Tue, 31 Jan 2023 15:33:40 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
2023-01-31 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/std.pk (Pk_Version): Add control fields.
(Pk_Version.to_string): New method.
(Pk_Version._print): Likewise.
* doc/poke.texi (Version Tools): Reflect new contents of
Pk_Version.
* testsuite/poke.std/std-test.pk: Add tests for
Pk_Version.to_string.
---
ChangeLog | 10 ++++++++++
doc/poke.texi | 10 +++++++++-
libpoke/std.pk | 27 +++++++++++++++++++++++++--
testsuite/poke.std/std-test.pk | 9 +++++++++
4 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 354135da..ef5675b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-01-31 Jose E. Marchesi <jemarch@gnu.org>
+
+ * libpoke/std.pk (Pk_Version): Add control fields.
+ (Pk_Version.to_string): New method.
+ (Pk_Version._print): Likewise.
+ * doc/poke.texi (Version Tools): Reflect new contents of
+ Pk_Version.
+ * testsuite/poke.std/std-test.pk: Add tests for
+ Pk_Version.to_string.
+
2023-01-30 Arsen Arsenović <arsen@aarsen.me>
poke.texi: Remedy syntax-check fails
diff --git a/doc/poke.texi b/doc/poke.texi
index 426c6a8a..b373eb97 100644
--- a/doc/poke.texi
+++ b/doc/poke.texi
@@ -16269,10 +16269,18 @@ type Pk_Version =
string branch;
uint<32> offset;
string commit;
- uint<8> dirty;
+
+ uint<8> has_branch_p;
+ uint<8> has_subminor_p;
+ uint<8> has_commit_p;
+ uint<8> dirty_p;
@};
@end example
+@deftypefun string Pk_Version.to_string ()
+Method that returns the printed representation of a version.
+@end deftypefun
+
@deftypefun Pk_Version pk_version_parse (string @var{version})
Parses the string @var{version} into a new instance of
@code{Pk_Version}, or raises @code{E_inval} if the string is invalid.
diff --git a/libpoke/std.pk b/libpoke/std.pk
index 956dede5..49de3950 100644
--- a/libpoke/std.pk
+++ b/libpoke/std.pk
@@ -662,7 +662,27 @@ type Pk_Version =
string branch;
uint<32> offset;
string commit;
- uint<8> dirty;
+
+ uint<8> has_branch_p;
+ uint<8> has_subminor_p;
+ uint<8> has_commit_p;
+ uint<8> dirty_p;
+
+ method to_string = string:
+ {
+ return format ("%u8d.%u8d%s%s%s%s%s",
+ major, minor,
+ has_subminor_p ? format (".%u8d", subminor) : "",
+ has_branch_p ? "-" + branch : "",
+ has_branch_p ? format ("-%u32d", offset) : "",
+ has_commit_p ? "-g" + commit : "",
+ dirty_p ? "-dirty" : "");
+ }
+
+ method _print = void:
+ {
+ printf "#<%s>", to_string;
+ }
};
/* Parse the string A into a new Pk_Version object. */
@@ -679,7 +699,7 @@ fun pk_version_parse = (string a) Pk_Version:
if (a[i:] == dirty)
{
a = a[:i];
- res.dirty = 1;
+ res.dirty_p = 1;
};
}
@@ -699,6 +719,7 @@ fun pk_version_parse = (string a) Pk_Version:
has_hash = 0;
break;
};
+ res.has_commit_p = 1;
res.commit = a[dashi + 2:];
if (has_hash)
a = a[:dashi];
@@ -747,6 +768,7 @@ fun pk_version_parse = (string a) Pk_Version:
if (i.peek () == '.')
{
i.i++;
+ res.has_subminor_p =1;
res.subminor = i.pop_number();
};
@@ -756,6 +778,7 @@ fun pk_version_parse = (string a) Pk_Version:
try
{
popassert ('-');
+ res.has_branch_p = 1;
res.branch = i.poprdelim ("-");
/* The above should've popped the dash too. */
res.offset = i.pop_number ();
diff --git a/testsuite/poke.std/std-test.pk b/testsuite/poke.std/std-test.pk
index 5eeab351..1a189fc9 100644
--- a/testsuite/poke.std/std-test.pk
+++ b/testsuite/poke.std/std-test.pk
@@ -483,6 +483,15 @@ var tests = [
assert (1, "expects exception");
}
}
+
+ /* Test the to_string method. */
+ for (s in ["3.0", "3.21", "3.21.0",
+ "3.0-g12345", "3.0-g12345-dirty",
+ "3.0-dev-12", "3.0-nondev-12",
+ "3.0-dev-22-g2e092-dirty",
+ "3.0-arsen_do-gettext-stuff-13",
+ "3.0-a_-b_c-12"])
+ assert (pk_version_parse (s).to_string == s);
},
},
];
--
2.30.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [COMMITTED] std: add to_string method to Pk_Version, and a pretty-printer,
Jose E. Marchesi <=