File tree 3 files changed +21
-4
lines changed
3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 8c51d4b002b2743fd50bc715429265aaaf482762
2
+ refs/heads/master: 7080ac15fb13c472985da692ca92c4a48b1f5575
Original file line number Diff line number Diff line change @@ -103,16 +103,18 @@ fn parse_buf(buf: [u8], radix: uint) -> int {
103
103
fail;
104
104
}
105
105
let i = vec:: len :: < u8 > ( buf) - 1 u;
106
+ let start = 0 u;
106
107
let power = 1 ;
108
+
107
109
if buf[ 0 ] == ( '-' as u8 ) {
108
110
power = -1 ;
109
- i - = 1 u;
111
+ start = 1 u;
110
112
}
111
113
let n = 0 ;
112
114
while true {
113
115
n += ( buf[ i] - ( '0' as u8 ) as int ) * power;
114
116
power *= radix as int ;
115
- if i == 0 u { ret n; }
117
+ if i <= start { ret n; }
116
118
i -= 1 u;
117
119
}
118
120
fail;
Original file line number Diff line number Diff line change @@ -3,6 +3,21 @@ use std;
3
3
import std:: int;
4
4
import std:: str:: eq;
5
5
6
+ #[ test]
7
+ fn test_from_str ( ) {
8
+ assert ( int:: from_str ( "0" ) == 0 ) ;
9
+ assert ( int:: from_str ( "3" ) == 3 ) ;
10
+ assert ( int:: from_str ( "10" ) == 10 ) ;
11
+ assert ( int:: from_str ( "123456789" ) == 123456789 ) ;
12
+ assert ( int:: from_str ( "00100" ) == 100 ) ;
13
+
14
+ assert ( int:: from_str ( "-1" ) == -1 ) ;
15
+ assert ( int:: from_str ( "-3" ) == -3 ) ;
16
+ assert ( int:: from_str ( "-10" ) == -10 ) ;
17
+ assert ( int:: from_str ( "-123456789" ) == -123456789 ) ;
18
+ assert ( int:: from_str ( "-00100" ) == -100 ) ;
19
+ }
20
+
6
21
#[ test]
7
22
fn test_to_str ( ) {
8
23
assert ( eq ( int:: to_str ( 0 , 10 u) , "0" ) ) ;
@@ -29,4 +44,4 @@ fn test_overflows() {
29
44
assert ( int:: max_value ( ) > 0 ) ;
30
45
assert ( int:: min_value ( ) <= 0 ) ;
31
46
assert ( int:: min_value ( ) + int:: max_value ( ) + 1 == 0 ) ;
32
- }
47
+ }
You can’t perform that action at this time.
0 commit comments