Skip to content

Commit 351a564

Browse files
committed
libnum: Remove all uses of ~str from libnum
1 parent 1ef8246 commit 351a564

File tree

3 files changed

+85
-81
lines changed

3 files changed

+85
-81
lines changed

src/libnum/bigint.rs

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,60 +1865,60 @@ mod biguint_tests {
18651865
assert!(((one << 64) + one).is_odd());
18661866
}
18671867

1868-
fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, ~str)>)> {
1868+
fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, StrBuf)>)> {
18691869
let bits = BigDigit::bits;
18701870
vec!(( Zero::zero(), vec!(
1871-
(2, "0".to_owned()), (3, "0".to_owned())
1871+
(2, "0".to_strbuf()), (3, "0".to_strbuf())
18721872
)), ( BigUint::from_slice([ 0xff ]), vec!(
1873-
(2, "11111111".to_owned()),
1874-
(3, "100110".to_owned()),
1875-
(4, "3333".to_owned()),
1876-
(5, "2010".to_owned()),
1877-
(6, "1103".to_owned()),
1878-
(7, "513".to_owned()),
1879-
(8, "377".to_owned()),
1880-
(9, "313".to_owned()),
1881-
(10, "255".to_owned()),
1882-
(11, "212".to_owned()),
1883-
(12, "193".to_owned()),
1884-
(13, "168".to_owned()),
1885-
(14, "143".to_owned()),
1886-
(15, "120".to_owned()),
1887-
(16, "ff".to_owned())
1873+
(2, "11111111".to_strbuf()),
1874+
(3, "100110".to_strbuf()),
1875+
(4, "3333".to_strbuf()),
1876+
(5, "2010".to_strbuf()),
1877+
(6, "1103".to_strbuf()),
1878+
(7, "513".to_strbuf()),
1879+
(8, "377".to_strbuf()),
1880+
(9, "313".to_strbuf()),
1881+
(10, "255".to_strbuf()),
1882+
(11, "212".to_strbuf()),
1883+
(12, "193".to_strbuf()),
1884+
(13, "168".to_strbuf()),
1885+
(14, "143".to_strbuf()),
1886+
(15, "120".to_strbuf()),
1887+
(16, "ff".to_strbuf())
18881888
)), ( BigUint::from_slice([ 0xfff ]), vec!(
1889-
(2, "111111111111".to_owned()),
1890-
(4, "333333".to_owned()),
1891-
(16, "fff".to_owned())
1889+
(2, "111111111111".to_strbuf()),
1890+
(4, "333333".to_strbuf()),
1891+
(16, "fff".to_strbuf())
18921892
)), ( BigUint::from_slice([ 1, 2 ]), vec!(
18931893
(2,
1894-
"10".to_owned() +
1895-
"0".repeat(bits - 1) + "1"),
1894+
format_strbuf!("10{}1", "0".repeat(bits - 1))),
18961895
(4,
1897-
"2".to_owned() +
1898-
"0".repeat(bits / 2 - 1) + "1"),
1896+
format_strbuf!("2{}1", "0".repeat(bits / 2 - 1))),
18991897
(10, match bits {
1900-
32 => "8589934593".to_owned(), 16 => "131073".to_owned(), _ => fail!()
1898+
32 => "8589934593".to_strbuf(),
1899+
16 => "131073".to_strbuf(),
1900+
_ => fail!()
19011901
}),
19021902
(16,
1903-
"2".to_owned() +
1904-
"0".repeat(bits / 4 - 1) + "1")
1903+
format_strbuf!("2{}1", "0".repeat(bits / 4 - 1)))
19051904
)), ( BigUint::from_slice([ 1, 2, 3 ]), vec!(
19061905
(2,
1907-
"11".to_owned() +
1908-
"0".repeat(bits - 2) + "10" +
1909-
"0".repeat(bits - 1) + "1"),
1906+
format_strbuf!("11{}10{}1",
1907+
"0".repeat(bits - 2),
1908+
"0".repeat(bits - 1))),
19101909
(4,
1911-
"3".to_owned() +
1912-
"0".repeat(bits / 2 - 1) + "2" +
1913-
"0".repeat(bits / 2 - 1) + "1"),
1910+
format_strbuf!("3{}2{}1",
1911+
"0".repeat(bits / 2 - 1),
1912+
"0".repeat(bits / 2 - 1))),
19141913
(10, match bits {
1915-
32 => "55340232229718589441".to_owned(),
1916-
16 => "12885032961".to_owned(),
1914+
32 => "55340232229718589441".to_strbuf(),
1915+
16 => "12885032961".to_strbuf(),
19171916
_ => fail!()
19181917
}),
1919-
(16, "3".to_owned() +
1920-
"0".repeat(bits / 4 - 1) + "2" +
1921-
"0".repeat(bits / 4 - 1) + "1")
1918+
(16,
1919+
format_strbuf!("3{}2{}1",
1920+
"0".repeat(bits / 4 - 1),
1921+
"0".repeat(bits / 4 - 1)))
19221922
)) )
19231923
}
19241924

@@ -1929,7 +1929,8 @@ mod biguint_tests {
19291929
let &(ref n, ref rs) = num_pair;
19301930
for str_pair in rs.iter() {
19311931
let &(ref radix, ref str) = str_pair;
1932-
assert_eq!(&n.to_str_radix(*radix), str);
1932+
assert_eq!(n.to_str_radix(*radix).as_slice(),
1933+
str.as_slice());
19331934
}
19341935
}
19351936
}
@@ -1941,7 +1942,9 @@ mod biguint_tests {
19411942
let &(ref n, ref rs) = num_pair;
19421943
for str_pair in rs.iter() {
19431944
let &(ref radix, ref str) = str_pair;
1944-
assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).unwrap());
1945+
assert_eq!(n,
1946+
&FromStrRadix::from_str_radix(str.as_slice(),
1947+
*radix).unwrap());
19451948
}
19461949
}
19471950

