File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1108,6 +1108,22 @@ def current_command_version
1108
1108
version_parts . fill ( 0 , version_parts . length ...3 )
1109
1109
end
1110
1110
1111
+ # Returns current_command_version <=> other_version
1112
+ #
1113
+ # @example
1114
+ # lib.current_command_version #=> [2, 42, 0]
1115
+ #
1116
+ # lib.compare_version_to(2, 41, 0) #=> 1
1117
+ # lib.compare_version_to(2, 42, 0) #=> 0
1118
+ # lib.compare_version_to(2, 43, 0) #=> -1
1119
+ #
1120
+ # @param other_version [Array<Object>] the other version to compare to
1121
+ # @return [Integer] -1 if this version is less than other_version, 0 if equal, or 1 if greater than
1122
+ #
1123
+ def compare_version_to ( *other_version )
1124
+ current_command_version <=> other_version
1125
+ end
1126
+
1111
1127
def required_command_version
1112
1128
[ 1 , 6 ]
1113
1129
end
Original file line number Diff line number Diff line change @@ -325,4 +325,15 @@ def test_show
325
325
assert ( @lib . show ( 'gitsearch1' , 'scott/text.txt' ) == "hello\n this is\n a file\n that is\n put here\n to search one\n to search two\n nothing!\n " )
326
326
end
327
327
328
+ def test_compare_version_to
329
+ lib = Git ::Lib . new ( nil , nil )
330
+ current_version = [ 2 , 42 , 0 ]
331
+ lib . define_singleton_method ( :current_command_version ) { current_version }
332
+ assert lib . compare_version_to ( 0 , 43 , 9 ) == 1
333
+ assert lib . compare_version_to ( 2 , 41 , 0 ) == 1
334
+ assert lib . compare_version_to ( 2 , 42 , 0 ) == 0
335
+ assert lib . compare_version_to ( 2 , 42 , 1 ) == -1
336
+ assert lib . compare_version_to ( 2 , 43 , 0 ) == -1
337
+ assert lib . compare_version_to ( 3 , 0 , 0 ) == -1
338
+ end
328
339
end
You can’t perform that action at this time.
0 commit comments