Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harden test-cases and implementation to align with other implementations
This commit refactors and adds more tests to the `parse()` implementation to align with similar libraries's behaviour, e.g.: - https://github.com/Microsoft/node-fast-plist - https://docs.python.org/3/library/plistlib.html With the new tests a few of the tests were failing: ``` 31 passing (177ms) 10 failing 1) parse() real should throw an Error when parsing an empty real: AssertionError: Missing expected exception.. 2) parse() string should parse a self closing string: AssertionError: null === '' 3) parse() string should parse an empty string: AssertionError: null === '' 4) parse() string should parse a string with comments: AssertionError: 'a comment string' === 'a string' 5) parse() array should parse empty elements inside an array: AssertionError: [ false ] deepEqual [ '', false ] 6) parse() dict should throw if key is missing: AssertionError: Missing expected exception.. 7) parse() dict should throw if two keys follow each other: AssertionError: Missing expected exception.. 8) parse() dict should throw if value is missing: AssertionError: Missing expected exception.. 9) parse() dict should parse an empty key: AssertionError: {} deepEqual { '': '1' } 10) parse() dict should parse an empty value: AssertionError: { a: null } deepEqual { a: '' } ``` This commit also refactors the `lib/parse.js` to pass these tests. When executing the new implementation of `lib/parse.js` agains the old tests the following tests were failing: ``` 25 passing (143ms) 3 failing 1) plist parse() should parse an empty <key/> in a dictionary: AssertionError: false == true 2) plist parse() should parse an empty <key></key> in a dictionary: AssertionError: false == true 3) plist parse() should parse an empty <key></key> and <string></string> in dictionary with more data: AssertionError: { '': '', UIRequiredDeviceCapabilities: [ 'armv7' ] } deepEqual { UIRequiredDeviceCapabilities: [ 'armv7' ] } ``` As the output above shows, most of the issue are with the handling of empty strings and empty dictionary keys. Added with the new implementation are custom Errors for unexpected input, better handling of comments inside tags and a more aligned handling of empty keys/strings.
- Loading branch information