From 18751f8ec73ec067f121557d06c4777f535be839 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Mon, 1 Jul 2019 22:32:21 -0500 Subject: [PATCH] test context merge, yaml parser --- test/parser/TestYamlParser.ts | 28 ++++++++++++++++++++++++++++ test/visitor/TestContext.ts | 21 ++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/parser/TestYamlParser.ts diff --git a/test/parser/TestYamlParser.ts b/test/parser/TestYamlParser.ts new file mode 100644 index 0000000..062dd28 --- /dev/null +++ b/test/parser/TestYamlParser.ts @@ -0,0 +1,28 @@ +import { expect } from 'chai'; +import { mock } from 'sinon'; +import { YamlParser } from 'src/parser/YamlParser'; + +describe('yaml parser', () => { + describe('dump documents', () => { + it('should dump multiple documents', () => { + const parser = new YamlParser(); + const data = parser.dump({}, {}); + + expect(data).to.contain('---'); + }); + }); + + describe('parse documents', () => { + it('should parse multiple documents', () => { + const parser = new YamlParser(); + const data = parser.parse(` +foo: {} +--- +bar: {} + `); + + expect(Array.isArray(data)).to.equal(true); + expect(data.length).to.equal(2); + }); + }); +}); diff --git a/test/visitor/TestContext.ts b/test/visitor/TestContext.ts index 066800d..22d0a4b 100644 --- a/test/visitor/TestContext.ts +++ b/test/visitor/TestContext.ts @@ -1,7 +1,22 @@ import { expect } from 'chai'; +import { VisitorContext } from 'src/visitor/context'; +import { ConsoleLogger } from 'noicejs'; -describe('context', () => { - it('tests things', () => { - expect(true).to.equal(true); +describe('visitor context', () => { + it('should merge results', () => { + const firstCtx = new VisitorContext({ + coerce: false, + defaults: false, + logger: new ConsoleLogger(), + }); + + const nextCtx = firstCtx.mergeResult({ + changes: [{bar: 3}], + errors: [{foo: 2}], + }); + + expect(nextCtx).to.equal(firstCtx); + expect(nextCtx.errors.length).to.equal(1); + expect(nextCtx.changes.length).to.equal(1); }); });