index.html revision b9436848b51ee2b4f04b9217e74172c5a05ce276
273e421813f295d65aab512f508e8fb575d997d4gouldtj<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
273e421813f295d65aab512f508e8fb575d997d4gouldtj<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
273e421813f295d65aab512f508e8fb575d997d4gouldtj<script type="text/javascript" src="/build/yui/yui.js"></script>
273e421813f295d65aab512f508e8fb575d997d4gouldtj<script type="text/javascript" src="/build/dataschema/dataschema-debug.js" id="buildsrc"></script>
273e421813f295d65aab512f508e8fb575d997d4gouldtj<script type="text/javascript" src="/build/datatype/datatype-debug.js" id="buildsrc"></script>
273e421813f295d65aab512f508e8fb575d997d4gouldtj(function() {
273e421813f295d65aab512f508e8fb575d997d4gouldtj filter: "debug",
273e421813f295d65aab512f508e8fb575d997d4gouldtj useConsole: true,
273e421813f295d65aab512f508e8fb575d997d4gouldtj insertBefore: "buildsrc"
273e421813f295d65aab512f508e8fb575d997d4gouldtj }).use("console", "test", "dump", "dataschema", "datatype", function(Y) {
273e421813f295d65aab512f508e8fb575d997d4gouldtj // Set up the page
273e421813f295d65aab512f508e8fb575d997d4gouldtj var ASSERT = Y.Assert,
273e421813f295d65aab512f508e8fb575d997d4gouldtj ARRAYASSERT = Y.ArrayAssert,
273e421813f295d65aab512f508e8fb575d997d4gouldtj btnRun = Y.get("#btnRun"),
myConsole = new Y.Console().render();
btnRun.set("disabled", false);
Y.on("click", function(){
var testJSON = new Y.Test.Case({
metaFields: {top:"top", nested:"second.nested"}
data_out = Y.DataSchema.JSON.apply(schema, data_in);
resultsFields: ["name", {key:"number", parser:Y.DataType.Number.parse}, "letter"]
data_out = Y.DataSchema.JSON.apply(schema, data_in);
metaFields: {metaTotal:"response['meta-total']", metaMessage:"response['data array'][1].response.message"},
"['customer.data']['alert(\'id\')']",
position: "array.item.0",
position: "array.item.1",
data_out = Y.DataSchema.JSON.apply(schema, data_in);
ASSERT.areSame(10, data_out.results[0]["['customer.data']['alert(\'id\')']"], "Expected first id.");
ASSERT.areSame("234-5678", data_out.results[1]["['customer.data']['phone/email']"], "Expected second phone/email.");
ASSERT.areSame("Fido", data_out.results[1]["['array-pets'][0].name"], "Expected nested array item data.");
data_out = Y.DataSchema.JSON.apply(schema, data_in);
data_out = Y.DataSchema.JSON.apply(schema, data_in);
data_out = Y.DataSchema.JSON.apply(schema, data_in);
var testXML = new Y.Test.Case({
metaFields: {rootatt:{parser:Y.DataType.Number.parse, locator:"/myroot/@rootatt"}, topnode:"//top", nestedatt:"//second/@nested"}
data_in = Y.DataType.XML.parse("<myroot rootatt='5'><top>topvalue</top><second nested='nestedvalue' /><item type='foo'><name>Abc</name><rank>0</rank></item><item type='bar'><name>Def</name><rank>1</rank></item><item type='bat'><name>Ghi</name><rank>2</rank></item></myroot>"),
data_out = Y.DataSchema.XML.apply(schema, data_in);
resultsFields: [{key:"type", locator:"@type"}, {key:"rank", parser:Y.DataType.Number.parse}, "name"]
data_in = Y.DataType.XML.parse("<myroot><item type='foo'><name>Abc</name><rank>0</rank></item><item type='bar'><name>Def</name><rank>1</rank></item><item type='bat'><name>Ghi</name><rank>2</rank></item></myroot>"),
data_out = Y.DataSchema.XML.apply(schema, data_in);
metaFields: {rootatt:{parser:Y.DataType.Number.parse, locator:"/myroot/@rootatt"}, topnode:"//top", nestedatt:"//second/@nested"},
resultsFields: [{key:"type", locator:"@type"}, {key:"rank", parser:Y.DataType.Number.parse}, "name", {key:"subnameatt", locator:"subitem/name/@type"}, {key:"age", locator:"subitem/age", parser:"number"}]
data_in = Y.DataType.XML.parse("<myroot rootatt='5'><top>topvalue</top><second nested='nestedsecond' /><allitems><livehere><item type='foo'><name type='nametype0'>Abc</name><rank>0</rank><subitem><name type='subnametype0'>subABC</name><age>10</age></subitem></item><item type='bar'><name type='nametype1'>Def</name><rank>1</rank><subitem><name type='subnametype1'>subDEF</name><age>11</age></subitem></item><item type='bat'><name type='nametype2'>Ghi</name><rank>2</rank><subitem><name type='subnametype2'>subGHI</name><age>12</age></subitem></item></livehere></allitems></myroot>"),
data_out = Y.DataSchema.XML.apply(schema, data_in);
ASSERT.areSame("subnametype0", data_out.results[0].subnameatt, "Expected first subitem name attribute.");
ASSERT.areSame("subnametype2", data_out.results[2].subnameatt, "Expected last subitemnameattribute.");
resultsFields: ["type", {key:"rank", parser:Y.DataType.Number.parse}, "name"]
data_in = Y.DataType.XML.parse("<mismatch><item type='foo'><name>Abc</name><rank>1</rank></item></mismatchedtags>"),
data_out = Y.DataSchema.XML.apply(schema, data_in);
Y.Test.Runner.add(testJSON);
Y.Test.Runner.add(testXML);