Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogarrote committed Nov 22, 2017
1 parent a010449 commit 765c1d5
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/canonical.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function toCanonical (form) {
return subType
} else {
const superType = toCanonical(type)
const res = minType(superType, subType)
const res = minType(superType, toCanonical(subType))
return toCanonical(res)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/minType.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ function minType (sup, sub) {
computed.type = superType
// 8.1. for each value `i` `elem-super` in the property `of` of `super`
// 8.1.1. we replace `i` in `of` with the output of applying this algorithm to `elem-super` and `sub`

computed.anyOf = sup.anyOf.map(elem => minType(elem, sub))

for (let restriction in restrictions) {
Expand All @@ -300,7 +301,7 @@ function minType (sup, sub) {
}

if (subType === 'union' && superType !== 'union') {
const computed = Object.assign({}, sup)
const computed = Object.assign({}, sub)
let anyOf = sub.anyOf
computed.anyOf = []
for (let i = 0; i < anyOf.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions test/canonical.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('canonicalForm()', function () {

const expForm = expandedForm(types[name], types)
const canForm = canonicalForm(expForm)

expect(canForm).to.deep.equal(forms[name])
})
})
Expand Down
51 changes: 51 additions & 0 deletions test/fixtures/canonical_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,5 +1170,56 @@ module.exports = {
}
},
'additionalProperties': true
},
UnionInheritance2: {
'type': 'union',
'anyOf': [
{
'type': 'object',
'properties': {
'a': {
'type': 'string',
'required': true,
'minLength': 5,
'maxLength': 10
}
},
'additionalProperties': true
},
{
'type': 'object',
'properties': {
'a': {
'type': 'string',
'required': true,
'minLength': 6,
'maxLength': 10
}
},
'additionalProperties': true
},
{
'type': 'object',
'properties': {
'a': {
'type': 'string',
'required': true,
'minLength': 5
}
},
'additionalProperties': true
},
{
'type': 'object',
'properties': {
'a': {
'type': 'string',
'required': true,
'minLength': 6
}
},
'additionalProperties': true
}
]
}
}
40 changes: 40 additions & 0 deletions test/fixtures/expanded_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,5 +1355,45 @@ module.exports = {
}
},
'additionalProperties': true
},
UnionInheritance2: {
'type': {
'type': 'object',
'properties': {
'a': {
'type': 'union',
'anyOf': [
{
'type': 'string',
'minLength': 2,
'maxLength': 10
},
{
'type': 'string',
'minLength': 3
}
],
'required': true
}
},
'additionalProperties': true
},
'properties': {
'a': {
'type': 'union',
'anyOf': [
{
'type': 'string',
'minLength': 5
},
{
'type': 'string',
'minLength': 6
}
],
'required': true
}
},
'additionalProperties': true
}
}
36 changes: 36 additions & 0 deletions test/fixtures/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,5 +627,41 @@ module.exports = {
minLength: 4
}
}
},
UnionInheritance2: {
type: {
type: 'object',
properties: {
'a': {
type: 'union',
anyOf: [
{
type: 'string',
minLength: 2,
maxLength: 10
},
{
type: 'string',
minLength: 3
}
]
}
}
},
properties: {
'a': {
type: 'union',
anyOf: [
{
type: 'string',
minLength: 5
},
{
type: 'string',
minLength: 6
}
]
}
}
}
}

0 comments on commit 765c1d5

Please sign in to comment.