Skip to content

Commit

Permalink
add the CDATA test cases of 9dc10a
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNorthMemory committed Oct 3, 2018
1 parent 7e90b0f commit befa053
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions test/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,19 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns value wrapped by `CDATA` when passing {CDATA: true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<notagname><![CDATA[foo&bar 1<2]]></notagname>"
var definition = {
type: "string",
example: "foo&bar 1<2",
xml: {
CDATA: true
}
}

expect(sut(definition)).toEqual(expected)
})

it("sets first enum if provided", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>one</newtagname>"
var definition = {
Expand Down Expand Up @@ -902,6 +915,27 @@ describe("createXMLExample", function () {

expect(sut(definition)).toEqual(expected)
})

it("returns array with example values wrapped by `CDATA` when passing {CDATA: true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal><![CDATA[foo&bar]]></animal>\n\t<animal><![CDATA[1<2]]></animal>\n</animals>"
var definition = {
type: "array",
items: {
type: "string",
xml: {
CDATA: true,
name: "animal"
}
},
"example": [ "foo&bar", "1<2" ],
xml: {
wrapped: true,
name: "animals"
}
}

expect(sut(definition)).toEqual(expected)
})
})

describe("object", function () {
Expand Down Expand Up @@ -1300,5 +1334,91 @@ describe("createXMLExample", function () {

expect(sut(definition)).toEqual(expected)
})

it("returns object with example value wrapped by `CDATA` when passing {CDATA: true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bob>\n\t<foo><![CDATA[&bar]]></foo>\n\t<bar><![CDATA[<2]]></bar>\n</bob>"
var definition = {
type: "object",
properties: {
foo: {
type: "string",
xml: {
CDATA: true
}
},
bar:{
type: "string",
xml: {
CDATA: true
}
}
},
xml: {
name: "bob"
},
example: {
foo: "&bar",
bar: "<2"
}
}

expect(sut(definition)).toEqual(expected)
})

it("returns object with 2 properties those values wrapped by `CDATA` when passing {CDATA: true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bob>\n\t<foo><![CDATA[string]]></foo>\n\t<bar><![CDATA[string]]></bar>\n</bob>"
var definition = {
properties: {
foo: {
type: "string",
xml: {
CDATA: true
}
},
bar: {
type: "string",
xml: {
CDATA: true
}
}
},
xml: {
name: "bob"
}
}

expect(sut(definition)).toEqual(expected)
})

it("returns object with additional props equals `true` and those values wrapped by `CDATA` when the defs passing {CDATA: true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<additionalProp><![CDATA[Anything can be here]]></additionalProp>\n</animals>"
var definition = {
additionalProperties: true,
xml: {
name: "animals",
wrapped: true,
CDATA: true
}
}

expect(sut(definition)).toEqual(expected)
})

it("returns object with additional props those values wrapped by `CDATA` when passing {CDATA: true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<additionalProp><![CDATA[string]]></additionalProp>\n</animals>"
var definition = {
additionalProperties: {
type: "string",
xml: {
CDATA: true
}
},
xml: {
name: "animals"
}
}

expect(sut(definition)).toEqual(expected)
})
})
})

0 comments on commit befa053

Please sign in to comment.