test_advanceValidate.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/ */
  4. "use strict";
  5. // Tests the advanceValidate function from rule-view.js.
  6. const {utils: Cu, interfaces: Ci} = Components;
  7. const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
  8. const {advanceValidate} = require("devtools/client/inspector/shared/utils");
  9. // 1 2 3
  10. // 0123456789012345678901234567890
  11. const sampleInput = '\\symbol "string" url(somewhere)';
  12. function testInsertion(where, result, testName) {
  13. do_print(testName);
  14. equal(advanceValidate(Ci.nsIDOMKeyEvent.DOM_VK_SEMICOLON, sampleInput, where),
  15. result, "testing advanceValidate at " + where);
  16. }
  17. function run_test() {
  18. testInsertion(4, true, "inside a symbol");
  19. testInsertion(1, false, "after a backslash");
  20. testInsertion(8, true, "after whitespace");
  21. testInsertion(11, false, "inside a string");
  22. testInsertion(24, false, "inside a URL");
  23. testInsertion(31, true, "at the end");
  24. }