| 0 | 1 /** | 
|  | 2  * Test Harness for CodeMirror | 
|  | 3  * JS-unit compatible tests here.  The two available assertions are | 
|  | 4  * assertEquals (strict equality) and assertEquivalent (looser equivalency). | 
|  | 5  * | 
|  | 6  * 'editor' is a global object for the CodeMirror editor shared between all | 
|  | 7  * tests.  After manipulating it in each test, try to restore it to | 
|  | 8  * approximately its original state. | 
|  | 9  */ | 
|  | 10 | 
|  | 11 function testSetGet() { | 
|  | 12   var code = 'It was the best of times.\nIt was the worst of times.'; | 
|  | 13   editor.setCode(code); | 
|  | 14   assertEquals(code, editor.getCode()); | 
|  | 15   editor.setCode(''); | 
|  | 16   assertEquals('', editor.getCode()); | 
|  | 17 } | 
|  | 18 | 
|  | 19 function testSetStylesheet() { | 
|  | 20   function cssStatus() { | 
|  | 21     // Returns a list of tuples, for each CSS link return the filename and | 
|  | 22     // whether it is enabled. | 
|  | 23     links = editor.win.document.getElementsByTagName('link'); | 
|  | 24     css = []; | 
|  | 25     for (var x = 0, link; link = links[x]; x++) { | 
|  | 26       if (link.rel.indexOf("stylesheet") !== -1) { | 
|  | 27         css.push([link.href.substring(link.href.lastIndexOf('/') + 1), | 
|  | 28                  !link.disabled]) | 
|  | 29       } | 
|  | 30     } | 
|  | 31     return css; | 
|  | 32   } | 
|  | 33   assertEquivalent([], cssStatus()); | 
|  | 34   editor.setStylesheet('css/jscolors.css'); | 
|  | 35   assertEquivalent([['jscolors.css', true]], cssStatus()); | 
|  | 36   editor.setStylesheet(['css/csscolors.css', 'css/xmlcolors.css']); | 
|  | 37   assertEquivalent([['jscolors.css', false], ['csscolors.css', true], ['xmlcolors.css', true]], cssStatus()); | 
|  | 38   editor.setStylesheet([]); | 
|  | 39   assertEquivalent([['jscolors.css', false], ['csscolors.css', false], ['xmlcolors.css', false]], cssStatus()); | 
|  | 40 } | 
|  | 41 | 
|  | 42 // Update this list of tests as new ones are added. | 
|  | 43 var tests = ['testSetGet', 'testSetStylesheet']; | 
|  | 44 |