[Pkg-javascript-commits] [node-expat] 289/371: More refactor

Jonas Smedegaard dr at jones.dk
Sun Feb 28 10:00:21 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 98973f27cb3484c1cd6242cce5ab7237b9610c07
Author: Lloyd Watkin <lloyd.watkin at surevine.com>
Date:   Mon Nov 24 13:28:20 2014 +0000

    More refactor
---
 test/index.js | 184 +++++++++++++++++++++++++++-------------------------------
 1 file changed, 85 insertions(+), 99 deletions(-)

diff --git a/test/index.js b/test/index.js
index fd3360d..55b805c 100644
--- a/test/index.js
+++ b/test/index.js
@@ -218,7 +218,7 @@ vows.describe('node-expat').addBatch({
           }
           p.setUnknownEncoding(map);
         });
-        var text = "";
+        var text = '';
         p.addListener('text', function(s) {
           text += s;
         });
@@ -259,119 +259,105 @@ vows.describe('node-expat').addBatch({
   }
     },
     'stop and resume': {
-	topic: function() {
-	    var cb = this.callback;
-	    var p = new expat.Parser("UTF-8");
-
-	    var input = '\
-		<wrap> \
-			<short /> \
-			<short></short> \
-			<long /> \
-			<short /> \
-			<long>foo</long> \
-		</wrap>';
+        topic: function() {
+            var cb = this.callback;
+            var p = new expat.Parser("UTF-8");
 
-	    var expected = ['wrap', 'short', 'short', 'long', 'short', 'long'];
-	    var received = [];
+            var input = '\
+            <wrap> \
+                <short /> \
+                <short></short> \
+                <long /> \
+                <short /> \
+                <long>foo</long> \
+            </wrap>';
 
-	    var tolerance = 10/100;
-	    var expectedRuntime = 1000;
-	    var start = new Date();
+            var expected = ['wrap', 'short', 'short', 'long', 'short', 'long'];
+            var received = [];
 
-	    p.addListener('startElement', function(name, attrs) {
-		received.push(name);
+            var tolerance = 10/100;
+            var expectedRuntime = 1000;
+            var start = new Date();
 
-		// suspend parser for 1/2 second
-		if(name == 'long') {
-		    p.stop();
+            p.addListener('startElement', function(name, attrs) {
+                received.push(name)
 
-		    setTimeout(function() {
-			p.resume();
-		    }, 500);
-		}
-	    });
+                // suspend parser for 1/2 second
+                if (name == 'long') {
+                    p.stop()
+                    setTimeout(function() {
+                        p.resume()
+                    }, 500)
+                }
+            });
 
-	    p.addListener('endElement', function(name) {
-		// finished parsing
-		if(name == 'wrap') {
-		    // test elements received (count. naming, order)
-		    assert.equal(JSON.stringify(received), JSON.stringify(expected));
+            p.addListener('endElement', function(name) {
+            // finished parsing
+            if(name == 'wrap') {
+                // test elements received (count. naming, order)
+                assert.equal(JSON.stringify(received), JSON.stringify(expected));
 
-		    // test timing (+-5%)
-		    var now = new Date();
-		    var diff = now.getTime() - start.getTime();
-		    var max = expectedRuntime + expectedRuntime * tolerance,
-			min = expectedRuntime - expectedRuntime * tolerance;
+                // test timing (+-5%)
+                var now = new Date();
+                var diff = now.getTime() - start.getTime();
+                var max = expectedRuntime + expectedRuntime * tolerance,
+                min = expectedRuntime - expectedRuntime * tolerance;
 
-		    assert.ok(diff < max, 'Runtime within maximum expected time');
-		    assert.ok(diff > min, 'Runtime at least minimum expected time');
+                assert.ok(diff < max, 'Runtime within maximum expected time');
+                assert.ok(diff > min, 'Runtime at least minimum expected time');
 
-		    return cb(true);
-		}
-	    });
+                return cb(true);
+            }
+            });
 
-	    assert.ok(p.parse(input));
-	},
-	'should have worked': function() {
-	    assert.ok(true, 'start & stop works');
-	}
+            assert.ok(p.parse(input));
+        },
+        'should have worked': function() {
+            assert.ok(true, 'start & stop works')
+        }
     },
     'corner cases': {
-	'parse empty string': function() {
-	    var p = new expat.Parser("UTF-8");
-	    p.parse('');
-	    assert.ok(true, "Did not segfault");
-	},
-    'Escaping of ampersands': function() {
-	    expect('<e>foo & bar</e>',
-		[['startElement', 'e', {}],
-		['text', 'foo & bar'],
-		['endElement', 'e']])
-    },
-	'parsing twice the same document with the same parser instance should be fine': 
-	  function() {
-	   var p = new expat.Parser('UTF-8')
-           var xml = '<foo>bar</foo>'
-           var result = p.parse(xml)
-           assert.ok(result)
-           assert.isNull(p.getError())
-           p.reset()
-           var result2 = p.parse(xml)
-           assert.isNull(p.getError())
-           assert.ok(result2)
-
+        'parse empty string': function() {
+            var p = new expat.Parser('UTF-8')
+            p.parse('')
+            assert.ok(true, 'Did not segfault')
+        },
+        'Escaping of ampersands': function() {
+            expect('<e>foo & bar</e>',
+            [['startElement', 'e', {}],
+            ['text', 'foo & bar'],
+            ['endElement', 'e']])
         }
     },
     'statistics': {
-	'line number': function() {
-	    var p = new expat.Parser()
-	    assert.equal(p.getCurrentLineNumber(), 1)
-	    p.parse('\n')
-	    assert.equal(p.getCurrentLineNumber(), 2)
-	    p.parse('\n')
-	    assert.equal(p.getCurrentLineNumber(), 3)
-	},
-	'column number': function() {
-	    var p = new expat.Parser();
-	    assert.equal(p.getCurrentColumnNumber(), 0)
-	    p.parse(' ')
-	    assert.equal(p.getCurrentColumnNumber(), 1)
-	    p.parse(' ')
-	    assert.equal(p.getCurrentColumnNumber(), 2)
-	    p.parse('\n')
-	    assert.equal(p.getCurrentColumnNumber(), 0)
-	},
-	'byte index': function() {
-	    var p = new expat.Parser()
-	    assert.equal(p.getCurrentByteIndex(), -1)
-	    p.parse('')
-	    assert.equal(p.getCurrentByteIndex(), -1)
-	    p.parse('\n')
-	    assert.equal(p.getCurrentByteIndex(), 1)
-	    p.parse(' ')
-	    assert.equal(p.getCurrentByteIndex(), 2)
-	},
+        'line number': function() {
+            var p = new expat.Parser()
+            assert.equal(p.getCurrentLineNumber(), 1)
+            p.parse('\n')
+            assert.equal(p.getCurrentLineNumber(), 2)
+            p.parse('\n')
+            assert.equal(p.getCurrentLineNumber(), 3)
+        },
+        'column number': function() {
+            var p = new expat.Parser();
+            assert.equal(p.getCurrentColumnNumber(), 0)
+            p.parse(' ')
+            assert.equal(p.getCurrentColumnNumber(), 1)
+            p.parse(' ')
+            assert.equal(p.getCurrentColumnNumber(), 2)
+            p.parse('\n')
+            assert.equal(p.getCurrentColumnNumber(), 0)
+        },
+        'byte index': function() {
+            var p = new expat.Parser()
+            assert.equal(p.getCurrentByteIndex(), -1)
+            p.parse('')
+            assert.equal(p.getCurrentByteIndex(), -1)
+            p.parse('\n')
+            assert.equal(p.getCurrentByteIndex(), 1)
+            p.parse(' ')
+            assert.equal(p.getCurrentByteIndex(), 2)
+        },
     },
     'Stream interface': {
         'read file': {

-- 
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