1 | import strconv |
2 | |
3 | fn test_format_int() { |
4 | assert strconv.format_int(0, 2) == '0' |
5 | assert strconv.format_int(0, 10) == '0' |
6 | assert strconv.format_int(0, 16) == '0' |
7 | assert strconv.format_int(0, 36) == '0' |
8 | assert strconv.format_int(1, 2) == '1' |
9 | assert strconv.format_int(1, 10) == '1' |
10 | assert strconv.format_int(1, 16) == '1' |
11 | assert strconv.format_int(1, 36) == '1' |
12 | assert strconv.format_int(-1, 2) == '-1' |
13 | assert strconv.format_int(-1, 10) == '-1' |
14 | assert strconv.format_int(-1, 16) == '-1' |
15 | assert strconv.format_int(-1, 36) == '-1' |
16 | assert strconv.format_int(255, 2) == '11111111' |
17 | assert strconv.format_int(255, 8) == '377' |
18 | assert strconv.format_int(255, 10) == '255' |
19 | assert strconv.format_int(255, 16) == 'ff' |
20 | assert strconv.format_int(-255, 2) == '-11111111' |
21 | assert strconv.format_int(-255, 8) == '-377' |
22 | assert strconv.format_int(-255, 10) == '-255' |
23 | assert strconv.format_int(-255, 16) == '-ff' |
24 | for i in -256 .. 256 { |
25 | assert strconv.format_int(i, 10) == i.str() |
26 | } |
27 | } |
28 | |
29 | fn test_format_uint() { |
30 | assert strconv.format_uint(0, 2) == '0' |
31 | assert strconv.format_int(255, 2) == '11111111' |
32 | assert strconv.format_int(255, 8) == '377' |
33 | assert strconv.format_int(255, 10) == '255' |
34 | assert strconv.format_int(255, 16) == 'ff' |
35 | assert strconv.format_uint(18446744073709551615, 2) == '1111111111111111111111111111111111111111111111111111111111111111' |
36 | assert strconv.format_uint(18446744073709551615, 16) == 'ffffffffffffffff' |
37 | assert strconv.format_uint(683058467, 36) == 'baobab' |
38 | } |