@@ -1183,7 +1183,7 @@ pub fn test_prefix_ext() {
1183
1183
#[ test]
1184
1184
pub fn test_push ( ) {
1185
1185
macro_rules! tp (
1186
- ( $path: expr, $push: expr, $expected: expr) => ( {
1186
+ ( $path: expr, $push: expr, $expected: expr) => ( {
1187
1187
let mut actual = PathBuf :: from( $path) ;
1188
1188
actual. push( $push) ;
1189
1189
assert!( actual. to_str( ) == Some ( $expected) ,
@@ -1281,7 +1281,7 @@ pub fn test_push() {
1281
1281
#[ test]
1282
1282
pub fn test_pop ( ) {
1283
1283
macro_rules! tp (
1284
- ( $path: expr, $expected: expr, $output: expr) => ( {
1284
+ ( $path: expr, $expected: expr, $output: expr) => ( {
1285
1285
let mut actual = PathBuf :: from( $path) ;
1286
1286
let output = actual. pop( ) ;
1287
1287
assert!( actual. to_str( ) == Some ( $expected) && output == $output,
@@ -1335,7 +1335,7 @@ pub fn test_pop() {
1335
1335
#[ test]
1336
1336
pub fn test_set_file_name ( ) {
1337
1337
macro_rules! tfn (
1338
- ( $path: expr, $file: expr, $expected: expr) => ( {
1338
+ ( $path: expr, $file: expr, $expected: expr) => ( {
1339
1339
let mut p = PathBuf :: from( $path) ;
1340
1340
p. set_file_name( $file) ;
1341
1341
assert!( p. to_str( ) == Some ( $expected) ,
@@ -1369,7 +1369,7 @@ pub fn test_set_file_name() {
1369
1369
#[ test]
1370
1370
pub fn test_set_extension ( ) {
1371
1371
macro_rules! tfe (
1372
- ( $path: expr, $ext: expr, $expected: expr, $output: expr) => ( {
1372
+ ( $path: expr, $ext: expr, $expected: expr, $output: expr) => ( {
1373
1373
let mut p = PathBuf :: from( $path) ;
1374
1374
let output = p. set_extension( $ext) ;
1375
1375
assert!( p. to_str( ) == Some ( $expected) && output == $output,
@@ -1394,6 +1394,46 @@ pub fn test_set_extension() {
1394
1394
tfe ! ( "/" , "foo" , "/" , false ) ;
1395
1395
}
1396
1396
1397
+ #[ test]
1398
+ pub fn test_with_extension ( ) {
1399
+ macro_rules! twe (
1400
+ ( $input: expr, $extension: expr, $expected: expr) => ( {
1401
+ let input = Path :: new( $input) ;
1402
+ let output = input. with_extension( $extension) ;
1403
+
1404
+ assert!(
1405
+ output. to_str( ) == Some ( $expected) ,
1406
+ "calling Path::new({:?}).with_extension({:?}): Expected {:?}, got {:?}" ,
1407
+ $input, $extension, $expected, output,
1408
+ ) ;
1409
+ } ) ;
1410
+ ) ;
1411
+
1412
+ twe ! ( "foo" , "txt" , "foo.txt" ) ;
1413
+ twe ! ( "foo.bar" , "txt" , "foo.txt" ) ;
1414
+ twe ! ( "foo.bar.baz" , "txt" , "foo.bar.txt" ) ;
1415
+ twe ! ( ".test" , "txt" , ".test.txt" ) ;
1416
+ twe ! ( "foo.txt" , "" , "foo" ) ;
1417
+ twe ! ( "foo" , "" , "foo" ) ;
1418
+ twe ! ( "" , "foo" , "" ) ;
1419
+ twe ! ( "." , "foo" , "." ) ;
1420
+ twe ! ( "foo/" , "bar" , "foo.bar" ) ;
1421
+ twe ! ( "foo/." , "bar" , "foo.bar" ) ;
1422
+ twe ! ( ".." , "foo" , ".." ) ;
1423
+ twe ! ( "foo/.." , "bar" , "foo/.." ) ;
1424
+ twe ! ( "/" , "foo" , "/" ) ;
1425
+
1426
+ // New extension is smaller than file name
1427
+ twe ! ( "aaa_aaa_aaa" , "bbb_bbb" , "aaa_aaa_aaa.bbb_bbb" ) ;
1428
+ // New extension is greater than file name
1429
+ twe ! ( "bbb_bbb" , "aaa_aaa_aaa" , "bbb_bbb.aaa_aaa_aaa" ) ;
1430
+
1431
+ // New extension is smaller than previous extension
1432
+ twe ! ( "ccc.aaa_aaa_aaa" , "bbb_bbb" , "ccc.bbb_bbb" ) ;
1433
+ // New extension is greater than previous extension
1434
+ twe ! ( "ccc.bbb_bbb" , "aaa_aaa_aaa" , "ccc.aaa_aaa_aaa" ) ;
1435
+ }
1436
+
1397
1437
#[ test]
1398
1438
fn test_eq_receivers ( ) {
1399
1439
use crate :: borrow:: Cow ;
@@ -1669,7 +1709,7 @@ fn into_rc() {
1669
1709
#[ test]
1670
1710
fn test_ord ( ) {
1671
1711
macro_rules! ord(
1672
- ( $ord: ident, $left: expr, $right: expr) => ( {
1712
+ ( $ord: ident, $left: expr, $right: expr) => ( {
1673
1713
use core:: cmp:: Ordering ;
1674
1714
1675
1715
let left = Path :: new( $left) ;
0 commit comments