1 // ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗ 2 // ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝ 3 // ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗ 4 // ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║ 5 // ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝ 6 // ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ 7 8 #[cfg(test)] 9 mod passing { 10 use assert_cmd::prelude::*; 11 use std::env; 12 use std::process::Command; 13 14 #[test] add_new_when_provided()15 fn add_new_when_provided() { 16 let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); 17 let out = cmd 18 .arg("-M") 19 .arg("-b") 20 .arg("http://localhost:8000/") 21 .arg("data:text/html,Hello%2C%20World!") 22 .output() 23 .unwrap(); 24 25 // STDERR should be empty 26 assert_eq!(String::from_utf8_lossy(&out.stderr), ""); 27 28 // STDOUT should contain newly added base URL 29 assert_eq!( 30 String::from_utf8_lossy(&out.stdout), 31 "<html><head>\ 32 <base href=\"http://localhost:8000/\"></base>\ 33 </head><body>Hello, World!</body></html>\n" 34 ); 35 36 // Exit code should be 0 37 out.assert().code(0); 38 } 39 40 #[test] keep_existing_when_none_provided()41 fn keep_existing_when_none_provided() { 42 let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); 43 let out = cmd 44 .arg("-M") 45 .arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!") 46 .output() 47 .unwrap(); 48 49 // STDERR should be empty 50 assert_eq!(String::from_utf8_lossy(&out.stderr), ""); 51 52 // STDOUT should contain newly added base URL 53 assert_eq!( 54 String::from_utf8_lossy(&out.stdout), 55 "<html><head>\ 56 <base href=\"http://localhost:8000/\">\ 57 </head><body>Hello, World!</body></html>\n" 58 ); 59 60 // Exit code should be 0 61 out.assert().code(0); 62 } 63 64 #[test] override_existing_when_provided()65 fn override_existing_when_provided() { 66 let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); 67 let out = cmd 68 .arg("-M") 69 .arg("-b") 70 .arg("http://localhost/") 71 .arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!") 72 .output() 73 .unwrap(); 74 75 // STDERR should be empty 76 assert_eq!(String::from_utf8_lossy(&out.stderr), ""); 77 78 // STDOUT should contain newly added base URL 79 assert_eq!( 80 String::from_utf8_lossy(&out.stdout), 81 "<html><head>\ 82 <base href=\"http://localhost/\">\ 83 </head><body>Hello, World!</body></html>\n" 84 ); 85 86 // Exit code should be 0 87 out.assert().code(0); 88 } 89 90 #[test] set_existing_to_empty_when_empty_provided()91 fn set_existing_to_empty_when_empty_provided() { 92 let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); 93 let out = cmd 94 .arg("-M") 95 .arg("-b") 96 .arg("") 97 .arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!") 98 .output() 99 .unwrap(); 100 101 // STDERR should be empty 102 assert_eq!(String::from_utf8_lossy(&out.stderr), ""); 103 104 // STDOUT should contain newly added base URL 105 assert_eq!( 106 String::from_utf8_lossy(&out.stdout), 107 "<html><head>\ 108 <base href=\"\">\ 109 </head><body>Hello, World!</body></html>\n" 110 ); 111 112 // Exit code should be 0 113 out.assert().code(0); 114 } 115 } 116