Skip to content

Support in-dev Neo4j version #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/v1/internal/server-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import {assertString} from './util';

const SERVER_VERSION_REGEX = new RegExp('^(Neo4j/)?(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?$');
const NEO4J_IN_DEV_VERSION_STRING = 'Neo4j/dev';

class ServerVersion {

Expand Down Expand Up @@ -48,6 +49,10 @@ class ServerVersion {

assertString(versionStr, 'Neo4j version string');

if (versionStr.toLowerCase() === NEO4J_IN_DEV_VERSION_STRING.toLowerCase()) {
return VERSION_IN_DEV;
}

const version = versionStr.match(SERVER_VERSION_REGEX);
if (!version) {
throw new Error(`Unparsable Neo4j version: ${versionStr}`);
Expand Down Expand Up @@ -80,7 +85,7 @@ class ServerVersion {
}

function parseIntStrict(str, name) {
const value = parseInt(str);
const value = parseInt(str, 10);
if (!value && value !== 0) {
throw new Error(`Unparsable number ${name}: '${str}'`);
}
Expand All @@ -93,11 +98,13 @@ function compareInts(x, y) {

const VERSION_3_1_0 = new ServerVersion(3, 1, 0);
const VERSION_3_2_0 = new ServerVersion(3, 2, 0);
const VERSION_IN_DEV = new ServerVersion(0, 0, 0);

export {
ServerVersion,
VERSION_3_1_0,
VERSION_3_2_0
VERSION_3_2_0,
VERSION_IN_DEV
};


Expand Down
12 changes: 11 additions & 1 deletion test/internal/server-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

import {ServerVersion, VERSION_3_2_0} from '../../src/v1/internal/server-version';
import {ServerVersion, VERSION_3_2_0, VERSION_IN_DEV} from '../../src/v1/internal/server-version';

describe('ServerVersion', () => {

Expand Down Expand Up @@ -74,6 +74,10 @@ describe('ServerVersion', () => {
verifyVersion(parse('Neo4j/3.0-RC01'), 3, 0, 0);
verifyVersion(parse('Neo4j/2.3-SNAPSHOT'), 2, 3, 0);
verifyVersion(parse('Neo4j/2.2-M09'), 2, 2, 0);

verifyVersion(parse('Neo4j/dev'), 0, 0, 0);
verifyVersion(parse('Neo4j/DEV'), 0, 0, 0);
verifyVersion(parse('Neo4j/Dev'), 0, 0, 0);
});

it('should compare equal versions', () => {
Expand Down Expand Up @@ -105,6 +109,12 @@ describe('ServerVersion', () => {
expect(new ServerVersion(3, 3, 3).compareTo(new ServerVersion(3, 3, 42))).toBeLessThan(0);
});

it('should compare dev version', () => {
expect(new ServerVersion(3, 1, 0).compareTo(VERSION_IN_DEV)).toBeGreaterThan(0);
expect(new ServerVersion(3, 3, 6).compareTo(VERSION_IN_DEV)).toBeGreaterThan(0);
expect(new ServerVersion(2, 3, 0).compareTo(VERSION_IN_DEV)).toBeGreaterThan(0);
});

});

function verifyVersion(serverVersion, expectedMajor, expectedMinor, expectedPatch) {
Expand Down