Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for everything but binary
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"') | ||
}) |