src/libnum/complex.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ mod test {
348348

349349
#[test]
350350
fn test_to_str() {
351-
fn test(c : Complex64, s: ~str) {
352-
assert_eq!(c.to_str(), s);
351+
fn test(c : Complex64, s: StrBuf) {
352+
assert_eq!(c.to_str().to_strbuf(), s);
353353
}
354-
test(_0_0i, "0+0i".to_owned());
355-
test(_1_0i, "1+0i".to_owned());
356-
test(_0_1i, "0+1i".to_owned());
357-
test(_1_1i, "1+1i".to_owned());
358-
test(_neg1_1i, "-1+1i".to_owned());
359-
test(-_neg1_1i, "1-1i".to_owned());
360-
test(_05_05i, "0.5+0.5i".to_owned());
354+
test(_0_0i, "0+0i".to_strbuf());
355+
test(_1_0i, "1+0i".to_strbuf());
356+
test(_0_1i, "0+1i".to_strbuf());
357+
test(_1_1i, "1+1i".to_strbuf());
358+
test(_neg1_1i, "-1+1i".to_strbuf());
359+
test(-_neg1_1i, "1-1i".to_strbuf());
360+
test(_05_05i, "0.5+0.5i".to_strbuf());
361361
}
362362
}

src/libnum/rational.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,16 @@ mod test {
555555

556556
#[test]
557557
fn test_to_from_str() {
558-
fn test(r: Rational, s: ~str) {
559-
assert_eq!(FromStr::from_str(s), Some(r));
560-
assert_eq!(r.to_str(), s);
558+
fn test(r: Rational, s: StrBuf) {
559+
assert_eq!(FromStr::from_str(s.as_slice()), Some(r));
560+
assert_eq!(r.to_str().to_strbuf(), s);
561561
}
562-
test(_1, "1/1".to_owned());
563-
test(_0, "0/1".to_owned());
564-
test(_1_2, "1/2".to_owned());
565-
test(_3_2, "3/2".to_owned());
566-
test(_2, "2/1".to_owned());
567-
test(_neg1_2, "-1/2".to_owned());
562+
test(_1, "1/1".to_strbuf());
563+
test(_0, "0/1".to_strbuf());
564+
test(_1_2, "1/2".to_strbuf());
565+
test(_3_2, "3/2".to_strbuf());
566+
test(_2, "2/1".to_strbuf());
567+
test(_neg1_2, "-1/2".to_strbuf());
568568
}
569569
#[test]
570570
fn test_from_str_fail() {
@@ -581,30 +581,31 @@ mod test {
581581

582582
#[test]
583583
fn test_to_from_str_radix() {
584-
fn test(r: Rational, s: ~str, n: uint) {
585-
assert_eq!(FromStrRadix::from_str_radix(s, n), Some(r));
586-
assert_eq!(r.to_str_radix(n), s);
584+
fn test(r: Rational, s: StrBuf, n: uint) {
585+
assert_eq!(FromStrRadix::from_str_radix(s.to_owned(), n),
586+
Some(r));
587+
assert_eq!(r.to_str_radix(n).to_strbuf(), s);
587588
}
588-
fn test3(r: Rational, s: ~str) { test(r, s, 3) }
589-
fn test16(r: Rational, s: ~str) { test(r, s, 16) }
590-
591-
test3(_1, "1/1".to_owned());
592-
test3(_0, "0/1".to_owned());
593-
test3(_1_2, "1/2".to_owned());
594-
test3(_3_2, "10/2".to_owned());
595-
test3(_2, "2/1".to_owned());
596-
test3(_neg1_2, "-1/2".to_owned());
597-
test3(_neg1_2 / _2, "-1/11".to_owned());
598-
599-
test16(_1, "1/1".to_owned());
600-
test16(_0, "0/1".to_owned());
601-
test16(_1_2, "1/2".to_owned());
602-
test16(_3_2, "3/2".to_owned());
603-
test16(_2, "2/1".to_owned());
604-
test16(_neg1_2, "-1/2".to_owned());
605-
test16(_neg1_2 / _2, "-1/4".to_owned());
606-
test16(Ratio::new(13,15), "d/f".to_owned());
607-
test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_owned());
589+
fn test3(r: Rational, s: StrBuf) { test(r, s, 3) }
590+
fn test16(r: Rational, s: StrBuf) { test(r, s, 16) }
591+
592+
test3(_1, "1/1".to_strbuf());
593+
test3(_0, "0/1".to_strbuf());
594+
test3(_1_2, "1/2".to_strbuf());
595+
test3(_3_2, "10/2".to_strbuf());
596+
test3(_2, "2/1".to_strbuf());
597+
test3(_neg1_2, "-1/2".to_strbuf());
598+
test3(_neg1_2 / _2, "-1/11".to_strbuf());
599+
600+
test16(_1, "1/1".to_strbuf());
601+
test16(_0, "0/1".to_strbuf());
602+
test16(_1_2, "1/2".to_strbuf());
603+
test16(_3_2, "3/2".to_strbuf());
604+
test16(_2, "2/1".to_strbuf());
605+
test16(_neg1_2, "-1/2".to_strbuf());
606+
test16(_neg1_2 / _2, "-1/4".to_strbuf());
607+
test16(Ratio::new(13,15), "d/f".to_strbuf());
608+
test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_strbuf());
608609
}
609610

610611
#[test]

0 commit comments

Comments
 (0)