/*! * typographer * Copyright(c) 2011 Eugene Kalinin * MIT Licensed */ var tp = require('../typogr') , assert = require('assert'); describe('typogr', function() { it('amp tests', function() { ['One & two', 'One & two', 'One & two'].forEach( function (val) { assert.equal(tp.amp(val), 'One & two'); }); assert.equal(tp.amp('One & two'), 'One & two'); // It won't mess up & that are already wrapped, in entities or URLs assert.equal(tp.amp('One & two'), 'One & two'); assert.equal(tp.amp('“this” & that'), '“this” & that'); // It should ignore standalone amps that are in attributes assert.equal(tp.amp('xyz'), 'xyz'); // It should ignore amps inside script tags assert.equal(tp.amp(''), ''); }); it('ord tests', function() { assert.equal(tp.ord('1st'), '1st'); assert.equal(tp.ord('2nd'), '2nd'); assert.equal(tp.ord('3rd'), '3rd'); assert.equal(tp.ord('10th'), '10th'); assert.equal(tp.ord('37th'), '37th'); assert.equal(tp.ord('1000th'), '1000th'); // Make sure it does not happen within attributes assert.equal(tp.ord('1st'), '1st'); }); it('quotes tests', function() { assert.equal(tp.initQuotes('"With primes"'), '"With primes"'); assert.equal(tp.initQuotes("'With single primes'"), '\'With single primes\''); assert.equal(tp.initQuotes('"With primes and a link"'), '"With primes and a link"'); assert.equal(tp.initQuotes('“With smartypanted quotes”'), '“With smartypanted quotes”'); assert.equal(tp.initQuotes('
In a couple of paragraphs
the paragraph number two
'), 'In a couple of paragraphs
the paragraph number two
'); assert.equal(tp.widont('Neither do PREs'), '
Neither do PREs'); assert.equal(tp.widont('
But divs with paragraphs do!
But divs with paragraphs do!
Testing with a tag at the end.
'), 'Testing with a tag at the end.
'); assert.equal(tp.widont('Testing with multiple inline tags at the end.
'), 'Testing with multiple inline tags at the end.
'); // It should also take commas into consideration assert.equal(tp.widont('Start of the paragraph ... before they get deleted-I mean, published.
'), 'Start of the paragraph ... before they get deleted-I mean, published.
'); }); it('caps tests', function() { assert.equal(tp.caps('A message from KU'), 'A message from KU'); // Uses the smartypants tokenizer to not screw with HTML or with tags it shouldn't. assert.equal(tp.caps('CAPSmore CAPS'), '
CAPSmore CAPS'); assert.equal(tp.caps('A message from 2KU2 with digits'), 'A message from 2KU2 with digits'); assert.equal(tp.caps('Dotted caps followed by spaces should never include them in the wrap D.O.T. like so.'), 'Dotted caps followed by spaces should never include them in the wrap D.O.T. like so.'); // All caps with with apostrophes in them shouldn't break. Only handles dump apostrophes though. assert.equal(tp.caps("JIMMY'S"), 'JIMMY\'S'); assert.equal(tp.caps("D.O.T.HE34TRFID"), 'D.O.T.HE34TRFID'); }); it('tokenize', function() { assert.deepEqual( tp.tokenize('
some other text
'+ 'and appendix ...'), [ { type: 'tag', txt: '' }, { type: 'text', txt: 'some ' }, { type: 'tag', txt: '' }, { type: 'text', txt: 'other' }, { type: 'tag', txt: '' }, { type: 'text', txt: ' text' }, { type: 'tag', txt: '
' }, { type: 'text', txt: ' and appendix ...' } ] ); }); it('smartEscapes', function() { assert.deepEqual( tp.smartEscapes( '\\" : \\\' : \\- : \\. : \\\\ : \\`'), '" : ' : - : . : \ : `'); }) it('smartDashes', function() { assert.deepEqual( tp.smartDashes( '-- : --- : -- : ---'), '– : — : – : —'); assert.deepEqual( tp.smartDashes( ':'), ':'); }); it('smartEllipses', function() { assert.deepEqual( tp.smartEllipses( '. ... : . . . .'), '. … : … .'); }); it('smartBackticks', function() { assert.deepEqual( tp.smartBackticks( "``Isn't this fun?''"), "“Isn't this fun?”"); }); it('smartQuotes', function() { assert.deepEqual( tp.smartQuotes( '"Isn\'t this fun?"'), '“Isn’t this fun?”'); }); it('smartypants', function() { assert.deepEqual( tp.smartypants( 'The "Green" man'), 'The “Green” man'); assert.deepEqual( tp.smartypants( '"switched off".'), '“switched off”.'); assert.deepEqual( tp.smartypants('markdown\'s popularity is growing'), 'markdown’s popularity is growing'); assert.deepEqual( tp.smartypants("I love rock 'n' roll
"), 'I love rock ’n’ roll
'); }); it('typogrify', function() { assert.deepEqual( tp.typogrify( '