Files
firefox/browser/devtools/shared/test/unit/test_undoStack.js
T
Jim Blandy 39dc0c6097 Bug 914753: Make Emacs file variable header lines correct, or at least consistent. DONTBUILD r=ehsan
The -*- file variable lines -*- establish per-file settings that Emacs will
pick up. This patch makes the following changes to those lines (and touches
nothing else):

 - Never set the buffer's mode.

   Years ago, Emacs did not have a good JavaScript mode, so it made sense
   to use Java or C++ mode in .js files. However, Emacs has had js-mode for
   years now; it's perfectly serviceable, and is available and enabled by
   default in all major Emacs packagings.

   Selecting a mode in the -*- file variable line -*- is almost always the
   wrong thing to do anyway. It overrides Emacs's default choice, which is
   (now) reasonable; and even worse, it overrides settings the user might
   have made in their '.emacs' file for that file extension. It's only
   useful when there's something specific about that particular file that
   makes a particular mode appropriate.

 - Correctly propagate settings that establish the correct indentation
   level for this file: c-basic-offset and js2-basic-offset should be
   js-indent-level. Whatever value they're given should be preserved;
   different parts of our tree use different indentation styles.

 - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil.
   Remove tab-width: settings, at least in files that don't contain tab
   characters.

 - Remove js2-mode settings that belong in the user's .emacs file, like
   js2-skip-preprocessor-directives.
2014-06-24 22:12:07 -07:00

99 lines
2.0 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const Cu = Components.utils;
let {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
let loader = new Loader.Loader({
paths: {
"": "resource://gre/modules/commonjs/",
"devtools": "resource:///modules/devtools",
},
globals: {},
});
let require = Loader.Require(loader, { id: "undo-test" })
let {UndoStack} = require("devtools/shared/undo");
const MAX_SIZE = 5;
function run_test()
{
let str = "";
let stack = new UndoStack(MAX_SIZE);
function add(ch) {
stack.do(function() {
str += ch;
}, function() {
str = str.slice(0, -1);
});
}
do_check_false(stack.canUndo());
do_check_false(stack.canRedo());
// Check adding up to the limit of the size
add("a");
do_check_true(stack.canUndo());
do_check_false(stack.canRedo());
add("b");
add("c");
add("d");
add("e");
do_check_eq(str, "abcde");
// Check a simple undo+redo
stack.undo();
do_check_eq(str, "abcd");
do_check_true(stack.canRedo());
stack.redo();
do_check_eq(str, "abcde")
do_check_false(stack.canRedo());
// Check an undo followed by a new action
stack.undo();
do_check_eq(str, "abcd");
add("q");
do_check_eq(str, "abcdq");
do_check_false(stack.canRedo());
stack.undo();
do_check_eq(str, "abcd");
stack.redo();
do_check_eq(str, "abcdq");
// Revert back to the beginning of the queue...
while (stack.canUndo()) {
stack.undo();
}
do_check_eq(str, "");
// Now put it all back....
while (stack.canRedo()) {
stack.redo();
}
do_check_eq(str, "abcdq");
// Now go over the undo limit...
add("1");
add("2");
add("3");
do_check_eq(str, "abcdq123");
// And now undoing the whole stack should only undo 5 actions.
while (stack.canUndo()) {
stack.undo();
}
do_check_eq(str, "abc");
}