This repository was archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathparseBoolean-test.js
61 lines (47 loc) · 2.24 KB
/
parseBoolean-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { Fury } = require('fury');
const { expect } = require('../chai');
const parseBoolean = require('../../../lib/parser/parseBoolean');
const { minim: namespace } = new Fury();
const Context = require('../../../lib/context');
describe('parseBoolean', () => {
let context;
beforeEach(() => {
context = new Context(namespace);
});
it('can parse a BooleanElement with `true` value', () => {
const member = new namespace.elements.Member('required', true);
const parseResult = parseBoolean(context, 'Example Object', true, member);
expect(parseResult.length).to.equal(1);
expect(parseResult.get(0).value).to.be.instanceof(namespace.elements.Boolean);
expect(parseResult.get(0).value.toValue()).to.equal(true);
});
it('can parse a BooleanElement with `false` value', () => {
const member = new namespace.elements.Member('required', false);
const parseResult = parseBoolean(context, 'Example Object', true, member);
expect(parseResult.length).to.equal(1);
expect(parseResult.get(0).value).to.be.instanceof(namespace.elements.Boolean);
expect(parseResult.get(0).value.toValue()).to.equal(false);
});
it('returns a warning annotation when given optional element is not a BooleanElement', () => {
const value = new namespace.elements.Number(1);
const member = new namespace.elements.Member('required', value);
const parseResult = parseBoolean(context, 'Example Object', false, member);
expect(parseResult.length).to.equal(1);
const warning = parseResult.warnings.get(0);
expect(warning).to.be.instanceof(namespace.elements.Annotation);
expect(warning.toValue()).to.equal(
"'Example Object' 'required' is not a boolean"
);
});
it('returns a error annotation when given required element is not a BooleanElement', () => {
const value = new namespace.elements.Number(1);
const member = new namespace.elements.Member('required', value);
const parseResult = parseBoolean(context, 'Example Object', true, member);
expect(parseResult.length).to.equal(1);
const error = parseResult.errors.get(0);
expect(error).to.be.instanceof(namespace.elements.Annotation);
expect(error.toValue()).to.equal(
"'Example Object' 'required' is not a boolean"
);
});
});