summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_parser-07.js
blob: bea913a9ed62689ad928df18acbc927b788b3f46 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Check that nodes with locaiton information attached can be properly
 * verified for containing lines and columns.
 */

function test() {
  let { ParserHelpers } = Cu.import("resource://devtools/shared/Parser.jsm", {});

  let node1 = { loc: {
    start: { line: 1, column: 10 },
    end: { line: 10, column: 1 }
  }};
  let node2 = { loc: {
    start: { line: 1, column: 10 },
    end: { line: 1, column: 20 }
  }};

  ok(ParserHelpers.nodeContainsLine(node1, 1), "1st check.");
  ok(ParserHelpers.nodeContainsLine(node1, 5), "2nd check.");
  ok(ParserHelpers.nodeContainsLine(node1, 10), "3rd check.");

  ok(!ParserHelpers.nodeContainsLine(node1, 0), "4th check.");
  ok(!ParserHelpers.nodeContainsLine(node1, 11), "5th check.");

  ok(ParserHelpers.nodeContainsLine(node2, 1), "6th check.");
  ok(!ParserHelpers.nodeContainsLine(node2, 0), "7th check.");
  ok(!ParserHelpers.nodeContainsLine(node2, 2), "8th check.");

  ok(!ParserHelpers.nodeContainsPoint(node1, 1, 10), "9th check.");
  ok(!ParserHelpers.nodeContainsPoint(node1, 10, 1), "10th check.");

  ok(!ParserHelpers.nodeContainsPoint(node1, 0, 10), "11th check.");
  ok(!ParserHelpers.nodeContainsPoint(node1, 11, 1), "12th check.");

  ok(!ParserHelpers.nodeContainsPoint(node1, 1, 9), "13th check.");
  ok(!ParserHelpers.nodeContainsPoint(node1, 10, 2), "14th check.");

  ok(ParserHelpers.nodeContainsPoint(node2, 1, 10), "15th check.");
  ok(ParserHelpers.nodeContainsPoint(node2, 1, 15), "16th check.");
  ok(ParserHelpers.nodeContainsPoint(node2, 1, 20), "17th check.");

  ok(!ParserHelpers.nodeContainsPoint(node2, 0, 10), "18th check.");
  ok(!ParserHelpers.nodeContainsPoint(node2, 2, 20), "19th check.");

  ok(!ParserHelpers.nodeContainsPoint(node2, 0, 9), "20th check.");
  ok(!ParserHelpers.nodeContainsPoint(node2, 2, 21), "21th check.");

  ok(!ParserHelpers.nodeContainsPoint(node2, 1, 9), "22th check.");
  ok(!ParserHelpers.nodeContainsPoint(node2, 1, 21), "23th check.");

  finish();
}