From a147fd1e76b4d9789899a7291f92788469aaf8ce Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 5 Nov 2011 15:58:28 -0700 Subject: [PATCH] update tests (really need to be rewritten as proper tests) --- test_format.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/test_format.js b/test_format.js index e2c7cec..2d2c6e3 100644 --- a/test_format.js +++ b/test_format.js @@ -1,25 +1,24 @@ -var sys = require('sys') - , format = require('./format') +var format = require('./lib') + , printf = format.printf ; -format.extendNativeStrings(); -sys.puts('Testing printf:'); -'hello'.printf(); -sys.puts('(expected "hello")'); -'hello %s'.printf('sami'); -sys.puts('(expected "hello sami")'); -'b: %b\nc: %c\nd: %d\nf: %f\no: %o\ns: %s\nx: %x\nX: %X'.printf(42, 65, 42*42, 42*42*42/1000000000, 255, 'sami', 0xfeedface, 0xc0ffee); -sys.puts('(expected "b: 101010\nc: A\nd: 1764\nf: 0.000074\no: 0377\ns: sami\nx: 0xfeedface\nX: 0xC0FFEE")'); -sys.puts('(passed if the output looks ok)'); +console.log('Testing printf:'); +printf('hello'); +console.log('(expected "hello")'); +printf('hello %s', 'sami'); +console.log('(expected "hello sami")'); +printf('b: %b\nc: %c\nd: %d\nf: %f\no: %o\ns: %s\nx: %x\nX: %X', 42, 65, 42*42, 42*42*42/1000000000, 255, 'sami', 0xfeedface, 0xc0ffee); +console.log('(expected "b: 101010\nc: A\nd: 1764\nf: 0.000074\no: 0377\ns: sami\nx: 0xfeedface\nX: 0xC0FFEE")'); +console.log('(passed if the output looks ok)'); function assertEqual(a, b) { if (a !== b) throw new Error('assertion failed, ' + a + ' !== ' + b); } -sys.puts('Testing format:'); -assertEqual('hello'.format(), 'hello'); -assertEqual('hello %s'.format('sami'), 'hello sami'); -assertEqual('b: %b\nc: %c\nd: %d\nf: %f\no: %o\ns: %s\nx: %x\nX: %X'.format(42, 65, 42*42, 42*42*42/1000000000, 255, 'sami', 0xfeedface, 0xc0ffee), "b: 101010\nc: A\nd: 1764\nf: 0.000074\no: 0377\ns: sami\nx: 0xfeedface\nX: 0xC0FFEE"); -sys.puts('(pass)'); +console.log('Testing format:'); +assertEqual(format.format('hello'), 'hello'); +assertEqual(format.format('hello %s', 'sami'), 'hello sami'); +assertEqual(format.format('b: %b\nc: %c\nd: %d\nf: %f\no: %o\ns: %s\nx: %x\nX: %X', 42, 65, 42*42, 42*42*42/1000000000, 255, 'sami', 0xfeedface, 0xc0ffee), "b: 101010\nc: A\nd: 1764\nf: 0.000074\no: 0377\ns: sami\nx: 0xfeedface\nX: 0xC0FFEE"); +console.log('(pass)'); -sys.puts('all passed'); \ No newline at end of file +console.log('all passed');