github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/logfmt/test/stringify_test.js (about)

     1  var logfmt = require('../logfmt'),
     2      assert = require('assert');
     3  
     4  suite('logfmt.stringify', function() {
     5    test("simple key value pairs", function(){
     6      var data = {foo: 'bar', a: 14}
     7      assert.equal("foo=bar a=14", logfmt.stringify(data))
     8    })
     9  
    10    test("true and false", function(){
    11      var data = {foo: true, bar: false}
    12      assert.equal("foo=true bar=false", logfmt.stringify(data))
    13    })
    14  
    15    test("quotes strings with spaces in them", function(){
    16      var data = {foo: "hello kitty"}
    17      assert.equal("foo=\"hello kitty\"", logfmt.stringify(data))
    18    })
    19  
    20    test("quotes strings with equals in them", function(){
    21      var data = {foo: "hello=kitty"}
    22      assert.equal("foo=\"hello=kitty\"", logfmt.stringify(data))
    23    })
    24  
    25    test("escapes quotes within strings with spaces in them", function(){
    26      var data = {foo: 'hello my "friend"'}
    27      assert.equal('foo="hello my \\"friend\\""', logfmt.stringify(data))
    28      var data = {foo: 'hello my "friend" whom I "love"'}
    29      assert.equal('foo="hello my \\"friend\\" whom I \\"love\\""', logfmt.stringify(data))
    30    })
    31  
    32    test("escapes backslahes within strings", function(){
    33      var data = {foo: 'why would you use \\LaTeX?'}
    34      assert.equal('foo="why would you use \\\\LaTeX?"', logfmt.stringify(data))
    35    })
    36  
    37    test("undefined is nothing", function(){
    38      var data = {foo: undefined}
    39      assert.equal("foo=", logfmt.stringify(data))
    40    })
    41  
    42    test("null is nothing", function(){
    43      var data = {foo: null}
    44      assert.equal("foo=", logfmt.stringify(data))
    45    })
    46  
    47    test("object with inherited properties", function(){
    48      var defaults = {foo: 42, bar: "abc"}
    49      var options = Object.create(defaults)
    50      options.foo = 13
    51      assert.equal('foo=13 bar=abc', logfmt.stringify(options));
    52    })
    53  })