File: unittests.js

package info (click to toggle)
libatteanx-endpoint-perl 0.002-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 528 kB
  • sloc: javascript: 3,887; perl: 1,862; makefile: 12; sh: 5
file content (44 lines) | stat: -rw-r--r-- 1,630 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * Test Harness for CodeMirror
 * JS-unit compatible tests here.  The two available assertions are
 * assertEquals (strict equality) and assertEquivalent (looser equivalency).
 *
 * 'editor' is a global object for the CodeMirror editor shared between all
 * tests.  After manipulating it in each test, try to restore it to
 * approximately its original state.
 */

function testSetGet() {
  var code = 'It was the best of times.\nIt was the worst of times.';
  editor.setCode(code);
  assertEquals(code, editor.getCode());
  editor.setCode('');
  assertEquals('', editor.getCode());
}

function testSetStylesheet() {
  function cssStatus() {
    // Returns a list of tuples, for each CSS link return the filename and
    // whether it is enabled.
    links = editor.win.document.getElementsByTagName('link');
    css = [];
    for (var x = 0, link; link = links[x]; x++) {
      if (link.rel.indexOf("stylesheet") !== -1) {
        css.push([link.href.substring(link.href.lastIndexOf('/') + 1),
                 !link.disabled])
      }
    }
    return css;
  }
  assertEquivalent([], cssStatus());
  editor.setStylesheet('css/jscolors.css');
  assertEquivalent([['jscolors.css', true]], cssStatus());
  editor.setStylesheet(['css/csscolors.css', 'css/xmlcolors.css']);
  assertEquivalent([['jscolors.css', false], ['csscolors.css', true], ['xmlcolors.css', true]], cssStatus());
  editor.setStylesheet([]);
  assertEquivalent([['jscolors.css', false], ['csscolors.css', false], ['xmlcolors.css', false]], cssStatus());
}

// Update this list of tests as new ones are added.
var tests = ['testSetGet', 'testSetStylesheet'];