|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2017 "Neo Technology,"," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import {ServerVersion, VERSION_3_2_0} from '../../src/v1/internal/server-version'; |
| 21 | + |
| 22 | +describe('ServerVersion', () => { |
| 23 | + |
| 24 | + it('should construct with correct values', () => { |
| 25 | + verifyVersion(new ServerVersion(2, 3, 10), 2, 3, 10); |
| 26 | + verifyVersion(new ServerVersion(3, 2, 0), 3, 2, 0); |
| 27 | + verifyVersion(new ServerVersion(1, 9, 12), 1, 9, 12); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should define correct 3.2.0 constant', () => { |
| 31 | + verifyVersion(VERSION_3_2_0, 3, 2, 0); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should parse "undefined" strings to 3.0.0 for backwards compatibility reasons', () => { |
| 35 | + verifyVersion(parse(null), 3, 0, 0); |
| 36 | + verifyVersion(parse(undefined), 3, 0, 0); |
| 37 | + verifyVersion(parse(''), 3, 0, 0); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should fail to parse object, array and function', () => { |
| 41 | + expect(() => parse({})).toThrowError(TypeError); |
| 42 | + expect(() => parse([])).toThrowError(TypeError); |
| 43 | + expect(() => parse(() => { |
| 44 | + })).toThrowError(TypeError); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should fail to parse illegal strings', () => { |
| 48 | + expect(() => parse('Cat')).toThrow(); |
| 49 | + expect(() => parse('Dog')).toThrow(); |
| 50 | + expect(() => parse('Neo4j')).toThrow(); |
| 51 | + expect(() => parse('Neo4j/')).toThrow(); |
| 52 | + expect(() => parse('Not-Neo4j/3.1.0')).toThrow(); |
| 53 | + expect(() => parse('Neo4j/5')).toThrow(); |
| 54 | + expect(() => parse('Neo4j/3.')).toThrow(); |
| 55 | + expect(() => parse('Neo4j/1.A')).toThrow(); |
| 56 | + expect(() => parse('Neo4j/1.Hello')).toThrow(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should parse valid version strings', () => { |
| 60 | + verifyVersion(parse('Neo4j/3.2.1'), 3, 2, 1); |
| 61 | + verifyVersion(parse('Neo4j/1.9.10'), 1, 9, 10); |
| 62 | + verifyVersion(parse('Neo4j/7.77.777'), 7, 77, 777); |
| 63 | + |
| 64 | + verifyVersion(parse('Neo4j/3.10.0-GA'), 3, 10, 0); |
| 65 | + verifyVersion(parse('Neo4j/2.5.5-RC01'), 2, 5, 5); |
| 66 | + verifyVersion(parse('Neo4j/3.1.1-SNAPSHOT'), 3, 1, 1); |
| 67 | + verifyVersion(parse('Neo4j/2.0.0-M09'), 2, 0, 0); |
| 68 | + |
| 69 | + verifyVersion(parse('Neo4j/3.2'), 3, 2, 0); |
| 70 | + verifyVersion(parse('Neo4j/1.5'), 1, 5, 0); |
| 71 | + verifyVersion(parse('Neo4j/42.42'), 42, 42, 0); |
| 72 | + |
| 73 | + verifyVersion(parse('Neo4j/2.2-GA'), 2, 2, 0); |
| 74 | + verifyVersion(parse('Neo4j/3.0-RC01'), 3, 0, 0); |
| 75 | + verifyVersion(parse('Neo4j/2.3-SNAPSHOT'), 2, 3, 0); |
| 76 | + verifyVersion(parse('Neo4j/2.2-M09'), 2, 2, 0); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should compare equal versions', () => { |
| 80 | + expect(new ServerVersion(3, 1, 0).compareTo(new ServerVersion(3, 1, 0))).toEqual(0); |
| 81 | + expect(new ServerVersion(1, 9, 12).compareTo(new ServerVersion(1, 9, 12))).toEqual(0); |
| 82 | + expect(new ServerVersion(2, 3, 8).compareTo(new ServerVersion(2, 3, 8))).toEqual(0); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should compare correctly by major', () => { |
| 86 | + expect(new ServerVersion(3, 1, 0).compareTo(new ServerVersion(2, 1, 0))).toBeGreaterThan(0); |
| 87 | + expect(new ServerVersion(2, 1, 0).compareTo(new ServerVersion(3, 1, 0))).toBeLessThan(0); |
| 88 | + |
| 89 | + expect(new ServerVersion(3, 1, 4).compareTo(new ServerVersion(1, 9, 10))).toBeGreaterThan(0); |
| 90 | + expect(new ServerVersion(1, 5, 42).compareTo(new ServerVersion(10, 10, 43))).toBeLessThan(0); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should compare correctly by minor', () => { |
| 94 | + expect(new ServerVersion(3, 3, 0).compareTo(new ServerVersion(3, 1, 0))).toBeGreaterThan(0); |
| 95 | + expect(new ServerVersion(1, 3, 5).compareTo(new ServerVersion(1, 9, 5))).toBeLessThan(0); |
| 96 | + |
| 97 | + expect(new ServerVersion(3, 9, 5).compareTo(new ServerVersion(3, 1, 2))).toBeGreaterThan(0); |
| 98 | + expect(new ServerVersion(1, 5, 42).compareTo(new ServerVersion(1, 10, 11))).toBeLessThan(0); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should compare correctly by patch', () => { |
| 102 | + expect(new ServerVersion(3, 3, 6).compareTo(new ServerVersion(3, 3, 5))).toBeGreaterThan(0); |
| 103 | + expect(new ServerVersion(1, 8, 2).compareTo(new ServerVersion(1, 8, 8))).toBeLessThan(0); |
| 104 | + expect(new ServerVersion(9, 9, 9).compareTo(new ServerVersion(9, 9, 0))).toBeGreaterThan(0); |
| 105 | + expect(new ServerVersion(3, 3, 3).compareTo(new ServerVersion(3, 3, 42))).toBeLessThan(0); |
| 106 | + }); |
| 107 | + |
| 108 | +}); |
| 109 | + |
| 110 | +function verifyVersion(serverVersion, expectedMajor, expectedMinor, expectedPatch) { |
| 111 | + expect(serverVersion.major).toEqual(expectedMajor); |
| 112 | + expect(serverVersion.minor).toEqual(expectedMinor); |
| 113 | + expect(serverVersion.patch).toEqual(expectedPatch); |
| 114 | +} |
| 115 | + |
| 116 | +function parse(string) { |
| 117 | + return ServerVersion.fromString(string); |
| 118 | +} |
0 commit comments