basics.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // --------------------------------------------------------------------------------------------------------------------
  2. //
  3. // basics.js - tests for node-data2xml
  4. //
  5. // Copyright (c) 2011 Andrew Chilton - http://chilts.org/
  6. // Written by Andrew Chilton <andychilton@gmail.com>
  7. //
  8. // License: http://opensource.org/licenses/MIT
  9. //
  10. // --------------------------------------------------------------------------------------------------------------------
  11. var test = require('tape');
  12. var data2xml = require('../data2xml');
  13. // --------------------------------------------------------------------------------------------------------------------
  14. test('some simple entities', function (t) {
  15. var test1 = data2xml.entitify('<hello>');
  16. var exp1 = '&lt;hello&gt;';
  17. t.equal(test1, exp1, 'LT and GT entitified correctly');
  18. var test2 = data2xml.entitify('\'&\"');
  19. var exp2 = '&apos;&amp;&quot;';
  20. t.equal(test2, exp2, 'other entities');
  21. t.end();
  22. });
  23. test('making some elements', function (t) {
  24. var test1 = data2xml.makeStartTag('tagme');
  25. var exp1 = '<tagme>';
  26. t.equal(test1, exp1, 'simple start tag');
  27. var test2 = data2xml.makeEndTag('tagme');
  28. var exp2 = '</tagme>';
  29. t.equal(test2, exp2, 'simple end tag');
  30. var test3 = data2xml.makeStartTag('tagme', { attr : 'value' });
  31. var exp3 = '<tagme attr="value">';
  32. t.equal(test3, exp3, '1) complex start tag');
  33. var test4 = data2xml.makeStartTag('tagme', { attr : '<anothertag>' });
  34. var exp4 = '<tagme attr="&lt;anothertag&gt;">';
  35. t.equal(test4, exp4, '2) complex start tag');
  36. var test5 = data2xml.makeStartTag('tagme', { attr1 : '<anothertag>', attr2 : 'val2' });
  37. var exp5 = '<tagme attr1="&lt;anothertag&gt;" attr2="val2">';
  38. t.equal(test5, exp5, '3) complex start tag');
  39. t.end();
  40. });
  41. // --------------------------------------------------------------------------------------------------------------------