Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

parseTest.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. 'use strict';
  2. // tests are adapted from https://github.com/TooTallNate/node-plist
  3. var path = require('path');
  4. var nodeunit = require('nodeunit');
  5. var bplist = require('../');
  6. module.exports = {
  7. 'iTunes Small': function (test) {
  8. var file = path.join(__dirname, "iTunes-small.bplist");
  9. var startTime1 = new Date();
  10. bplist.parseFile(file, function (err, dicts) {
  11. if (err) {
  12. throw err;
  13. }
  14. var endTime = new Date();
  15. console.log('Parsed "' + file + '" in ' + (endTime - startTime1) + 'ms');
  16. var dict = dicts[0];
  17. test.equal(dict['Application Version'], "9.0.3");
  18. test.equal(dict['Library Persistent ID'], "6F81D37F95101437");
  19. test.done();
  20. });
  21. },
  22. 'sample1': function (test) {
  23. var file = path.join(__dirname, "sample1.bplist");
  24. var startTime = new Date();
  25. bplist.parseFile(file, function (err, dicts) {
  26. if (err) {
  27. throw err;
  28. }
  29. var endTime = new Date();
  30. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  31. var dict = dicts[0];
  32. test.equal(dict['CFBundleIdentifier'], 'com.apple.dictionary.MySample');
  33. test.done();
  34. });
  35. },
  36. 'sample2': function (test) {
  37. var file = path.join(__dirname, "sample2.bplist");
  38. var startTime = new Date();
  39. bplist.parseFile(file, function (err, dicts) {
  40. if (err) {
  41. throw err;
  42. }
  43. var endTime = new Date();
  44. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  45. var dict = dicts[0];
  46. test.equal(dict['PopupMenu'][2]['Key'], "\n #import <Cocoa/Cocoa.h>\n\n#import <MacRuby/MacRuby.h>\n\nint main(int argc, char *argv[])\n{\n return macruby_main(\"rb_main.rb\", argc, argv);\n}\n");
  47. test.done();
  48. });
  49. },
  50. 'airplay': function (test) {
  51. var file = path.join(__dirname, "airplay.bplist");
  52. var startTime = new Date();
  53. bplist.parseFile(file, function (err, dicts) {
  54. if (err) {
  55. throw err;
  56. }
  57. var endTime = new Date();
  58. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  59. var dict = dicts[0];
  60. test.equal(dict['duration'], 5555.0495000000001);
  61. test.equal(dict['position'], 4.6269989039999997);
  62. test.done();
  63. });
  64. },
  65. 'utf16': function (test) {
  66. var file = path.join(__dirname, "utf16.bplist");
  67. var startTime = new Date();
  68. bplist.parseFile(file, function (err, dicts) {
  69. if (err) {
  70. throw err;
  71. }
  72. var endTime = new Date();
  73. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  74. var dict = dicts[0];
  75. test.equal(dict['CFBundleName'], 'sellStuff');
  76. test.equal(dict['CFBundleShortVersionString'], '2.6.1');
  77. test.equal(dict['NSHumanReadableCopyright'], '©2008-2012, sellStuff, Inc.');
  78. test.done();
  79. });
  80. },
  81. 'utf16chinese': function (test) {
  82. var file = path.join(__dirname, "utf16_chinese.plist");
  83. var startTime = new Date();
  84. bplist.parseFile(file, function (err, dicts) {
  85. if (err) {
  86. throw err;
  87. }
  88. var endTime = new Date();
  89. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  90. var dict = dicts[0];
  91. test.equal(dict['CFBundleName'], '天翼阅读');
  92. test.equal(dict['CFBundleDisplayName'], '天翼阅读');
  93. test.done();
  94. });
  95. },
  96. 'uid': function (test) {
  97. var file = path.join(__dirname, "uid.bplist");
  98. var startTime = new Date();
  99. bplist.parseFile(file, function (err, dicts) {
  100. if (err) {
  101. throw err;
  102. }
  103. var endTime = new Date();
  104. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  105. var dict = dicts[0];
  106. test.deepEqual(dict['$objects'][1]['NS.keys'], [{UID:2}, {UID:3}, {UID:4}]);
  107. test.deepEqual(dict['$objects'][1]['NS.objects'], [{UID: 5}, {UID:6}, {UID:7}]);
  108. test.deepEqual(dict['$top']['root'], {UID:1});
  109. test.done();
  110. });
  111. },
  112. 'int64': function (test) {
  113. var file = path.join(__dirname, "int64.bplist");
  114. var startTime = new Date();
  115. bplist.parseFile(file, function (err, dicts) {
  116. if (err) {
  117. throw err;
  118. }
  119. var endTime = new Date();
  120. console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
  121. var dict = dicts[0];
  122. test.equal(dict['zero'], '0');
  123. test.equal(dict['int64item'], '12345678901234567890');
  124. test.done();
  125. });
  126. }
  127. };