diff --git a/test/fixtures/dot-with-nested-quotes.yml b/test/fixtures/dot-with-nested-quotes.yml new file mode 100644 index 0000000..152e465 --- /dev/null +++ b/test/fixtures/dot-with-nested-quotes.yml @@ -0,0 +1,2 @@ +foo: + "ba'r.b'az": qux diff --git a/test/fixtures/dot-with-partly-quoted-key.yml b/test/fixtures/dot-with-partly-quoted-key.yml new file mode 100644 index 0000000..faa9f3f --- /dev/null +++ b/test/fixtures/dot-with-partly-quoted-key.yml @@ -0,0 +1 @@ +foo."bar.baz".qux: Lorem ipsum diff --git a/test/fixtures/dot-with-unended-quote.yml b/test/fixtures/dot-with-unended-quote.yml new file mode 100644 index 0000000..084f666 --- /dev/null +++ b/test/fixtures/dot-with-unended-quote.yml @@ -0,0 +1,2 @@ +foo: + "bar.baz: qux diff --git a/test/specs/camlSpec.js b/test/specs/camlSpec.js index 38763bb..126d53c 100644 --- a/test/specs/camlSpec.js +++ b/test/specs/camlSpec.js @@ -38,15 +38,42 @@ describe('Caml', function () { var sanitize = readFixture('sanitize'); it('should return an array of prepocessed yaml lines', function () { - var yaml = caml.sanitize(sanitize); - assert.equal(yaml.split('\n').length, 8); - - var obj = caml.parse(yaml.split('\n')); + var obj = caml.camlize({ + dir: 'test/fixtures', + files: [ + 'sanitize' + ] + }); assert.equal("name", obj['variable.name']); assert.equal('test."variable.name"', obj.test['variable.name']); assert.equal("test.'other.variable.name'", obj.test['other.variable.name']) }); + + it('should fail for uneven quoting in keys', function () { + var fixture = readFixture('dot-with-unended-quote'); + assert.throws(function () { + caml.sanitize(fixture); + }, /Key contains incomplete quoted section/); + }); + + it('should fail when nesting quotes in keys', function () { + var fixture = readFixture('dot-with-nested-quotes'); + assert.throws(function () { + caml.sanitize(fixture); + }, /Key cannot contain nested quotes/); + }); + + it('should handle partly quoted keys correctly', function () { + var json = caml.camlize({ + dir: 'test/fixtures', + files: [ + 'dot-with-partly-quoted-key' + ] + }); + + assert.equal(json.foo['bar.baz'].qux, 'Lorem ipsum'); + }); }); describe('#parse()', function () {