Screw.Unit(function() { describe("Print", function() { describe('when given undefined', function() { it("returns 'undefined'", function() { expect($.print(undefined)).to(equal, 'undefined'); }); }); describe('when given null', function() { it("returns 'null'", function() { expect($.print(null)).to(equal, 'null'); }); }); describe('when given a number', function() { it("returns the string representation of the number", function() { expect($.print(1)).to(equal, '1'); expect($.print(1.01)).to(equal, '1.01'); expect($.print(-1)).to(equal, '-1'); }); }); describe('when given a boolean', function() { it("returns the string representation of the boolean", function() { expect($.print(true)).to(equal, 'true'); expect($.print(false)).to(equal, 'false'); }); }); describe('when given a string', function() { it("returns the string, quoted", function() { expect($.print('asdf')).to(equal, '"asdf"'); }); describe('when the string is longer than the [max_string] option', function() { it("returns the string, truncated", function() { expect($.print('asdf', { max_string: 3 })).to(equal, '"asd..."'); }); }); describe('when the strings has quotes or escaped characters', function() { it("returns the string, with quotes and escaped characters escaped", function() { expect($.print('as"df')).to(equal, '"as\\"df"'); expect($.print('as\tdf')).to(equal, '"as\\tdf"'); }); }); }); describe('when given a function', function() { it("returns the function's signature", function() { expect($.print(function() {})).to(match, /function\s*\(\)/); expect($.print(function foo() {})).to(match, /function\s*foo\(\)/); expect($.print(function foo(bar) {})).to(match, /function\s*foo\(bar\)/); }); }); describe('when given a RegExp', function() { it('should print the regexp', function() { expect($.print(/abc/i)).to(equal, '/abc/i'); }); }); describe('when given NaN', function() { it('should print the string "NaN"', function() { expect($.print(NaN)).to(equal, 'NaN'); }); }); describe('when given 0', function() { it('should print the string "0"', function() { expect($.print(0)).to(equal, '0'); }); }); describe('when given an element', function() { it("returns the string representation of the element", function() { expect($.print($('
').get(0))).to(equal, '