gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] 01/02: Add libtool version comparison


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] 01/02: Add libtool version comparison module and tests
Date: Sun, 04 Jun 2017 19:41:52 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-webex.

commit 55a1b25ea2312f2e0bd476513015b952ace914dd
Author: Florian Dold <address@hidden>
AuthorDate: Sun Jun 4 19:27:50 2017 +0200

    Add libtool version comparison module and tests
---
 src/libtoolVersion-test.ts | 30 +++++++++++++++++
 src/libtoolVersion.ts      | 83 ++++++++++++++++++++++++++++++++++++++++++++++
 src/wallet.ts              |  2 +-
 tsconfig.json              |  2 ++
 4 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/src/libtoolVersion-test.ts b/src/libtoolVersion-test.ts
new file mode 100644
index 00000000..5b8d5445
--- /dev/null
+++ b/src/libtoolVersion-test.ts
@@ -0,0 +1,30 @@
+/*
+ This file is part of TALER
+ (C) 2017 GNUnet e.V.
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+import * as LibtoolVersion from "./libtoolVersion";
+
+import {test} from "ava";
+
+test("version comparison", (t) => {
+  t.deepEqual(LibtoolVersion.compare("0:0:0", "0:0:0"), {compatible: true, 
currentCmp: 0});
+  t.deepEqual(LibtoolVersion.compare("0:0:0", ""), undefined);
+  t.deepEqual(LibtoolVersion.compare("foo", "0:0:0"), undefined);
+  t.deepEqual(LibtoolVersion.compare("0:0:0", "1:0:1"), {compatible: true, 
currentCmp: -1});
+  t.deepEqual(LibtoolVersion.compare("0:0:0", "1:5:1"), {compatible: true, 
currentCmp: -1});
+  t.deepEqual(LibtoolVersion.compare("0:0:0", "1:5:0"), {compatible: false, 
currentCmp: -1});
+  t.deepEqual(LibtoolVersion.compare("1:0:0", "0:5:0"), {compatible: false, 
currentCmp: 1});
+  t.deepEqual(LibtoolVersion.compare("1:0:1", "1:5:1"), {compatible: true, 
currentCmp: 0});
+});
diff --git a/src/libtoolVersion.ts b/src/libtoolVersion.ts
new file mode 100644
index 00000000..0525f5c0
--- /dev/null
+++ b/src/libtoolVersion.ts
@@ -0,0 +1,83 @@
+/*
+ This file is part of TALER
+ (C) 2017 GNUnet e.V.
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ * Semantic versioning, but libtool-style.
+ * See 
https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html 
+ */
+
+
+/**
+ * Result of comparing two libtool versions.
+ */
+export interface VersionMatchResult {
+  /**
+   * Is the first version compatible with the second?
+   */
+  compatible: boolean;
+  /**
+   * Is the first version older (-1), newser (+1) or
+   * identical (0)?
+   */
+  currentCmp: number
+}
+
+interface Version {
+  current: number;
+  revision: number;
+  age: number;
+}
+
+export function compare(me: string, other: string): 
VersionMatchResult|undefined {
+  const meVer = parseVersion(me);
+  const otherVer = parseVersion(other);
+
+  if (!(meVer && otherVer)) {
+    return undefined;
+  }
+
+  const compatible = (meVer.current <= otherVer.current &&
+                      meVer.current >= (otherVer.current - otherVer.age));
+
+  const currentCmp = Math.sign(meVer.current - otherVer.current);
+
+  return {compatible, currentCmp};
+}
+
+
+function parseVersion(v: string): Version|undefined {
+  const [currentStr, revisionStr, ageStr, ...rest] = v.split(":");
+  if (rest.length != 0) {
+    return undefined;
+  }
+  const current = Number.parseInt(currentStr);
+  const revision = Number.parseInt(revisionStr);
+  const age = Number.parseInt(ageStr);
+
+  if (Number.isNaN(current)) {
+    return undefined;
+  }
+
+  if (Number.isNaN(revision)) {
+    return undefined;
+  }
+
+  if (Number.isNaN(age)) {
+    return undefined;
+  }
+
+  return {current, revision, age};
+}
diff --git a/src/wallet.ts b/src/wallet.ts
index 1d72489c..80ba533c 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -321,7 +321,7 @@ export interface ConfigRecord {
 }
 
 
-const WALLET_PROTOCOL_VERSION = "0:0:0";
+export const WALLET_PROTOCOL_VERSION = "0:0:0";
 
 const builtinCurrencies: CurrencyRecord[] = [
   {
diff --git a/tsconfig.json b/tsconfig.json
index dee558cf..7bcf7d49 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -39,6 +39,8 @@
     "src/http.ts",
     "src/i18n.tsx",
     "src/i18n/strings.ts",
+    "src/libtoolVersion-test.ts",
+    "src/libtoolVersion.ts",
     "src/logging.ts",
     "src/memidb-test.ts",
     "src/memidb.ts",

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]