core: Don't allow radix 1 in uint::to_str

This commit is contained in:
Brian Anderson 2012-06-04 15:22:40 -07:00
parent 6e0085210c
commit 2d0e7cd272

View File

@ -95,9 +95,15 @@ fn from_str_radix(buf: str, radix: u64) -> option<u64> {
};
}
#[doc = "Convert to a string in a given base"]
#[doc = "
Convert to a string in a given base
# Failure
Fails if `radix` < 2 or `radix` > 16
"]
fn to_str(num: T, radix: uint) -> str {
assert (0u < radix && radix <= 16u);
assert (1u < radix && radix <= 16u);
let mut n = num;
let radix = radix as T;
fn digit(n: T) -> u8 {
@ -167,3 +173,17 @@ fn test_parse_buf() {
assert parse_buf(str::bytes("Z"), 10u) == none;
assert parse_buf(str::bytes("_"), 2u) == none;
}
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
fn to_str_radix1() {
uint::to_str(100u, 1u);
}
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
fn to_str_radix17() {
uint::to_str(100u, 17u);
}