time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

parseTest.js (3747B)


      1 'use strict';
      2 
      3 // tests are adapted from https://github.com/TooTallNate/node-plist
      4 
      5 const assert = require('assert');
      6 const path = require('path');
      7 const bplist = require('../');
      8 
      9 describe('bplist-parser', function () {
     10   it('iTunes Small', async function () {
     11     const file = path.join(__dirname, "iTunes-small.bplist");
     12     const startTime1 = new Date();
     13 
     14     const [dict] = await bplist.parseFile(file);
     15     const endTime = new Date();
     16     console.log('Parsed "' + file + '" in ' + (endTime - startTime1) + 'ms');
     17     assert.equal(dict['Application Version'], "9.0.3");
     18     assert.equal(dict['Library Persistent ID'], "6F81D37F95101437");
     19   });
     20 
     21   it('sample1', async function () {
     22     const file = path.join(__dirname, "sample1.bplist");
     23     const startTime = new Date();
     24 
     25     const [dict] = await bplist.parseFile(file);
     26     const endTime = new Date();
     27     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
     28 
     29     assert.equal(dict['CFBundleIdentifier'], 'com.apple.dictionary.MySample');
     30   });
     31 
     32   it('sample2', async function () {
     33     const file = path.join(__dirname, "sample2.bplist");
     34     const startTime = new Date();
     35 
     36     const [dict] = await bplist.parseFile(file);
     37     const endTime = new Date();
     38     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
     39 
     40     assert.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");
     41   });
     42 
     43   it('airplay', async function () {
     44     const file = path.join(__dirname, "airplay.bplist");
     45     const startTime = new Date();
     46 
     47     const [dict] = await bplist.parseFile(file);
     48     const endTime = new Date();
     49     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
     50 
     51     assert.equal(dict['duration'], 5555.0495000000001);
     52     assert.equal(dict['position'], 4.6269989039999997);
     53   });
     54 
     55   it('utf16', async function () {
     56     const file = path.join(__dirname, "utf16.bplist");
     57     const startTime = new Date();
     58 
     59     const [dict] = await bplist.parseFile(file);
     60     const endTime = new Date();
     61     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
     62 
     63     assert.equal(dict['CFBundleName'], 'sellStuff');
     64     assert.equal(dict['CFBundleShortVersionString'], '2.6.1');
     65     assert.equal(dict['NSHumanReadableCopyright'], '©2008-2012, sellStuff, Inc.');
     66   });
     67 
     68   it('utf16chinese', async function () {
     69     const file = path.join(__dirname, "utf16_chinese.plist");
     70     const startTime = new Date();
     71 
     72     const [dict] = await bplist.parseFile(file);
     73     const endTime = new Date();
     74     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
     75 
     76     assert.equal(dict['CFBundleName'], '天翼阅读');
     77     assert.equal(dict['CFBundleDisplayName'], '天翼阅读');
     78   });
     79 
     80   it('uid', async function () {
     81     const file = path.join(__dirname, "uid.bplist");
     82     const startTime = new Date();
     83 
     84     const [dict] = await bplist.parseFile(file);
     85     const endTime = new Date();
     86     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
     87 
     88     assert.deepEqual(dict['$objects'][1]['NS.keys'], [{UID:2}, {UID:3}, {UID:4}]);
     89     assert.deepEqual(dict['$objects'][1]['NS.objects'], [{UID: 5}, {UID:6}, {UID:7}]);
     90     assert.deepEqual(dict['$top']['root'], {UID:1});
     91   });
     92 
     93   it('int64', async function () {
     94     const file = path.join(__dirname, "int64.bplist");
     95     const startTime = new Date();
     96 
     97     const [dict] = await bplist.parseFile(file);
     98     const endTime = new Date();
     99     console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
    100 
    101     assert.equal(dict['zero'], '0');
    102     assert.equal(dict['int64item'], '12345678901234567890');
    103   });
    104 });