mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Format components config #21373
This commit is contained in:
parent
c8f3abfdbc
commit
ce41c95e05
6 changed files with 444 additions and 225 deletions
|
@ -24,7 +24,10 @@ fn test_argument_parsing() {
|
|||
|
||||
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"]);
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["foo", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -34,7 +37,10 @@ fn test_file_path_parsing() {
|
|||
|
||||
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"]);
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["fake", "cwd", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -44,7 +50,10 @@ fn test_file_path_parsing() {
|
|||
|
||||
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"]);
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["C:", "fake", "cwd", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -57,16 +66,24 @@ fn test_argument_parsing_special() {
|
|||
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.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.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.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["fake", "cwd", "bar%3Fbaz%23buzz.html"]
|
||||
);
|
||||
assert_eq!(url.query(), None);
|
||||
assert_eq!(url.fragment(), None);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ use std::io::{Read, Write};
|
|||
#[test]
|
||||
fn test_create_pref() {
|
||||
let json_str = "{\
|
||||
\"layout.writing-mode.enabled\": true,\
|
||||
\"network.mime.sniff\": false,\
|
||||
\"shell.homepage\": \"https://servo.org\"\
|
||||
}";
|
||||
\"layout.writing-mode.enabled\": true,\
|
||||
\"network.mime.sniff\": false,\
|
||||
\"shell.homepage\": \"https://servo.org\"\
|
||||
}";
|
||||
|
||||
let prefs = read_prefs(json_str);
|
||||
assert!(prefs.is_ok());
|
||||
|
@ -27,40 +27,52 @@ fn test_create_pref() {
|
|||
#[test]
|
||||
fn test_get_set_reset_extend() {
|
||||
let json_str = "{\
|
||||
\"layout.writing-mode.enabled\": true,\
|
||||
\"extra.stuff\": false,\
|
||||
\"shell.homepage\": \"https://google.com\"\
|
||||
}";
|
||||
\"layout.writing-mode.enabled\": true,\
|
||||
\"extra.stuff\": false,\
|
||||
\"shell.homepage\": \"https://google.com\"\
|
||||
}";
|
||||
|
||||
assert_eq!(*PREFS.get("test"), PrefValue::Missing);
|
||||
PREFS.set("test", PrefValue::String("hi".to_owned()));
|
||||
assert_eq!(*PREFS.get("test"), PrefValue::String("hi".to_owned()));
|
||||
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::String("https://servo.org".to_owned()));
|
||||
assert_eq!(
|
||||
*PREFS.get("shell.homepage"),
|
||||
PrefValue::String("https://servo.org".to_owned())
|
||||
);
|
||||
PREFS.set("shell.homepage", PrefValue::Boolean(true));
|
||||
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::Boolean(true));
|
||||
PREFS.reset("shell.homepage");
|
||||
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::String("https://servo.org".to_owned()));
|
||||
assert_eq!(
|
||||
*PREFS.get("shell.homepage"),
|
||||
PrefValue::String("https://servo.org".to_owned())
|
||||
);
|
||||
|
||||
let extension = read_prefs(json_str).unwrap();
|
||||
PREFS.extend(extension);
|
||||
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::String("https://google.com".to_owned()));
|
||||
assert_eq!(*PREFS.get("layout.writing-mode.enabled"), PrefValue::Boolean(true));
|
||||
assert_eq!(
|
||||
*PREFS.get("shell.homepage"),
|
||||
PrefValue::String("https://google.com".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
*PREFS.get("layout.writing-mode.enabled"),
|
||||
PrefValue::Boolean(true)
|
||||
);
|
||||
assert_eq!(*PREFS.get("extra.stuff"), PrefValue::Boolean(false));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[test]
|
||||
fn test_default_config_dir_create_read_write() {
|
||||
let json_str = "{\
|
||||
\"layout.writing-mode.enabled\": true,\
|
||||
\"extra.stuff\": false,\
|
||||
\"shell.homepage\": \"https://google.com\"\
|
||||
}";
|
||||
let json_str = "{\
|
||||
\"layout.writing-mode.enabled\": true,\
|
||||
\"extra.stuff\": false,\
|
||||
\"shell.homepage\": \"https://google.com\"\
|
||||
}";
|
||||
let mut expected_json = String::new();
|
||||
let config_path = basedir::default_config_dir().unwrap();
|
||||
|
||||
if !config_path.exists() {
|
||||
fs::create_dir_all(&config_path).unwrap();
|
||||
fs::create_dir_all(&config_path).unwrap();
|
||||
}
|
||||
|
||||
let json_path = config_path.join("test_config.json");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue