[Pkg-javascript-commits] [node-expat] 04/371: test: use all stepsizes for each test
Jonas Smedegaard
dr at jones.dk
Sun Feb 28 09:59:39 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-expat.
commit 2de23b91d2b8ab72315b287c7eae76d88c1d95c0
Author: Astro <astro at spaceboyz.net>
Date: Sat May 22 15:19:21 2010 +0200
test: use all stepsizes for each test
---
test.js | 67 ++++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 24 deletions(-)
diff --git a/test.js b/test.js
index 1625d96..c6742da 100644
--- a/test.js
+++ b/test.js
@@ -1,29 +1,50 @@
var sys = require('sys');
var expat = require('./build/default/expat');
-function expect(s, evs_expected) {
- var evs_received = [];
- var p = new expat.Parser();
- p.addListener('startElement', function(name, attrs) {
- evs_received.push(['startElement', name, attrs]);
- });
- p.addListener('endElement', function(name) {
- evs_received.push(['endElement', name]);
- });
- p.addListener('text', function(s) {
- evs_received.push(['text', s]);
- });
- p.addListener('cdata', function(s) {
- evs_received.push(['cdata', s]);
+function collapseTexts(evs) {
+ var r = [];
+ var t = "";
+ evs.forEach(function(ev) {
+ if (ev[0] == 'text')
+ t += ev[1];
+ else {
+ if (t != "")
+ r.push(['text', t]);
+ t = "";
+ r.push(ev);
+ }
});
- p.parse(s, true);
+ if (t != "")
+ r.push(['text', t]);
+ return r;
+}
+
+function expect(s, evs_expected) {
+ for(var step = s.length; step > 0; step--) {
+ var evs_received = [];
+ var p = new expat.Parser();
+ p.addListener('startElement', function(name, attrs) {
+ evs_received.push(['startElement', name, attrs]);
+ });
+ p.addListener('endElement', function(name) {
+ evs_received.push(['endElement', name]);
+ });
+ p.addListener('text', function(s) {
+ evs_received.push(['text', s]);
+ });
+ p.addListener('cdata', function(s) {
+ evs_received.push(['cdata', s]);
+ });
+ for(var l = 0; l < s.length; l += step)
+ p.parse(s.substr(l, step), false);
- var expected = JSON.stringify(evs_expected);
- var received = JSON.stringify(evs_received);
- if (expected != received) {
- sys.puts("Fail for: " + s);
- sys.puts("Expected: " + expected);
- sys.puts("Received: " + received);
+ var expected = JSON.stringify(evs_expected);
+ var received = JSON.stringify(collapseTexts(evs_received));
+ if (expected != received) {
+ sys.puts("Fail for: " + s + " (step=" + step + ")");
+ sys.puts("Expected: " + expected);
+ sys.puts("Received: " + received);
+ }
}
}
@@ -45,9 +66,7 @@ expect("<r>foo</r>",
['endElement', 'r']]);
expect("<r>foo\nbar</r>",
[['startElement', 'r', {}],
- ['text', "foo"],
- ['text', "\n"],
- ['text', "bar"],
+ ['text', "foo\nbar"],
['endElement', 'r']]);
expect("<r><![CDATA[<greeting>Hello, world!</greeting>]]></r>",
[['startElement', 'r', {}],
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git
More information about the Pkg-javascript-commits
mailing list