github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/logfmt/test/parser_tests.js (about) 1 var logfmt = require('../logfmt'), 2 assert = require('assert'); 3 4 suite('logfmt.parse', function() { 5 test("simple flag parses", function(){ 6 assert.deepEqual({'hello':true}, logfmt.parse('hello')); 7 }) 8 9 test("simple key/value parses", function(){ 10 assert.deepEqual({'hello':'kitty'}, logfmt.parse('hello=kitty')); 11 }) 12 13 test("simple boolean parses", function(){ 14 assert.deepEqual({'foo':true, 'bar':false}, 15 logfmt.parse('foo=true bar=false')); 16 }) 17 18 test('big numbers dont lose precision', function(){ 19 var parsed = logfmt.parse("thing=90071992547409934"); 20 assert.equal(parsed.thing.toString(), '90071992547409934'); 21 }) 22 23 test("number parse to strings", function(){ 24 assert.deepEqual({'foo':'123', 'bar':'456.789'}, 25 logfmt.parse('foo=123 bar=456.789')); 26 }) 27 28 test("string with escapes", function(){ 29 assert.deepEqual({'hello':"\'kitty\'"}, 30 logfmt.parse('hello="\'kitty\'"')); 31 assert.deepEqual({'hello':"\'kitty\'"}, 32 logfmt.parse('hello=\'kitty\'')); 33 }) 34 35 test("string with equals", function(){ 36 assert.deepEqual({foo:"hello=kitty"}, logfmt.parse('foo="hello=kitty"')); 37 }) 38 39 test("readme string parses", function(){ 40 var test_string = "foo=bar a=14 baz=\"hello kitty\" " 41 test_string += "cool%story=bro f %^asdf "; 42 test_string += "code=H12 path=/hello/user@foo.com/close"; 43 var result = logfmt.parse(test_string) 44 assert.equal( "H12", result["code"]) 45 assert.equal( "bar", result["foo"]) 46 assert.equal(14, result.a) 47 assert.equal("hello kitty", result['baz']) 48 assert.equal('bro', result['cool%story']) 49 assert.equal(true, result.f) 50 assert.equal(true, result['%^asdf']) 51 assert.equal('/hello/user@foo.com/close', result['path']) 52 }) 53 })