@@ -19,4 +19,42 @@ describe('OptionsService', () => {
1919 assert . equal ( new OptionsService ( { tabStopWidth : 0 } ) . getOption ( 'tabStopWidth' ) , DEFAULT_OPTIONS . tabStopWidth ) ;
2020 } ) ;
2121 } ) ;
22+ describe ( 'setOption' , ( ) => {
23+ let service : OptionsService ;
24+ beforeEach ( ( ) => {
25+ service = new OptionsService ( { } ) ;
26+ } ) ;
27+ it ( 'applies valid fontWeight option values' , ( ) => {
28+ service . setOption ( 'fontWeight' , 'bold' ) ;
29+ assert . equal ( service . getOption ( 'fontWeight' ) , 'bold' , '"bold" keyword value should be applied' ) ;
30+
31+ service . setOption ( 'fontWeight' , 'normal' ) ;
32+ assert . equal ( service . getOption ( 'fontWeight' ) , 'normal' , '"normal" keyword value should be applied' ) ;
33+
34+ service . setOption ( 'fontWeight' , '600' ) ;
35+ assert . equal ( service . getOption ( 'fontWeight' ) , '600' , 'String numeric values should be applied' ) ;
36+
37+ service . setOption ( 'fontWeight' , 350 ) ;
38+ assert . equal ( service . getOption ( 'fontWeight' ) , 350 , 'Values between 1 and 1000 should be applied as is' ) ;
39+
40+ service . setOption ( 'fontWeight' , 1 ) ;
41+ assert . equal ( service . getOption ( 'fontWeight' ) , 1 , 'Range should include minimum value: 1' ) ;
42+
43+ service . setOption ( 'fontWeight' , 1000 ) ;
44+ assert . equal ( service . getOption ( 'fontWeight' ) , 1000 , 'Range should include maximum value: 1000' ) ;
45+ } ) ;
46+ it ( 'normalizes invalid fontWeight option values' , ( ) => {
47+ service . setOption ( 'fontWeight' , 350 ) ;
48+ assert . doesNotThrow ( ( ) => service . setOption ( 'fontWeight' , 10000 ) , 'fontWeight should be normalized instead of throwing' ) ;
49+ assert . equal ( service . getOption ( 'fontWeight' ) , DEFAULT_OPTIONS . fontWeight , 'Values greater than 1000 should be reset to default' ) ;
50+
51+ service . setOption ( 'fontWeight' , 350 ) ;
52+ service . setOption ( 'fontWeight' , - 10 ) ;
53+ assert . equal ( service . getOption ( 'fontWeight' ) , DEFAULT_OPTIONS . fontWeight , 'Values less than 1 should be reset to default' ) ;
54+
55+ service . setOption ( 'fontWeight' , 350 ) ;
56+ service . setOption ( 'fontWeight' , 'bold700' ) ;
57+ assert . equal ( service . getOption ( 'fontWeight' ) , DEFAULT_OPTIONS . fontWeight , 'Wrong string literals should be reset to default' ) ;
58+ } ) ;
59+ } ) ;
2260} ) ;
0 commit comments