|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2017 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | +// Author Ewout Prangsma |
| 21 | +// |
| 22 | + |
| 23 | +package test |
| 24 | + |
| 25 | +import ( |
| 26 | + "testing" |
| 27 | + |
| 28 | + driver "github.com/arangodb/go-driver" |
| 29 | +) |
| 30 | + |
| 31 | +// TestVersion tests Version functions. |
| 32 | +func TestVersion(t *testing.T) { |
| 33 | + |
| 34 | + tests := []struct { |
| 35 | + Input driver.Version |
| 36 | + Major int |
| 37 | + Minor int |
| 38 | + Sub string |
| 39 | + SubInt int |
| 40 | + SubIsInt bool |
| 41 | + }{ |
| 42 | + {"1.2.3", 1, 2, "3", 3, true}, |
| 43 | + {"", 0, 0, "", 0, false}, |
| 44 | + {"1.2.3a", 1, 2, "3a", 0, false}, |
| 45 | + {"13.12", 13, 12, "", 0, false}, |
| 46 | + } |
| 47 | + |
| 48 | + for _, test := range tests { |
| 49 | + if v := test.Input.Major(); v != test.Major { |
| 50 | + t.Errorf("Major failed for '%s', expected %d, got %d", test.Input, test.Major, v) |
| 51 | + } |
| 52 | + if v := test.Input.Minor(); v != test.Minor { |
| 53 | + t.Errorf("Minor failed for '%s', expected %d, got %d", test.Input, test.Minor, v) |
| 54 | + } |
| 55 | + if v := test.Input.Sub(); v != test.Sub { |
| 56 | + t.Errorf("Sub failed for '%s', expected '%s', got '%s'", test.Input, test.Sub, v) |
| 57 | + } |
| 58 | + if v, vIsInt := test.Input.SubInt(); vIsInt != test.SubIsInt || v != test.SubInt { |
| 59 | + t.Errorf("SubInt failed for '%s', expected (%d,%v), got (%d,%v)", test.Input, test.SubInt, test.SubIsInt, v, vIsInt) |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +// TestVersionCompareTo tests Version.CompareTo. |
| 65 | +func TestVersionCompareTo(t *testing.T) { |
| 66 | + tests := []struct { |
| 67 | + A driver.Version |
| 68 | + B driver.Version |
| 69 | + Result int |
| 70 | + }{ |
| 71 | + {"1.2.3", "1.2.3", 0}, |
| 72 | + {"1.2", "1.2.3", -1}, |
| 73 | + {"1.2.3", "2.3.5", -1}, |
| 74 | + {"1.2", "1.1", 1}, |
| 75 | + {"1.2.3", "1.1.7", 1}, |
| 76 | + {"2.2", "1.2.a", 1}, |
| 77 | + {"1", "1.2.3", -1}, |
| 78 | + {"1.2.a", "1.2.3", 1}, |
| 79 | + {"1.2.3", "1.2.a", -1}, |
| 80 | + {"", "", 0}, |
| 81 | + {"1", "1", 0}, |
| 82 | + {"2.1", "2.1", 0}, |
| 83 | + } |
| 84 | + |
| 85 | + for _, test := range tests { |
| 86 | + if r := test.A.CompareTo(test.B); r != test.Result { |
| 87 | + t.Errorf("CompareTo('%s', '%s') failed, expected %d, got %d", test.A, test.B, test.Result, r) |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments