mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move user input logic into servoshell (#30238)
* cleanup and move user input logix into servoshell * fix fmt * moves test from servoshell file * move command-line args into servoshell * remove feature media-gstreamer * fix fmt * move user input logic code into lib to make it more testable * remove opts_matches in fn instead get it from main2 * remove pub and fix import * add licence in new file * revert passing Matches, instead pass Option String * review update, also move sanitize fn to parser file * fmt fix * review fix: remove extra line
This commit is contained in:
parent
f137b2f2c3
commit
3df284cf54
9 changed files with 84 additions and 66 deletions
|
@ -1,86 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use servo_config::opts::parse_url_or_filename;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
const FAKE_CWD: &'static str = "/fake/cwd";
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
const FAKE_CWD: &'static str = "C:/fake/cwd";
|
||||
|
||||
#[test]
|
||||
fn test_argument_parsing() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
assert!(parse_url_or_filename(fake_cwd, "http://example.net:invalid").is_err());
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "http://example.net").unwrap();
|
||||
assert_eq!(url.scheme(), "http");
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "file:///foo/bar.html").unwrap();
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["foo", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn test_file_path_parsing() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "bar.html").unwrap();
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["fake", "cwd", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_file_path_parsing() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "bar.html").unwrap();
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["C:", "fake", "cwd", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
// Windows file paths can't contain ?
|
||||
fn test_argument_parsing_special() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
|
||||
// '?' and '#' have a special meaning in URLs...
|
||||
let url = parse_url_or_filename(fake_cwd, "file:///foo/bar?baz#buzz.html").unwrap();
|
||||
assert_eq!(&*url.to_file_path().unwrap(), Path::new("/foo/bar"));
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["foo", "bar"]
|
||||
);
|
||||
assert_eq!(url.query(), Some("baz"));
|
||||
assert_eq!(url.fragment(), Some("buzz.html"));
|
||||
|
||||
// but not in file names.
|
||||
let url = parse_url_or_filename(fake_cwd, "./bar?baz#buzz.html").unwrap();
|
||||
assert_eq!(
|
||||
&*url.to_file_path().unwrap(),
|
||||
Path::new("/fake/cwd/bar?baz#buzz.html")
|
||||
);
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["fake", "cwd", "bar%3Fbaz%23buzz.html"]
|
||||
);
|
||||
assert_eq!(url.query(), None);
|
||||
assert_eq!(url.fragment(), None);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue