mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Allow cli prefs to have numerical value
Fix for #14842. Extract the code inside a function to unit-test it.
This commit is contained in:
parent
4216c16879
commit
6a22174eb7
2 changed files with 40 additions and 9 deletions
|
@ -2,7 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use servo_config::opts::parse_url_or_filename;
|
||||
use servo_config::opts::{parse_url_or_filename, parse_pref_from_command_line};
|
||||
use servo_config::prefs::{PrefValue, PREFS};
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -67,3 +68,26 @@ fn test_argument_parsing_special() {
|
|||
assert_eq!(url.query(), None);
|
||||
assert_eq!(url.fragment(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_pref_from_command_line() {
|
||||
// Test with boolean values.
|
||||
parse_pref_from_command_line("testtrue=true");
|
||||
assert_eq!(*PREFS.get("testtrue"), PrefValue::Boolean(true));
|
||||
parse_pref_from_command_line("testfalse=false");
|
||||
assert_eq!(*PREFS.get("testfalse"), PrefValue::Boolean(false));
|
||||
|
||||
// Test with numbers.
|
||||
parse_pref_from_command_line("testint=42");
|
||||
assert_eq!(*PREFS.get("testint"), PrefValue::Number(42 as f64));
|
||||
parse_pref_from_command_line("testfloat=4.2");
|
||||
assert_eq!(*PREFS.get("testfloat"), PrefValue::Number(4.2));
|
||||
|
||||
// Test default (string).
|
||||
parse_pref_from_command_line("teststr=str");
|
||||
assert_eq!(*PREFS.get("teststr"), PrefValue::String("str".to_owned()));
|
||||
|
||||
// Test with no value.
|
||||
parse_pref_from_command_line("testempty");
|
||||
assert_eq!(*PREFS.get("testempty"), PrefValue::Boolean(true));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue