From 792958ac48bfb6fc758514d8cbf73c17e2a5998e Mon Sep 17 00:00:00 2001 From: chee Date: Fri, 5 May 2017 01:28:41 +0100 Subject: [PATCH] add tests for plist parsing for everything but binary --- tests.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests.js diff --git a/tests.js b/tests.js new file mode 100644 index 0000000..c4c7f2a --- /dev/null +++ b/tests.js @@ -0,0 +1,52 @@ +const test = require('tape') +const {parse} = require('.') + +test('it can parse an empty array', t => { + t.plan(1) + const plist = '()' + t.deepEqual(parse(plist), []) +}) + +test('it can parse an empty dictionary', t => { + t.plan(1) + const plist = '{}' + t.deepEqual(parse(plist), {}) +}) + +test('it wont parse nonsense', t => { + t.plan(3) + const error = /not valid/ + t.throws(() => parse('{;}'), error) + t.throws(() => parse('[2]'), error) + t.throws(() => parse('{"a" ='), error) +}) + +// test('it can parse binary', t => { +// t.plan(1) +// const plist = '(<2B>)' +// t.deepEqual(parse(plist), [47]) +// }) + +test('it can parse an array of strings', t => { + t.plan(3) + const plist = '("pineapple", "future", "sunset")' + const array = parse(plist) + t.equal(array[0], 'pineapple') + t.equal(array[1], 'future') + t.equal(array[2], 'sunset') +}) + +test('it can parse a dictionary', t => { + t.plan(2) + const plist = '{"lol" = "hello"; "phantasm" = "peter"}' + const object = parse(plist) + t.equal(object.lol, 'hello') + t.equal(object.phantasm, 'peter') +}) + +test('it can parse a string with escapes', t => { + t.plan(1) + const plist = '("she said \\"not me!\\"")' + const string = parse(plist)[0] + t.equal(string, 'she said "not me!"') +})