Permalink
Browse files

Extra tests for issues. Updated roadmap.

  • Loading branch information...
timdown committed May 10, 2015
1 parent d00807b commit ed8f997d7f710cd2ebaa8a2a18e9dcb39301085f
Showing with 85 additions and 9 deletions.
  1. +2 −2 builder/build.js
  2. +1 −1 demos/highlighter.html
  3. +6 −0 fiddlings/browserify/test.html
  4. +3 −0 roadmap.txt
  5. +13 −0 test/rangetests.js
  6. +60 −6 test/textrangetests.js
View
@@ -118,14 +118,14 @@ function getVersion() {
console.log("Getting version from Git repo");
exec("git describe", function(error, stdout, stderr) {
console.log(error, stdout, stderr);
- console.log("Getting version from package.json");
buildVersion = JSON.parse( fs.readFileSync("package.json")).version;
+ console.log("Got version " + buildVersion + " from package.json");
zipDir = buildDir + "rangy-" + buildVersion + "/";
fs.mkdirSync(zipDir);
uncompressedBuildDir = zipDir + "uncompressed/";
fs.mkdirSync(uncompressedBuildDir);
- console.log("Got git version " + stdout);
+ console.log("Got git version " + stdout + " but not using that");
callback();
});
}
View
@@ -11,7 +11,7 @@
.note {
background-color: limegreen;
}
-
+
#summary {
border: dotted orange 1px;
}
@@ -3,6 +3,12 @@
<head>
<title></title>
<script src="bundle.js"></script>
+ <script>
+ window.onload = function() {
+ rangy.init();
+ console.log(rangy.modules);
+ }
+ </script>
</head>
<body>
View
@@ -29,6 +29,8 @@
- [ ] Add withinRange and withinNode options to move(), moveStart() and moveEnd() methods
- [?] Positions module
(http://stackoverflow.com/questions/4122315/how-to-find-xy-position-in-javascript-with-offset/4123495#4123495)
+- [ ] Config module or something so that config can work with AMD. See P" 285
+ (https://github.com/timdown/rangy/pull/285)
Possible features for some version
----------------------------------
@@ -37,3 +39,4 @@ Possible features for some version
(http://stackoverflow.com/questions/2887101/apply-style-to-range-of-text-with-javascript-in-uiwebview/2888969#2888969)
- [?] More commands (block? Insert line break? Think about this, don't want to build a WYSIWYG editor)
- [ ] Add selection extend()? Don't think this is possible.
+- [ ] Option in TextRange module for alternative ways to extract text for an element (see email from Bruce Augustine)
View
@@ -301,6 +301,19 @@ function testRangeCreator(docs, docName, rangeCreator, rangeCreatorName) {
});
s.test("extractContents in single text node", function(t) {
+ var range = rangeCreator(doc);
+ t.nodes.div.innerHTML = "<p>1 2 <span>3</span> 4 5</p>";
+ var p = t.nodes.div.firstChild;
+ range.setStart(p.firstChild, 2);
+ range.setEnd(p.lastChild, 2);
+ var frag = range.extractContents();
+ var container = doc.createElement("div");
+ container.appendChild(frag);
+ t.assertEquals(container.innerHTML, "2 <span>3</span> 4");
+ t.assertEquals(t.nodes.div.innerHTML, "<p>1 5</p>");
+ });
+
+ s.test("extractContents inside paragraph (issue 163)", function(t) {
var range = rangeCreator(doc);
range.setStart(t.nodes.plainText, 1);
range.setEnd(t.nodes.plainText, 2);
View
@@ -495,34 +495,38 @@ xn.test.suite("Text Range module tests", function(s) {
t.assertEquals(range.startOffset, 0);
});
+ function visibleSpaces(str) {
+ return str.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\s/g, function(m) { return "[" + m.charCodeAt(0) + "]"; });
+ }
+
s.test("innerText on br inside block 1", function(t) {
t.el.innerHTML = '<div><br></div>';
- t.assertEquals(rangy.innerText(t.el).replace(/\n/g, "\\n"), "\\n");
+ t.assertEquals(visibleSpaces( rangy.innerText(t.el) ), "\\n");
});
s.test("innerText on br inside block 2", function(t) {
t.el.innerHTML = '<div>x<div><br></div></div>';
- t.assertEquals(rangy.innerText(t.el).replace(/\n/g, "\\n"), "x\\n");
+ t.assertEquals(visibleSpaces( rangy.innerText(t.el) ), "x\\n");
});
s.test("innerText on br inside block 3", function(t) {
t.el.innerHTML = '<div>x<div><br></div>y</div>z';
- t.assertEquals(rangy.innerText(t.el).replace(/\n/g, "\\n"), "x\\ny\\nz");
+ t.assertEquals(visibleSpaces( rangy.innerText(t.el) ), "x\\ny\\nz");
});
s.test("innerText on br inside block 4", function(t) {
t.el.innerHTML = '<div>x<div><br></div>y</div>z';
- t.assertEquals(rangy.innerText(t.el).replace(/\n/g, "\\n"), "x\\ny\\nz");
+ t.assertEquals(visibleSpaces( rangy.innerText(t.el) ), "x\\ny\\nz");
});
s.test("innerText on br inside block 5", function(t) {
t.el.innerHTML = 'x<div><br></div><div><br></div>';
- t.assertEquals(rangy.innerText(t.el).replace(/\n/g, "\\n"), "x\\n\\n");
+ t.assertEquals(visibleSpaces( rangy.innerText(t.el) ), "x\\n\\n");
});
s.test("innerText on br inside block 6", function(t) {
t.el.innerHTML = '<div><div><br></div></div>';
- t.assertEquals(rangy.innerText(t.el).replace(/\n/g, "\\n"), "\\n");
+ t.assertEquals(visibleSpaces( rangy.innerText(t.el) ), "\\n");
});
@@ -1257,4 +1261,54 @@ xn.test.suite("Text Range module tests", function(s) {
t.assertEquals(charRange.start, 2);
t.assertEquals(charRange.end, 2);
});
+
+ s.test("Issue 304", function(t) {
+/*
+ t.el.innerHTML = "<span>1 2";
+ t.assertEquals(visibleSpaces(rangy.innerText(t.el)), visibleSpaces("1 2") );
+*/
+
+ t.el.innerHTML = "<span>X</span> <span> Y</span>";
+ t.assertEquals(visibleSpaces(rangy.innerText(t.el)), visibleSpaces("X Y") );
+
+/*
+ t.el.innerHTML = ["<span>female</span>",
+ " <span> presents to the ED with a Chief Complaint of </span>",
+ " <span>Shoulder Pain</span>"].join("\n");
+
+ t.assertEquals(visibleSpaces(rangy.innerText(t.el)), visibleSpaces("female presents to the ED with a Chief Complaint of Shoulder Pain") );
+*/
+ });
+
+ s.test("Paragraphs test (issue 128)", function(t) {
+ t.el.innerHTML = "\n <p>a</p>\n <p>a</p>\n";
+ var p = t.el.getElementsByTagName("p")[1];
+ var range = rangy.createRange();
+ range.setStartAndEnd(p.firstChild, 0, 1);
+ var charRange = range.toCharacterRange(t.el);
+ t.assertEquals(charRange.start, 2);
+ t.assertEquals(charRange.end, 3);
+
+ var sel = rangy.getSelection();
+ sel.selectAllChildren(p);
+ charRange = sel.getRangeAt(0).toCharacterRange(t.el);
+ t.assertEquals(charRange.start, 2);
+ t.assertEquals(charRange.end, 3);
+ });
+
+ s.test("Word iterator test (issue 130)", function(t) {
+ t.el.innerHTML = "Hello . . Goodbye";
+ var it = rangy.createWordIterator(t.el, 0);
+ var word, words = [];
+ while ( (word = it.next()) ) {
+ if (!rangy.dom.isOrIsAncestorOf(t.el, word.chars[0].node)) {
+ break;
+ }
+ if (word.isWord) {
+ words.push(word.toString());
+ }
+ }
+ t.assertArraysEquivalent(words, ["Hello", "Goodbye"]);
+ });
+
}, false);

0 comments on commit ed8f997

Please sign in to comment.