text: // Generated by CoffeeScript 1.7.1
  (function() {
    var AWS, helpers, matchXML;
  
    helpers = require('../helpers');
  
    AWS = helpers.AWS;
  
    matchXML = helpers.matchXML;
  
    describe('AWS.XML.Builder', function() {
      var toXML, xmlns;
      xmlns = 'http://mockservice.com/xmlns';
      toXML = function(rules, params, options) {
        var builder;
        if (!options) {
          options = {};
        }
        options.xmlnamespace = xmlns;
        builder = new AWS.XML.Builder('Data', rules, options);
        return builder.toXML(params);
      };
      describe('toXML', function() {
        it('returns an empty element when there are no params', function() {
          return expect(toXML(null, null)).toEqual("<Data xmlns=\"" + xmlns + "\"/>");
        });
        it('wraps simple structures with location of body', function() {
          var params, rules, xml;
          rules = {
            Name: {},
            State: {}
          };
          params = {
            Name: 'abc',
            State: 'Enabled'
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Name>abc</Name>\n  <State>Enabled</State>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('orders xml members by the order they appear in the rules', function() {
          var params, rules, xml;
          rules = {
            Count: {
              type: 'integer'
            },
            State: {}
          };
          params = {
            State: 'Disabled',
            Count: 123
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Count>123</Count>\n  <State>Disabled</State>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('can serializes structures into XML', function() {
          var params, rules, xml;
          rules = {
            Name: {},
            Details: {
              type: 'structure',
              members: {
                Abc: {},
                Xyz: {}
              }
            }
          };
          params = {
            Details: {
              Xyz: 'xyz',
              Abc: 'abc'
            },
            Name: 'john'
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Name>john</Name>\n  <Details>\n    <Abc>abc</Abc>\n    <Xyz>xyz</Xyz>\n  </Details>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('serializes empty structures as empty element', function() {
          var params, rules, xml;
          rules = {
            Config: {
              type: 'structure',
              members: {
                Foo: {},
                Bar: {}
              }
            }
          };
          params = {
            Config: {}
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Config/>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        return it('does not serialize missing members', function() {
          var params, rules, xml;
          rules = {
            Config: {
              type: 'structure',
              members: {
                Foo: {},
                Bar: {}
              }
            }
          };
          params = {
            Config: {
              Foo: 'abc'
            }
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Config>\n    <Foo>abc</Foo>\n  </Config>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
      describe('lists', function() {
        it('serializes lists (default member names)', function() {
          var params, rules, xml;
          rules = {
            Aliases: {
              type: 'list',
              members: {}
            }
          };
          params = {
            Aliases: ['abc', 'mno', 'xyz']
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Aliases>\n    <member>abc</member>\n    <member>mno</member>\n    <member>xyz</member>\n  </Aliases>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('serializes lists (custom member names)', function() {
          var params, rules, xml;
          rules = {
            Aliases: {
              type: 'list',
              members: {
                name: 'Alias'
              }
            }
          };
          params = {
            Aliases: ['abc', 'mno', 'xyz']
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Aliases>\n    <Alias>abc</Alias>\n    <Alias>mno</Alias>\n    <Alias>xyz</Alias>\n  </Aliases>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('includes lists elements even if they have no members', function() {
          var params, rules, xml;
          rules = {
            Aliases: {
              type: 'list',
              members: {
                name: 'Alias'
              }
            }
          };
          params = {
            Aliases: []
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Aliases/>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        return it('serializes lists of structures', function() {
          var params, rules, xml;
          rules = {
            Points: {
              type: 'list',
              members: {
                type: 'structure',
                name: 'Point',
                members: {
                  X: {
                    type: 'float'
                  },
                  Y: {
                    type: 'float'
                  }
                }
              }
            }
          };
          params = {
            Points: [
              {
                X: 1.2,
                Y: 2.1
              }, {
                X: 3.4,
                Y: 4.3
              }
            ]
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Points>\n    <Point>\n      <X>1.2</X>\n      <Y>2.1</Y>\n    </Point>\n    <Point>\n      <X>3.4</X>\n      <Y>4.3</Y>\n    </Point>\n  </Points>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
      describe('lists', function() {
        it('serializes lists without a base wrapper', function() {
          var params, rules, xml;
          rules = {
            Aliases: {
              type: 'list',
              flattened: true,
              members: {}
            }
          };
          params = {
            Aliases: ['abc', 'mno', 'xyz']
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Aliases>abc</Aliases>\n  <Aliases>mno</Aliases>\n  <Aliases>xyz</Aliases>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('serializes lists (custom member names)', function() {
          var params, rules, xml;
          rules = {
            Aliases: {
              type: 'list',
              flattened: true,
              name: 'Alias',
              members: {}
            }
          };
          params = {
            Aliases: ['abc', 'mno', 'xyz']
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Alias>abc</Alias>\n  <Alias>mno</Alias>\n  <Alias>xyz</Alias>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('omits lists elements when no members are given', function() {
          var params, rules, xml;
          rules = {
            Aliases: {
              type: 'list',
              flattened: true,
              members: {
                name: 'Alias'
              }
            }
          };
          params = {
            Aliases: []
          };
          xml = "<Data xmlns=\"" + xmlns + "\"/>";
          return matchXML(toXML(rules, params), xml);
        });
        return it('serializes lists of structures', function() {
          var params, rules, xml;
          rules = {
            Points: {
              type: 'list',
              flattened: true,
              name: 'Point',
              members: {
                type: 'structure',
                name: 'Point',
                members: {
                  X: {
                    type: 'float'
                  },
                  Y: {
                    type: 'float'
                  }
                }
              }
            }
          };
          params = {
            Points: [
              {
                X: 1.2,
                Y: 2.1
              }, {
                X: 3.4,
                Y: 4.3
              }
            ]
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Point>\n    <X>1.2</X>\n    <Y>2.1</Y>\n  </Point>\n  <Point>\n    <X>3.4</X>\n    <Y>4.3</Y>\n  </Point>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
      describe('numbers', function() {
        it('integers', function() {
          var params, rules, xml;
          rules = {
            Count: {
              type: 'integer'
            }
          };
          params = {
            Count: 123.0
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Count>123</Count>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        return it('floats', function() {
          var params, rules, xml;
          rules = {
            Count: {
              type: 'float'
            }
          };
          params = {
            Count: 123.123
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Count>123.123</Count>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
      describe('booleans', function() {
        it('true', function() {
          var params, rules, xml;
          rules = {
            Enabled: {
              type: 'boolean'
            }
          };
          params = {
            Enabled: true
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Enabled>true</Enabled>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        return it('false', function() {
          var params, rules, xml;
          rules = {
            Enabled: {
              type: 'booleans'
            }
          };
          params = {
            Enabled: false
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Enabled>false</Enabled>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
      describe('timestamps', function() {
        var time;
        time = new Date();
        it('iso8601', function() {
          var params, rules, xml;
          rules = {
            Expires: {
              type: 'timestamp'
            }
          };
          params = {
            Expires: time
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Expires>" + (AWS.util.date.iso8601(time)) + "</Expires>\n</Data>";
          return matchXML(toXML(rules, params, {
            timestampFormat: 'iso8601'
          }), xml);
        });
        it('rfc822', function() {
          var params, rules, xml;
          rules = {
            Expires: {
              type: 'timestamp'
            }
          };
          params = {
            Expires: time
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Expires>" + (AWS.util.date.rfc822(time)) + "</Expires>\n</Data>";
          return matchXML(toXML(rules, params, {
            timestampFormat: 'rfc822'
          }), xml);
        });
        it('unix timestamp', function() {
          var params, rules, xml;
          rules = {
            Expires: {
              type: 'timestamp'
            }
          };
          params = {
            Expires: time
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Expires>" + (AWS.util.date.unixTimestamp(time)) + "</Expires>\n</Data>";
          return matchXML(toXML(rules, params, {
            timestampFormat: 'unixTimestamp'
          }), xml);
        });
        return it('follows the forat given on the shape', function() {
          var params, rules, xml;
          rules = {
            Expires: {
              type: 'timestamp',
              format: 'rfc822'
            }
          };
          params = {
            Expires: time
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Expires>" + (AWS.util.date.rfc822(time)) + "</Expires>\n</Data>";
          return matchXML(toXML(rules, params, {
            timestampFormat: 'unixTimestamp'
          }), xml);
        });
      });
      describe('xml attributes', function() {
        return it('can serialize xml attributes', function() {
          var params, rules, xml;
          rules = {
            Config: {
              type: 'structure',
              members: {
                Foo: {
                  type: 'string'
                },
                Attr: {
                  type: 'string',
                  attribute: true,
                  name: 'attr:name'
                }
              }
            }
          };
          params = {
            Config: {
              Foo: 'bar',
              Attr: 'abc'
            }
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Config attr:name=\"abc\"><Foo>bar</Foo></Config>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
      return describe('xml namespaces', function() {
        it('can apply xml namespaces on structures', function() {
          var params, rules, xml;
          rules = {
            Config: {
              type: 'structure',
              xmlns: {
                uri: 'URI'
              },
              members: {
                Foo: {
                  type: 'string'
                }
              }
            }
          };
          params = {
            Config: {
              Foo: 'bar'
            }
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Config xmlns=\"URI\"><Foo>bar</Foo></Config>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        it('applies namespace prefixes to the xmlns attribute', function() {
          var params, rules, xml;
          rules = {
            Config: {
              type: 'structure',
              xmlns: {
                prefix: 'xsi',
                uri: 'URI'
              },
              members: {
                Foo: {
                  type: 'string'
                }
              }
            }
          };
          params = {
            Config: {
              Foo: 'bar'
            }
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Config xmlns:xsi=\"URI\"><Foo>bar</Foo></Config>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
        return it('can apply namespaces to elements that have other attributes', function() {
          var params, rules, xml;
          rules = {
            Config: {
              type: 'structure',
              xmlns: {
                prefix: 'xsi',
                uri: 'URI'
              },
              members: {
                Foo: {
                  type: 'string'
                },
                Bar: {
                  type: 'string',
                  attribute: true,
                  name: 'xsi:label'
                }
              }
            }
          };
          params = {
            Config: {
              Foo: 'abc',
              Bar: 'xyz'
            }
          };
          xml = "<Data xmlns=\"" + xmlns + "\">\n  <Config xsi:label=\"xyz\" xmlns:xsi=\"URI\"><Foo>abc</Foo></Config>\n</Data>";
          return matchXML(toXML(rules, params), xml);
        });
      });
    });
  
  }).call(this);
  
  //# sourceMappingURL=builder.spec.map
  