@@ -105,6 +105,15 @@ function forEach(arr, func) {
105105 }
106106}
107107
108+ function expectFail ( fn ) {
109+ try {
110+ fn ( ) ;
111+ } catch ( expected ) {
112+ return ;
113+ } ;
114+ throw new Error ( "Expected to throw an error" ) ;
115+ }
116+
108117function testVim ( name , run , opts , expectedFail ) {
109118 var vimOpts = {
110119 lineNumbers : true ,
@@ -4068,11 +4077,9 @@ testVim('set_boolean', function(cm, vim, helpers) {
40684077 CodeMirror . Vim . defineOption ( 'testoption' , true , 'boolean' ) ;
40694078 // Test default value is set.
40704079 is ( CodeMirror . Vim . getOption ( 'testoption' ) ) ;
4071- try {
4072- // Test fail to set to non-boolean
4073- CodeMirror . Vim . setOption ( 'testoption' , '5' ) ;
4074- fail ( ) ;
4075- } catch ( expected ) { }
4080+ // Test fail to set to non-boolean
4081+ var result = CodeMirror . Vim . setOption ( 'testoption' , '5' ) ;
4082+ is ( result instanceof Error ) ;
40764083 // Test setOption
40774084 CodeMirror . Vim . setOption ( 'testoption' , false ) ;
40784085 is ( ! CodeMirror . Vim . getOption ( 'testoption' ) ) ;
@@ -4081,11 +4088,10 @@ testVim('ex_set_boolean', function(cm, vim, helpers) {
40814088 CodeMirror . Vim . defineOption ( 'testoption' , true , 'boolean' ) ;
40824089 // Test default value is set.
40834090 is ( CodeMirror . Vim . getOption ( 'testoption' ) ) ;
4084- try {
4085- // Test fail to set to non-boolean
4086- helpers . doEx ( 'set testoption=22' ) ;
4087- fail ( ) ;
4088- } catch ( expected ) { }
4091+ is ( ! cm . state . currentNotificationClose ) ;
4092+ // Test fail to set to non-boolean
4093+ helpers . doEx ( 'set testoption=22' ) ;
4094+ is ( cm . state . currentNotificationClose ) ;
40894095 // Test setOption
40904096 helpers . doEx ( 'set notestoption' ) ;
40914097 is ( ! CodeMirror . Vim . getOption ( 'testoption' ) ) ;
@@ -4094,16 +4100,12 @@ testVim('set_string', function(cm, vim, helpers) {
40944100 CodeMirror . Vim . defineOption ( 'testoption' , 'a' , 'string' ) ;
40954101 // Test default value is set.
40964102 eq ( 'a' , CodeMirror . Vim . getOption ( 'testoption' ) ) ;
4097- try {
4098- // Test fail to set non-string.
4099- CodeMirror . Vim . setOption ( 'testoption' , true ) ;
4100- fail ( ) ;
4101- } catch ( expected ) { }
4102- try {
4103- // Test fail to set 'notestoption'
4104- CodeMirror . Vim . setOption ( 'notestoption' , 'b' ) ;
4105- fail ( ) ;
4106- } catch ( expected ) { }
4103+ // Test no fail to set non-string.
4104+ var result = CodeMirror . Vim . setOption ( 'testoption' , true ) ;
4105+ is ( ! result ) ;
4106+ // Test fail to set 'notestoption'
4107+ result = CodeMirror . Vim . setOption ( 'notestoption' , 'b' ) ;
4108+ is ( result instanceof Error ) ;
41074109 // Test setOption
41084110 CodeMirror . Vim . setOption ( 'testoption' , 'c' ) ;
41094111 eq ( 'c' , CodeMirror . Vim . getOption ( 'testoption' ) ) ;
@@ -4112,11 +4114,10 @@ testVim('ex_set_string', function(cm, vim, helpers) {
41124114 CodeMirror . Vim . defineOption ( 'testopt' , 'a' , 'string' ) ;
41134115 // Test default value is set.
41144116 eq ( 'a' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
4115- try {
4116- // Test fail to set 'notestopt'
4117- helpers . doEx ( 'set notestopt=b' ) ;
4118- fail ( ) ;
4119- } catch ( expected ) { }
4117+ // Test fail to set 'notestopt'
4118+ is ( ! cm . state . currentNotificationClose ) ;
4119+ helpers . doEx ( 'set notestopt=b' ) ;
4120+ is ( cm . state . currentNotificationClose ) ;
41204121 // Test setOption
41214122 helpers . doEx ( 'set testopt=c' )
41224123 eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
@@ -4162,11 +4163,10 @@ testVim('ex_set_callback', function(cm, vim, helpers) {
41624163 CodeMirror . Vim . defineOption ( 'testopt' , 'a' , 'string' , cb ) ;
41634164 // Test default value is set.
41644165 eq ( 'a' , CodeMirror . Vim . getOption ( 'testopt' ) ) ;
4165- try {
4166- // Test fail to set 'notestopt'
4167- helpers . doEx ( 'set notestopt=b' ) ;
4168- fail ( ) ;
4169- } catch ( expected ) { }
4166+ // Test fail to set 'notestopt'
4167+ is ( ! cm . state . currentNotificationClose ) ;
4168+ helpers . doEx ( 'set notestopt=b' ) ;
4169+ is ( cm . state . currentNotificationClose ) ;
41704170 // Test setOption (Identical to the string tests, but via callback instead)
41714171 helpers . doEx ( 'set testopt=c' )
41724172 eq ( 'c' , CodeMirror . Vim . getOption ( 'testopt' , cm ) ) ; //local || global
@@ -4256,10 +4256,9 @@ testVim('ex_unmap_key2key', function(cm, vim, helpers) {
42564256 CodeMirror . Vim . mapclear ( ) ;
42574257} , { value : 'abc' } ) ;
42584258testVim ( 'ex_unmap_key2key_does_not_remove_default' , function ( cm , vim , helpers ) {
4259- try {
4259+ expectFail ( function ( ) {
42604260 helpers . doEx ( 'unmap a' ) ;
4261- fail ( ) ;
4262- } catch ( expected ) { }
4261+ } ) ;
42634262 helpers . doKeys ( 'a' ) ;
42644263 eq ( 'vim-insert' , cm . getOption ( 'keyMap' ) ) ;
42654264 CodeMirror . Vim . mapclear ( ) ;
0 commit comments