summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Faivre <jeremy.faivre@gmail.com>2012-08-03 18:22:55 +0200
committerJeremy Faivre <jeremy.faivre@gmail.com>2012-08-03 18:22:55 +0200
commitbc778908ab5aa900f0b6cf842e09bdc8d8888488 (patch)
treea5dfb8a868fed508534acb925fc3dd5fdbe3cf28
parent82faa06fbfc044ce8c99f101996ed20955670e78 (diff)
downloadyamljs-bc778908ab5aa900f0b6cf842e09bdc8d8888488.tar.gz
Updated to current version of Symfony implementation. Added jasmine tests and fixed few bugs.
See: https://bitbucket.org/minj/yaml.js/overview
-rw-r--r--README.markdown14
-rw-r--r--com/jeremyfa/yaml/Yaml.js118
-rw-r--r--com/jeremyfa/yaml/YamlDumper.js30
-rw-r--r--com/jeremyfa/yaml/YamlEscaper.js89
-rw-r--r--com/jeremyfa/yaml/YamlInline.js165
-rw-r--r--com/jeremyfa/yaml/YamlParseException.js140
-rw-r--r--com/jeremyfa/yaml/YamlParser.js189
-rw-r--r--com/jeremyfa/yaml/YamlUnescaper.js108
-rw-r--r--demo.html98
-rw-r--r--libs/jasmine-1.2.0/MIT.LICENSE20
-rw-r--r--libs/jasmine-1.2.0/YamlSpec.js22
-rw-r--r--libs/jasmine-1.2.0/YamlTests.js689
-rw-r--r--libs/jasmine-1.2.0/jasmine-html.js616
-rw-r--r--libs/jasmine-1.2.0/jasmine.css81
-rw-r--r--libs/jasmine-1.2.0/jasmine.js2529
-rwxr-xr-xmake14
-rw-r--r--tests.html51
-rw-r--r--yaml.js23
18 files changed, 4723 insertions, 273 deletions
diff --git a/README.markdown b/README.markdown
index cf30883..9e5fb6a 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,9 +1,9 @@
yaml.js
=======
-Standalone JavaScript YAML Parser & Encoder. You don't need any javascript framework to use it.
+Standalone JavaScript YAML 1.2 Parser & Encoder. You don't need any javascript framework to use it.
-Mainly inspired from [sfYaml Library](http://components.symfony-project.org/yaml/) (part of the php Symfony components).
+Mainly inspired from [Yaml Component](https://github.com/symfony/Yaml) (part of the php framework Symfony).
How to use
----------
@@ -29,4 +29,12 @@ Load yaml file (asynchronous):
Dump native object into yaml string:
- yamlString = YAML.encode(nativeObject); \ No newline at end of file
+ yamlString = YAML.encode(nativeObject[, inline /* @integer depth to start using inline notation at */ ]);
+
+Important
+---------
+
+Symfony dropped support for YAML 1.1 spec. This means that `yes`, `no` and similar no longer convert to their *boolean* equivalents.
+
+The internal `Yaml().load()` and `Yaml().loadFile()` methods renamed to `Yaml().parse()` and `Yaml().parseFile()` respectively. Exceptions replaced with `YamlParseException` object.
+
diff --git a/com/jeremyfa/yaml/Yaml.js b/com/jeremyfa/yaml/Yaml.js
index 3f9dfec..0c5c11b 100644
--- a/com/jeremyfa/yaml/Yaml.js
+++ b/com/jeremyfa/yaml/Yaml.js
@@ -1,107 +1,80 @@
/**
- * sfYaml offers convenience methods to load and dump YAML.
+ * Yaml offers convenience methods to parse and dump YAML.
*
- * @package symfony
- * @subpackage yaml
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- * @version SVN: $Id: sfYaml.class.php 8988 2008-05-15 20:24:26Z fabien $
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
*/
var Yaml = function(){};
Yaml.prototype =
{
- spec: '1.2',
-
- /**
- * Sets the YAML specification version to use.
- *
- * @param string version The YAML specification version
- */
- setSpecVersion: function(version /* String */)
- {
- if ( version != '1.1' && version != '1.2' )
- {
- throw new InvalidArgumentException('Version '+version+' of the YAML specifications is not supported');
- }
-
- this.spec = version;
- },
-
- /**
- * Gets the YAML specification version to use.
- *
- * @return string The YAML specification version
- */
- getSpecVersion: function()
- {
- return this.spec;
- },
/**
- * Loads YAML into a JS representation.
+ * Parses YAML into a JS representation.
*
- * The load method, when supplied with a YAML stream (file),
+ * The parse method, when supplied with a YAML stream (file),
* will do its best to convert YAML in a file into a JS representation.
*
* Usage:
* <code>
- * obj = yaml.loadFile('config.yml');
+ * obj = yaml.parseFile('config.yml');
* </code>
*
- * @param string input Path of YAML file or string containing YAML
+ * @param string input Path of YAML file
*
* @return array The YAML converted to a JS representation
*
- * @throws InvalidArgumentException If the YAML is not valid
+ * @throws YamlParseException If the YAML is not valid
*/
- loadFile: function(file /* String */, callback /* Function */)
+ parseFile: function(file /* String */, callback /* Function */)
{
if ( callback == undefined )
{
- input = this.getFileContents(file);
- return this.load(input);
+ var input = this.getFileContents(file);
+ var ret = null;
+ try
+ {
+ ret = this.parse(input);
+ }
+ catch ( e )
+ {
+ if ( e instanceof YamlParseException ) {
+ e.setParsedFile(file);
+ }
+ throw e;
+ }
+ return ret;
}
this.getFileContents(file, function(data)
{
- callback(new Yaml().load(data));
+ callback(new Yaml().parse(data));
});
},
/**
- * Loads YAML into a JS representation.
+ * Parses YAML into a JS representation.
*
- * The load method, when supplied with a YAML stream (string),
- * will do its best to convert YAML in a file into a JS representation.
+ * The parse method, when supplied with a YAML stream (string),
+ * will do its best to convert YAML into a JS representation.
*
* Usage:
* <code>
- * obj = yaml.load(...);
+ * obj = yaml.parse(...);
* </code>
*
- * @param string input Path of YAML file or string containing YAML
+ * @param string input string containing YAML
*
* @return array The YAML converted to a JS representation
*
- * @throws InvalidArgumentException If the YAML is not valid
+ * @throws YamlParseException If the YAML is not valid
*/
- load: function(input /* String */)
+ parse: function(input /* String */)
{
var yaml = new YamlParser();
- var ret = null;
- try
- {
- ret = yaml.parse(input);
- }
- catch ( e )
- {
- if ( e.name != undefined && e.name.toString == "TypeError" ) throw e;
- throw 'Syntax error: '+e.message;
- //throw new InvalidArgumentException(e.name+' ('+e.lineNumber+') '+e.message);
- }
-
- return ret;
+ return yaml.parse(input);
},
/**
@@ -114,12 +87,14 @@ Yaml.prototype =
* @param integer inline The level where you switch to inline YAML
*
* @return string A YAML string representing the original JS representation
- */
+ *
+ * @api
+ */
dump: function(array, inline)
{
if ( inline == undefined ) inline = 2;
- yaml = new YamlDumper();
+ var yaml = new YamlDumper();
return yaml.dump(array, inline);
},
@@ -179,25 +154,22 @@ Yaml.prototype =
var YAML =
{
- encode: function(input)
+ /*
+ * @param integer inline The level where you switch to inline YAML
+ */
+
+ encode: function(input, inline)
{
- return new Yaml().dump(input);
+ return new Yaml().dump(input, inline);
},
decode: function(input)
{
- return new Yaml().load(input);
+ return new Yaml().parse(input);
},
load: function(file, callback)
{
- return new Yaml().loadFile(file, callback);
+ return new Yaml().parseFile(file, callback);
}
};
-
-if ( typeof(InvalidArgumentException) == 'undefined' )
- InvalidArgumentException = function(message)
- {
- this.name = 'InvalidArgumentException';
- this.message = message;
- };
diff --git a/com/jeremyfa/yaml/YamlDumper.js b/com/jeremyfa/yaml/YamlDumper.js
index 553cc5d..ffc4e7d 100644
--- a/com/jeremyfa/yaml/YamlDumper.js
+++ b/com/jeremyfa/yaml/YamlDumper.js
@@ -2,22 +2,19 @@
/**
* YamlDumper dumps JS variables to YAML strings.
*
- * @package symfony
- * @subpackage yaml
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- * @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
+ * @author Fabien Potencier <fabien@symfony.com>
*/
-YamlDumper = function(){};
+var YamlDumper = function(){};
YamlDumper.prototype =
{
/**
- * Dumps a PHP value to YAML.
+ * Dumps a JS value to YAML.
*
- * @param mixed $input The PHP value
- * @param integer $inline The level where you switch to inline YAML
- * @param integer $indent The level o indentation indentation (used internally)
+ * @param mixed input The JS value
+ * @param integer inline The level where you switch to inline YAML
+ * @param integer indent The level o indentation indentation (used internally)
*
- * @return string The YAML representation of the PHP value
+ * @return string The YAML representation of the JS value
*/
dump: function(input, inline, indent)
{
@@ -63,17 +60,24 @@ YamlDumper.prototype =
var i;
var result = '';
for ( i = 0; i < count; i++ ) result += str;
- return str;
+ return result;
},
isObject: function(input)
{
- return typeof(input) == 'object' && this.isDefined(input);
+ return this.isDefined(input) && typeof(input) == 'object';
},
isEmpty: function(input)
{
- return input == undefined || input == null || input == '' || input == 0 || input == "0" || input == false;
+ var ret = input == undefined || input == null || input == '' || input == 0 || input == "0" || input == false;
+ if ( !ret && typeof(input) == "object" && !(input instanceof Array)){
+ var propCount = 0;
+ for ( var key in input )
+ if ( input.hasOwnProperty(key) ) propCount++;
+ ret = !propCount;
+ }
+ return ret;
},
isDefined: function(input)
diff --git a/com/jeremyfa/yaml/YamlEscaper.js b/com/jeremyfa/yaml/YamlEscaper.js
new file mode 100644
index 0000000..8714c51
--- /dev/null
+++ b/com/jeremyfa/yaml/YamlEscaper.js
@@ -0,0 +1,89 @@
+/**
+ * YamlEscaper encapsulates escaping rules for single and double-quoted
+ * YAML strings.
+ *
+ * @author Matthew Lewinski <matthew@lewinski.org>
+ */
+YamlEscaper = function(){};
+YamlEscaper.prototype =
+{
+ /**
+ * Determines if a JS value would require double quoting in YAML.
+ *
+ * @param string value A JS value
+ *
+ * @return Boolean True if the value would require double quotes.
+ */
+ requiresDoubleQuoting: function(value)
+ {
+ return new RegExp(YamlEscaper.REGEX_CHARACTER_TO_ESCAPE).test(value);
+ },
+
+ /**
+ * Escapes and surrounds a JS value with double quotes.
+ *
+ * @param string value A JS value
+ *
+ * @return string The quoted, escaped string
+ */
+ escapeWithDoubleQuotes: function(value)
+ {
+ value = value + '';
+ var len = YamlEscaper.escapees.length;
+ var maxlen = YamlEscaper.escaped.length;
+ var esc = YamlEscaper.escaped;
+ for (var i = 0; i < len; ++i)
+ if ( i >= maxlen ) esc.push('');
+
+ var ret = '';
+ ret = value.replace(new RegExp(YamlEscaper.escapees.join('|'),'g'), function(str){
+ for(var i = 0; i < len; ++i){
+ if( str == YamlEscaper.escapees[i] )
+ return esc[i];
+ }
+ });
+ return '"' + ret + '"';
+ },
+
+ /**
+ * Determines if a JS value would require single quoting in YAML.
+ *
+ * @param string value A JS value
+ *
+ * @return Boolean True if the value would require single quotes.
+ */
+ requiresSingleQuoting: function(value)
+ {
+ return /[\s'":{}[\],&*#?]|^[-?|<>=!%@`]/.test(value);
+ },
+
+ /**
+ * Escapes and surrounds a JS value with single quotes.
+ *
+ * @param string value A JS value
+ *
+ * @return string The quoted, escaped string
+ */
+ escapeWithSingleQuotes : function(value)
+ {
+ return "'" + value.replace(/'/g, "''") + "'";
+ }
+};
+
+// Characters that would cause a dumped string to require double quoting.
+YamlEscaper.REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9";
+
+// Mapping arrays for escaping a double quoted string. The backslash is
+// first to ensure proper escaping.
+YamlEscaper.escapees = ['\\\\', '\\"', '"',
+ "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
+ "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f",
+ "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
+ "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
+ "\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9"];
+YamlEscaper.escaped = ['\\"', '\\\\', '\\"',
+ "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a",
+ "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f",
+ "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17",
+ "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f",
+ "\\N", "\\_", "\\L", "\\P"];
diff --git a/com/jeremyfa/yaml/YamlInline.js b/com/jeremyfa/yaml/YamlInline.js
index 2752b8e..a024385 100644
--- a/com/jeremyfa/yaml/YamlInline.js
+++ b/com/jeremyfa/yaml/YamlInline.js
@@ -14,7 +14,7 @@ YamlInline.prototype =
*
* @return object A JS object representing the YAML string
*/
- load: function(value)
+ parse: function(value)
{
var result = null;
value = this.trim(value);
@@ -34,6 +34,11 @@ YamlInline.prototype =
break;
default:
result = this.parseScalar(value);
+
+ // some comment can end the scalar
+ if ( value.substr(this.i).replace(/^\s+#.*$/, '') ) {
+ throw new YamlParseException('Unexpected characters near "'+value.substr(this.i)+'".');
+ }
}
return result;
@@ -48,47 +53,30 @@ YamlInline.prototype =
*/
dump: function(value)
{
- var trueValues;
- var falseValues;
-
- var yaml = new Yaml();
-
- if ( '1.1' == yaml.getSpecVersion() )
- {
- trueValues = ['true', 'on', '+', 'yes', 'y'];
- falseValues = ['false', 'off', '-', 'no', 'n'];
- }
- else
- {
- trueValues = ['true'];
- falseValues = ['false'];
- }
-
- if ( typeof(value) == 'object' && null != value )
- return this.dumpObject(value);
if ( undefined == value || null == value )
- return 'null';
+ return 'null';
+ if ( value instanceof Date)
+ return value.toISOString();
+ if ( typeof(value) == 'object')
+ return this.dumpObject(value);
if ( typeof(value) == 'boolean' )
return value ? 'true' : 'false';
- if ( /^\d+/.test(value) )
+ if ( /^\d+$/.test(value) )
return typeof(value) == 'string' ? "'"+value+"'" : parseInt(value);
if ( this.isNumeric(value) )
return typeof(value) == 'string' ? "'"+value+"'" : parseFloat(value);
if ( typeof(value) == 'number' )
return value == Infinity ? '.Inf' : ( value == -Infinity ? '-.Inf' : ( isNaN(value) ? '.NAN' : value ) );
- if ( (value+'').indexOf("\n") != -1 || (value+'').indexOf("\r") != -1 )
- return '"'+value.split('"').join('\\"').split("\n").join('\\n').split("\r").join('\\r')+'"';
- if ( ( /[\s\'"\:\{\}\[\],&\*\#\?]/.test(value) ) || ( /^[-?|<>=!%@`]/.test(value) ) )
- return "'"+value.split('\'').join('\'\'')+"'";
+ var yaml = new YamlEscaper();
+ if ( yaml.requiresDoubleQuoting(value) )
+ return yaml.escapeWithDoubleQuotes(value);
+ if ( yaml.requiresSingleQuoting(value) )
+ return yaml.escapeWithSingleQuotes(value);
if ( '' == value )
- return "''";
+ return "";
if ( this.getTimestampRegex().test(value) )
return "'"+value+"'";
- if ( this.inArray(value.toLowerCase(), trueValues) )
- return "'"+value+"'";
- if ( this.inArray(value.toLowerCase(), falseValues) )
- return "'"+value+"'";
- if ( this.inArray(value.toLowerCase(), ['null','~']) )
+ if ( this.inArray(value.toLowerCase(), ['null','~','true','false']) )
return "'"+value+"'";
// default
return value;
@@ -138,11 +126,13 @@ YamlInline.prototype =
*
* @param scalar scalar
* @param string delimiters
- * @param object stringDelimiter
+ * @param object stringDelimiters
* @param integer i
* @param boolean evaluate
*
* @return string A YAML string
+ *
+ * @throws YamlParseException When malformed inline YAML string is parsed
*/
parseScalar: function(scalar, delimiters, stringDelimiters, i, evaluate)
{
@@ -153,13 +143,19 @@ YamlInline.prototype =
var output = null;
var pos = null;
- var match = null;
+ var matches = null;
if ( this.inArray(scalar[i], stringDelimiters) )
{
// quoted scalar
output = this.parseQuotedScalar(scalar, i);
i = this.i;
+ if (null !== delimiters) {
+ var tmp = scalar.substr(i).replace(/^\s+/, '');
+ if (!this.inArray(tmp.charAt(0), delimiters)) {
+ throw new YamlParseException('Unexpected characters ('+scalar.substr(i)+').');
+ }
+ }
}
else
{
@@ -177,14 +173,14 @@ YamlInline.prototype =
output = output.substr(0, pos).replace(/\s+$/g,'');
}
}
- else if ( match = new RegExp('^(.+?)('+delimiters.join('|')+')').exec((scalar+'').substring(i)) )
+ else if ( matches = new RegExp('^(.+?)('+delimiters.join('|')+')').exec((scalar+'').substring(i)) )
{
- output = match[1];
+ output = matches[1];
i += output.length;
}
else
{
- throw new InvalidArgumentException('Malformed inline YAML string ('+scalar+').');
+ throw new YamlParseException('Malformed inline YAML string ('+scalar+').');
}
output = evaluate ? this.evaluateScalar(output) : output;
}
@@ -197,36 +193,37 @@ YamlInline.prototype =
/**
* Parses a quoted scalar to YAML.
*
- * @param string $scalar
- * @param integer $i
+ * @param string scalar
+ * @param integer i
*
* @return string A YAML string
+ *
+ * @throws YamlParseException When malformed inline YAML string is parsed
*/
parseQuotedScalar: function(scalar, i)
{
- var match = null;
- if ( !(match = new RegExp('^'+YamlInline.REGEX_QUOTED_STRING).exec((scalar+'').substring(i))) )
+ var matches = null;
+ //var item = /^(.*?)['"]\s*(?:[,:]|[}\]]\s*,)/.exec((scalar+'').substring(i))[1];
+
+ if ( !(matches = new RegExp('^'+YamlInline.REGEX_QUOTED_STRING).exec((scalar+'').substring(i))) )
{
- throw new InvalidArgumentException('Malformed inline YAML string ('+(scalar+'').substring(i)+').');
+ throw new YamlParseException('Malformed inline YAML string ('+(scalar+'').substring(i)+').');
}
- var output = match[0].substr(1, match[0].length - 2);
+ var output = matches[0].substr(1, matches[0].length - 2);
+
+ var unescaper = new YamlUnescaper();
if ( '"' == (scalar+'').charAt(i) )
{
- // evaluate the string
- output = output
- .split('\\"').join('"')
- .split('\\n').join("\n")
- .split('\\r').join("\r");
+ output = unescaper.unescapeDoubleQuotedString(output);
}
else
{
- // unescape '
- output = output.split('\'\'').join('\'');
+ output = unescaper.unescapeSingleQuotedString(output);
}
- i += match[0].length;
+ i += matches[0].length;
this.i = i;
return output;
@@ -239,6 +236,8 @@ YamlInline.prototype =
* @param integer i
*
* @return string A YAML string
+ *
+ * @throws YamlParseException When malformed inline YAML string is parsed
*/
parseSequence: function(sequence, i)
{
@@ -283,7 +282,7 @@ YamlInline.prototype =
}
catch ( e )
{
- if ( !(e instanceof InvalidArgumentException ) ) throw e;
+ if ( !(e instanceof YamlParseException ) ) throw e;
// no, it's not
}
}
@@ -296,7 +295,7 @@ YamlInline.prototype =
i++;
}
- throw new InvalidArgumentException('Malformed inline YAML string '+sequence);
+ throw new YamlParseException('Malformed inline YAML string "'+sequence+'"');
},
/**
@@ -306,6 +305,8 @@ YamlInline.prototype =
* @param integer i
*
* @return string A YAML string
+ *
+ * @throws YamlParseException When malformed inline YAML string is parsed
*/
parseMapping: function(mapping, i)
{
@@ -379,7 +380,7 @@ YamlInline.prototype =
if ( doContinue ) continue;
}
- throw new InvalidArgumentException('Malformed inline YAML string '+mapping);
+ throw new YamlParseException('Malformed inline YAML string "'+mapping+'"');
},
/**
@@ -393,22 +394,6 @@ YamlInline.prototype =
{
scalar = this.trim(scalar);
- var trueValues;
- var falseValues;
-
- var yaml = new Yaml();
-
- if ( '1.1' == yaml.getSpecVersion() )
- {
- trueValues = ['true', 'on', '+', 'yes', 'y'];
- falseValues = ['false', 'off', '-', 'no', 'n'];
- }
- else
- {
- trueValues = ['true'];
- falseValues = ['false'];
- }
-
var raw = null;
var cast = null;
@@ -416,22 +401,22 @@ YamlInline.prototype =
( '' == scalar ) ||
( '~' == scalar ) )
return null;
- if ( (scalar+'').indexOf('!str') != -1 )
+ if ( (scalar+'').indexOf('!str ') == 0 )
return (''+scalar).substring(5);
- if ( (scalar+'').indexOf('! ') != -1 )
- return parseInt(this.parseScalar((scalar+'').substring(2)));
- if ( /^\d+/.test(scalar) )
+ if ( (scalar+'').indexOf('! ') == 0 )
+ return parseInt(this.parseScalar((scalar+'').substr(2)));
+ if ( /^\d+$/.test(scalar) )
{
raw = scalar;
cast = parseInt(scalar);
return '0' == scalar.charAt(0) ? this.octdec(scalar) : (( ''+raw == ''+cast ) ? cast : raw);
}
- if ( this.inArray(scalar.toLowerCase(), trueValues) )
+ if ( 'true' == (scalar+'').toLowerCase() )
return true;
- if ( this.inArray(scalar.toLowerCase(), falseValues) )
+ if ( 'false' == (scalar+'').toLowerCase() )
return false;
if ( this.isNumeric(scalar) )
- return '0x' == (scalar+'').substr(0, 2) ? hexdec($scalar) : floatval($scalar);
+ return '0x' == (scalar+'').substr(0, 2) ? this.hexdec(scalar) : parseFloat(scalar);
if ( scalar.toLowerCase() == '.inf' )
return Infinity;
if ( scalar.toLowerCase() == '.nan' )
@@ -441,11 +426,16 @@ YamlInline.prototype =
if ( /^(-|\+)?[0-9,]+(\.[0-9]+)?$/.test(scalar) )
return parseFloat(scalar.split(',').join(''));
if ( this.getTimestampRegex().test(scalar) )
- return this.strtodate(scalar);
+ return new Date(this.strtotime(scalar));
//else
return ''+scalar;
},
+ /**
+ * Gets a regex that matches an unix timestamp
+ *
+ * @return string The regular expression
+ */
getTimestampRegex: function()
{
return new RegExp('^'+
@@ -502,11 +492,11 @@ YamlInline.prototype =
{
var len = tab.length;
if (typeof fun != "function")
- throw new InvalidArgumentException("fun is not a function");
+ throw new YamlParseException("fun is not a function");
// no value to return if no initial value and an empty array
if (len == 0 && arguments.length == 1)
- throw new InvalidArgumentException("empty array");
+ throw new YamlParseException("empty array");
var i = 0;
if (arguments.length >= 2)
@@ -525,7 +515,7 @@ YamlInline.prototype =
// if array contains no values, no initial value to return
if (++i >= len)
- throw new InvalidArgumentException("no initial value to return");
+ throw new YamlParseException("no initial value to return");
}
while (true);
}
@@ -551,18 +541,17 @@ YamlInline.prototype =
return parseInt((input+'').replace(/[^a-f0-9]/gi, ''), 16);
},
- strtodate: function(input)
- {
- var date = new Date();
- date.setTime(this.strtotime(input, new Date().getTime()));
- return date;
- },
-
/**
* @see http://phpjs.org/functions/strtotime
+ * @note we need timestamp with msecs so /1000 removed
+ * @note original contained binary | 0 (wtf?!) everywhere, which messes everything up
*/
- strtotime: function(h,c){var f,g,l,k="",d="";k=h;k=k.replace(/\s{2,}|^\s|\s$/g," ");k=k.replace(/[\t\r\n]/g,"");if(k=="now"){return(new Date()).getTime()/1000}else{if(!isNaN(d=Date.parse(k))){return(d/1000)}else{if(c){c=new Date(c*1000)}else{c=new Date()}}}k=k.toLowerCase();var e={day:{sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},mon:{jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11}};var a=this.strtotime;var b=function(i){var p=(i[2]&&i[2]=="ago");var o=(o=i[0]=="last"?-1:1)*(p?-1:1);switch(i[0]){case"last":case"next":switch(i[1].substring(0,3)){case"yea":c.setFullYear(c.getFullYear()+o);break;case"mon":c.setMonth(c.getMonth()+o);break;case"wee":c.setDate(c.getDate()+(o*7));break;case"day":c.setDate(c.getDate()+o);break;case"hou":c.setHours(c.getHours()+o);break;case"min":c.setMinutes(c.getMinutes()+o);break;case"sec":c.setSeconds(c.getSeconds()+o);break;default:var n;if(typeof(n=e.day[i[1].substring(0,3)])!="undefined"){var q=n-c.getDay();if(q==0){q=7*o}else{if(q>0){if(i[0]=="last"){q-=7}}else{if(i[0]=="next"){q+=7}}}c.setDate(c.getDate()+q)}}break;default:if(/\d+/.test(i[0])){o*=parseInt(i[0],10);switch(i[1].substring(0,3)){case"yea":c.setFullYear(c.getFullYear()+o);break;case"mon":c.setMonth(c.getMonth()+o);break;case"wee":c.setDate(c.getDate()+(o*7));break;case"day":c.setDate(c.getDate()+o);break;case"hou":c.setHours(c.getHours()+o);break;case"min":c.setMinutes(c.getMinutes()+o);break;case"sec":c.setSeconds(c.getSeconds()+o);break}}else{return false}break}return true};g=k.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(g!=null){if(!g[2]){g[2]="00:00:00"}else{if(!g[3]){g[2]+=":00"}}l=g[1].split(/-/g);for(f in e.mon){if(e.mon[f]==l[1]-1){l[1]=f}}l[0]=parseInt(l[0],10);l[0]=(l[0]>=0&&l[0]<=69)?"20"+(l[0]<10?"0"+l[0]:l[0]+""):(l[0]>=70&&l[0]<=99)?"19"+l[0]:l[0]+"";return parseInt(a(l[2]+" "+l[1]+" "+l[0]+" "+g[2])+(g[4]?g[4]/1000:""),10)}var j="([+-]?\\d+\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)|(last|next)\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))(\\sago)?";g=k.match(new RegExp(j,"gi"));if(g==null){return false}for(f=0;f<g.length;f++){if(!b(g[f].split(" "))){return false}}return(c.getTime()/1000)}
+ strtotime: function (h,b){var f,c,g,k,d="";h=(h+"").replace(/\s{2,}|^\s|\s$/g," ").replace(/[\t\r\n]/g,"");if(h==="now"){return b===null||isNaN(b)?new Date().getTime()||0:b||0}else{if(!isNaN(d=Date.parse(h))){return d||0}else{if(b){b=new Date(b)}else{b=new Date()}}}h=h.toLowerCase();var e={day:{sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},mon:["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]};var a=function(i){var o=(i[2]&&i[2]==="ago");var n=(n=i[0]==="last"?-1:1)*(o?-1:1);switch(i[0]){case"last":case"next":switch(i[1].substring(0,3)){case"yea":b.setFullYear(b.getFullYear()+n);break;case"wee":b.setDate(b.getDate()+(n*7));break;case"day":b.setDate(b.getDate()+n);break;case"hou":b.setHours(b.getHours()+n);break;case"min":b.setMinutes(b.getMinutes()+n);break;case"sec":b.setSeconds(b.getSeconds()+n);break;case"mon":if(i[1]==="month"){b.setMonth(b.getMonth()+n);break}default:var l=e.day[i[1].substring(0,3)];if(typeof l!=="undefined"){var p=l-b.getDay();if(p===0){p=7*n}else{if(p>0){if(i[0]==="last"){p-=7}}else{if(i[0]==="next"){p+=7}}}b.setDate(b.getDate()+p);b.setHours(0,0,0,0)}}break;default:if(/\d+/.test(i[0])){n*=parseInt(i[0],10);switch(i[1].substring(0,3)){case"yea":b.setFullYear(b.getFullYear()+n);break;case"mon":b.setMonth(b.getMonth()+n);break;case"wee":b.setDate(b.getDate()+(n*7));break;case"day":b.setDate(b.getDate()+n);break;case"hou":b.setHours(b.getHours()+n);break;case"min":b.setMinutes(b.getMinutes()+n);break;case"sec":b.setSeconds(b.getSeconds()+n);break}}else{return false}break}return true};g=h.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(g!==null){if(!g[2]){g[2]="00:00:00"}else{if(!g[3]){g[2]+=":00"}}k=g[1].split(/-/g);k[1]=e.mon[k[1]-1]||k[1];k[0]=+k[0];k[0]=(k[0]>=0&&k[0]<=69)?"20"+(k[0]<10?"0"+k[0]:k[0]+""):(k[0]>=70&&k[0]<=99)?"19"+k[0]:k[0]+"";return parseInt(this.strtotime(k[2]+" "+k[1]+" "+k[0]+" "+g[2])+(g[4]?g[4]:""),10)}var j="([+-]?\\d+\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)|(last|next)\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))(\\sago)?";g=h.match(new RegExp(j,"gi"));if(g===null){return false}for(f=0,c=g.length;f<c;f++){if(!a(g[f].split(" "))){return false}}return b.getTime()||0}
+
};
+/*
+ * @note uses only non-capturing sub-patterns (unlike PHP original)
+ */
YamlInline.REGEX_QUOTED_STRING = '(?:"(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\']*(?:\'\'[^\']*)*)\')';
diff --git a/com/jeremyfa/yaml/YamlParseException.js b/com/jeremyfa/yaml/YamlParseException.js
new file mode 100644
index 0000000..04fddf3
--- /dev/null
+++ b/com/jeremyfa/yaml/YamlParseException.js
@@ -0,0 +1,140 @@
+/**
+ * Exception class thrown when an error occurs during parsing.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
+ */
+
+/**
+ * Constructor.
+ *
+ * @param string message The error message
+ * @param integer parsedLine The line where the error occurred
+ * @param integer snippet The snippet of code near the problem
+ * @param string parsedFile The file name where the error occurred
+ */
+
+var YamlParseException = function(message, parsedLine, snippet, parsedFile){
+
+ this.rawMessage = message;
+ this.parsedLine = (parsedLine !== undefined) ? parsedLine : -1;
+ this.snippet = (snippet !== undefined) ? snippet : null;
+ this.parsedFile = (parsedFile !== undefined) ? parsedFile : null;
+
+ this.updateRepr();
+
+ this.message = message;
+
+};
+YamlParseException.prototype =
+{
+
+ name: 'YamlParseException',
+ message: null,
+
+ parsedFile: null,
+ parsedLine: -1,
+ snippet: null,
+ rawMessage: null,
+
+ isDefined: function(input)
+ {
+ return input != undefined && input != null;
+ },
+
+ /**
+ * Gets the snippet of code near the error.
+ *
+ * @return string The snippet of code
+ */
+ getSnippet: function()
+ {
+ return this.snippet;
+ },
+
+ /**
+ * Sets the snippet of code near the error.
+ *
+ * @param string snippet The code snippet
+ */
+ setSnippet: function(snippet)
+ {
+ this.snippet = snippet;
+
+ this.updateRepr();
+ },
+
+ /**
+ * Gets the filename where the error occurred.
+ *
+ * This method returns null if a string is parsed.
+ *
+ * @return string The filename
+ */
+ getParsedFile: function()
+ {
+ return this.parsedFile;
+ },
+
+ /**
+ * Sets the filename where the error occurred.
+ *
+ * @param string parsedFile The filename
+ */
+ setParsedFile: function(parsedFile)
+ {
+ this.parsedFile = parsedFile;
+
+ this.updateRepr();
+ },
+
+ /**
+ * Gets the line where the error occurred.
+ *
+ * @return integer The file line
+ */
+ getParsedLine: function()
+ {
+ return this.parsedLine;
+ },
+
+ /**
+ * Sets the line where the error occurred.
+ *
+ * @param integer parsedLine The file line
+ */
+ setParsedLine: function(parsedLine)
+ {
+ this.parsedLine = parsedLine;
+
+ this.updateRepr();
+ },
+
+ updateRepr: function()
+ {
+ this.message = this.rawMessage;
+
+ dot = false;
+ if ('.' === this.message.charAt(this.message.length - 1)) {
+ this.message = this.message.substring(0, this.message.length - 1);
+ dot = true;
+ }
+
+ if (null !== this.parsedFile) {
+ this.message += ' in ' + JSON.stringify(this.parsedFile);
+ }
+
+ if (this.parsedLine >= 0) {
+ this.message += ' at line ' + this.parsedLine;
+ }
+
+ if (this.snippet) {
+ this.message += ' (near "' + this.snippet + '")';
+ }
+
+ if (dot) {
+ this.message += '.';
+ }
+ }
+}
diff --git a/com/jeremyfa/yaml/YamlParser.js b/com/jeremyfa/yaml/YamlParser.js
index 0c80d57..3346b48 100644
--- a/com/jeremyfa/yaml/YamlParser.js
+++ b/com/jeremyfa/yaml/YamlParser.js
@@ -1,11 +1,11 @@
/**
* YamlParser parses YAML strings to convert them to JS objects
- * (port of sfYaml Symfony Component)
+ * (port of Yaml Symfony Component)
*/
var YamlParser = function(offset /* Integer */)
{
- this.offset = this.isDefined(offset) ? offset : 0;
+ this.offset = (offset !== undefined) ? offset : 0;
};
YamlParser.prototype =
{
@@ -29,7 +29,8 @@ YamlParser.prototype =
this.lines = this.cleanup(value).split("\n");
var data = null;
-
+ var context = null;
+
while ( this.moveToNextLine() )
{
if ( this.isCurrentLineEmpty() )
@@ -38,9 +39,9 @@ YamlParser.prototype =
}
// tab?
- if ( /^\t+/.test(this.currentLine) )
+ if ( this.currentLine.charAt(0) == '\t' )
{
- throw new InvalidArgumentException('A YAML file cannot contain tabs as indentation at line '+(this.getRealCurrentLineNb()+1)+' ('+this.currentLine+')');
+ throw new YamlParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine);
}
var isRef = false;
@@ -58,8 +59,14 @@ YamlParser.prototype =
if ( values = /^\-((\s+)(.+?))?\s*$/.exec(this.currentLine) )
{
+
+ if (context && 'mapping' == context) {
+ throw new YamlParseException('You cannot define a sequence item when in a mapping', this.getRealCurrentLineNb() + 1, this.currentLine);
+ }
+ context = 'sequence';
+
if ( !this.isDefined(data) ) data = [];
- if ( !(data instanceof Array) ) throw new InvalidArgumentException("Non array entry at line "+(this.getRealCurrentLineNb() + 1)+".");
+ //if ( !(data instanceof Array) ) throw new YamlParseException("Non array entry", this.getRealCurrentLineNb() + 1, this.currentLine);
values = {leadspaces: values[2], value: values[3]};
@@ -71,7 +78,7 @@ YamlParser.prototype =
}
// array
- if ( !this.isDefined(values.value) || '' == values.value.split(' ').join('') || this.trim(values.value).charAt(0) == '#' )
+ if ( !this.isDefined(values.value) || '' == this.trim(values.value) || values.value.replace(/^ +/,'').charAt(0) == '#' )
{
c = this.getRealCurrentLineNb() + 1;
parser = new YamlParser(c);
@@ -81,8 +88,10 @@ YamlParser.prototype =
}
else
{
- if ( this.isDefined(values.leadspaces) && ' ' == values.leadspaces && ( matches = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\{].*?) *\:(\\s+(.+?))?\\s*$').exec(values.value) ) )
- {
+ if ( this.isDefined(values.leadspaces) &&
+ ' ' == values.leadspaces &&
+ ( matches = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\{\[].*?) *\:(\\s+(.+?))?\\s*$').exec(values.value) )
+ ) {
matches = {key: matches[1], value: matches[3]};
// this is a compact notation element, add to next block and parse
c = this.getRealCurrentLineNb();
@@ -104,20 +113,37 @@ YamlParser.prototype =
}
}
}
- else if ( values = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"].*?) *\:(\\s+(.+?))?\\s*$').exec(this.currentLine) )
+ else if ( values = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\[\{].*?) *\:(\\s+(.+?))?\\s*$').exec(this.currentLine) )
{
if ( !this.isDefined(data) ) data = {};
- if ( data instanceof Array ) throw new InvalidArgumentException("Non mapped entry at line "+(this.getRealCurrentLineNb() + 1)+".");
+ if (context && 'sequence' == context) {
+ throw new YamlParseException('You cannot define a mapping item when in a sequence', this.getRealCurrentLineNb() + 1, this.currentLine);
+ }
+ context = 'mapping';
+ //if ( data instanceof Array ) throw new YamlParseException("Non mapped entry", this.getRealCurrentLineNb() + 1, this.currentLine);
values = {key: values[1], value: values[3]};
- key = (new YamlInline()).parseScalar(values.key);
+ try {
+ key = new YamlInline().parseScalar(values.key);
+ } catch (e) {
+ if ( e instanceof YamlParseException ) {
+ e.setParsedLine(this.getRealCurrentLineNb() + 1);
+ e.setSnippet(this.currentLine);
+ }
+ throw e;
+ }
+
if ( '<<' == key )
{
if ( this.isDefined(values.value) && '*' == (values.value+'').charAt(0) )
{
- isInPlace = values.value.substring(1);
+ isInPlace = values.value.substr(1);
+ if ( this.refs[isInPlace] == undefined )
+ {
+ throw new YamlParseException('Reference "'+value+'" does not exist', this.getRealCurrentLineNb() + 1, this.currentLine);
+ }
}
else
{
@@ -139,7 +165,7 @@ YamlParser.prototype =
var merged = [];
if ( !this.isObject(parsed) )
{
- throw new InvalidArgumentException("YAML merge keys used with a scalar value instead of an array at line "+(this.getRealCurrentLineNb() + 1)+" ("+this.currentLine+")");
+ throw new YamlParseException("YAML merge keys used with a scalar value instead of an array", this.getRealCurrentLineNb() + 1, this.currentLine);
}
else if ( this.isDefined(parsed[0]) )
{
@@ -151,7 +177,7 @@ YamlParser.prototype =
var parsedItem = reverse[i];
if ( !this.isObject(reverse[i]) )
{
- throw new InvalidArgumentException("Merge items must be arrays at line "+(this.getRealCurrentLineNb() + 1)+" ("+reverse[i]+").");
+ throw new YamlParseException("Merge items must be arrays", this.getRealCurrentLineNb() + 1, this.currentLine);
}
merged = this.mergeObject(reverse[i], merged);
}
@@ -178,10 +204,10 @@ YamlParser.prototype =
data = isProcessed;
}
// hash
- else if ( !this.isDefined(values.value) || '' == values.value.split(' ').join('') || this.trim(values.value).charAt(0) == '#' )
+ else if ( !this.isDefined(values.value) || '' == this.trim(values.value) || this.trim(values.value).charAt(0) == '#' )
{
// if next line is less indented or equal, then it means that the current value is null
- if ( this.isNextLineIndented() )
+ if ( this.isNextLineIndented() && !this.isNextLineUnIndentedCollection() )
{
data[key] = null;
}
@@ -211,18 +237,26 @@ YamlParser.prototype =
// 1-liner followed by newline
if ( 2 == this.lines.length && this.isEmpty(this.lines[1]) )
{
- value = (new YamlInline()).load(this.lines[0]);
+ try {
+ value = new YamlInline().parse(this.lines[0]);
+ } catch (e) {
+ if ( e instanceof YamlParseException ) {
+ e.setParsedLine(this.getRealCurrentLineNb() + 1);
+ e.setSnippet(this.currentLine);
+ }
+ throw e;
+ }
if ( this.isObject(value) )
{
first = value[0];
- if ( '*' == (first+'').substr(0, 1) )
+ if ( typeof(value) == 'string' && '*' == first.charAt(0) )
{
data = [];
len = value.length;
for ( var i = 0; i < len; i++ )
{
- data.push(this.refs[value[i].substring(1)]);
+ data.push(this.refs[value[i].substr(1)]);
}
value = data;
}
@@ -231,7 +265,7 @@ YamlParser.prototype =
return value;
}
- throw new InvalidArgumentException('"'+this.currentLine+'" at line '+(this.getRealCurrentLineNb() + 1));
+ throw new YamlParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine);
}
if ( isRef )
@@ -279,6 +313,8 @@ YamlParser.prototype =
* @param integer indentation The indent level at which the block is to be read, or null for default
*
* @return string A YAML string
+ *
+ * @throws YamlParseException When indentation problem are detected
*/
getNextEmbedBlock: function(indentation)
{
@@ -289,10 +325,12 @@ YamlParser.prototype =
if ( !this.isDefined(indentation) )
{
newIndent = this.getCurrentLineIndentation();
+
+ var unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine);
- if ( !this.isCurrentLineEmpty() && 0 == newIndent )
+ if ( !this.isCurrentLineEmpty() && 0 == newIndent && !unindentedEmbedBlock )
{
- throw new InvalidArgumentException('A Indentation problem at line '+(this.getRealCurrentLineNb() + 1)+' ('+this.currentLine+')');
+ throw new YamlParseException('Indentation problem A', this.getRealCurrentLineNb() + 1, this.currentLine);
}
}
else
@@ -300,30 +338,38 @@ YamlParser.prototype =
newIndent = indentation;
}
- var data = [this.currentLine.substring(newIndent)];
+ var data = [this.currentLine.substr(newIndent)];
+
+ var isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine);
while ( this.moveToNextLine() )
{
+
+ if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine)) {
+ this.moveToPreviousLine();
+ break;
+ }
+
if ( this.isCurrentLineEmpty() )
{
if ( this.isCurrentLineBlank() )
{
- data.push(this.currentLine.substring(newIndent));
+ data.push(this.currentLine.substr(newIndent));
}
continue;
}
indent = this.getCurrentLineIndentation();
- var match;
- if ( match = /^( *)$/.exec(this.currentLine) )
+ var matches;
+ if ( matches = /^( *)$/.exec(this.currentLine) )
{
// empty line
- data.push(match[1]);
+ data.push(matches[1]);
}
else if ( indent >= newIndent )
{
- data.push(this.currentLine.substring(newIndent));
+ data.push(this.currentLine.substr(newIndent));
}
else if ( 0 == indent )
{
@@ -333,7 +379,7 @@ YamlParser.prototype =
}
else
{
- throw new InvalidArgumentException('B Indentation problem at line '+(this.getRealCurrentLineNb() + 1)+' ('+this.currentLine+')');
+ throw new YamlParseException('Indentation problem B', this.getRealCurrentLineNb() + 1, this.currentLine);
}
}
@@ -342,6 +388,8 @@ YamlParser.prototype =
/**
* Moves the parser to the next line.
+ *
+ * @return Boolean
*/
moveToNextLine: function()
{
@@ -371,6 +419,8 @@ YamlParser.prototype =
* @param string value A YAML value
*
* @return mixed A JS value
+ *
+ * @throws YamlParseException When reference does not exist
*/
parseValue: function(value)
{
@@ -382,12 +432,12 @@ YamlParser.prototype =
}
else
{
- value = (value+'').substring(1);
+ value = (value+'').substr(1);
}
if ( this.refs[value] == undefined )
{
- throw new InvalidArgumentException('Reference "'+value+'" does not exist ('+this.currentLine+').');
+ throw new YamlParseException('Reference "'+value+'" does not exist', this.getRealCurrentLineNb() + 1, this.currentLine);
}
return this.refs[value];
}
@@ -400,9 +450,14 @@ YamlParser.prototype =
return this.parseFoldedScalar(matches.separator, modifiers.replace(/\d+/g, ''), Math.abs(parseInt(modifiers)));
}
- else
- {
- return (new YamlInline()).load(value);
+ try {
+ return new YamlInline().parse(value);
+ } catch (e) {
+ if ( e instanceof YamlParseException ) {
+ e.setParsedLine(this.getRealCurrentLineNb() + 1);
+ e.setSnippet(this.currentLine);
+ }
+ throw e;
}
},
@@ -472,7 +527,7 @@ YamlParser.prototype =
}
else if ( matches = /^( *)$/.exec(this.currentLine) )
{
- text += matches[1].replace(new RegExp('^ {1,'+textIndent.length+'}','g'), '', matches[1])+"\n";
+ text += matches[1].replace(new RegExp('^ {1,'+textIndent.length+'}','g'), '')+"\n";
}
else
{
@@ -551,7 +606,7 @@ YamlParser.prototype =
*/
isCurrentLineBlank: function()
{
- return '' == this.currentLine.split(' ').join('');
+ return '' == this.trim(this.currentLine);
},
/**
@@ -596,7 +651,7 @@ YamlParser.prototype =
regex = /^(#.*?\n)+/;
if ( regex.test(value) )
{
- trimmedValue = value.replace(regex, '');
+ var trimmedValue = value.replace(regex, '');
// items have been removed, update the offset
this.offset += this.subStrCount(value, "\n") - this.subStrCount(trimmedValue, "\n");
@@ -619,6 +674,48 @@ YamlParser.prototype =
return value;
},
+
+ /**
+ * Returns true if the next line starts unindented collection
+ *
+ * @return Boolean Returns true if the next line starts unindented collection, false otherwise
+ */
+ isNextLineUnIndentedCollection: function()
+ {
+ var currentIndentation = this.getCurrentLineIndentation();
+ var notEOF = this.moveToNextLine();
+
+ while (notEOF && this.isCurrentLineEmpty()) {
+ notEOF = this.moveToNextLine();
+ }
+
+ if (false === notEOF) {
+ return false;
+ }
+
+ var ret = false;
+ if (
+ this.getCurrentLineIndentation() == currentIndentation
+ &&
+ this.isStringUnIndentedCollectionItem(this.currentLine)
+ ) {
+ ret = true;
+ }
+
+ this.moveToPreviousLine();
+
+ return ret;
+ },
+
+ /**
+ * Returns true if the string is unindented collection item
+ *
+ * @return Boolean Returns true if the string is unindented collection item, false otherwise
+ */
+ isStringUnIndentedCollectionItem: function(string)
+ {
+ return (0 === this.currentLine.indexOf('- '));
+ },
isObject: function(input)
{
@@ -650,16 +747,19 @@ YamlParser.prototype =
merge: function(a /* Object */, b /* Object */)
{
var c = {};
+ var i;
for ( i in a )
{
- if ( /^\d+$/.test(i) ) c.push(a);
- else c[i] = a[i];
+ if ( a.hasOwnProperty(i) )
+ if ( /^\d+$/.test(i) ) c.push(a);
+ else c[i] = a[i];
}
for ( i in b )
{
- if ( /^\d+$/.test(i) ) c.push(b);
- else c[i] = b[i];
+ if ( b.hasOwnProperty(i) )
+ if ( /^\d+$/.test(i) ) c.push(b);
+ else c[i] = b[i];
}
return c;
@@ -670,7 +770,7 @@ YamlParser.prototype =
var i;
var result = '';
for ( i = 0; i < count; i++ ) result += str;
- return str;
+ return result;
},
subStrCount: function(string, subString, start, length)
@@ -689,6 +789,7 @@ YamlParser.prototype =
{
if ( subString == string.substr(i, sublen) )
c++;
+ i += sublen - 1;
}
return c;
@@ -696,6 +797,6 @@ YamlParser.prototype =
trim: function(str /* String */)
{
- return (str+'').replace(/^\s+/,'').replace(/\s+$/,'');
+ return (str+'').replace(/^ +/,'').replace(/ +$/,'');
}
};
diff --git a/com/jeremyfa/yaml/YamlUnescaper.js b/com/jeremyfa/yaml/YamlUnescaper.js
new file mode 100644
index 0000000..ea4a2c6
--- /dev/null
+++ b/com/jeremyfa/yaml/YamlUnescaper.js
@@ -0,0 +1,108 @@
+/**
+ * YamlUnescaper encapsulates unescaping rules for single and double-quoted
+ * YAML strings.
+ *
+ * @author Matthew Lewinski <matthew@lewinski.org>
+ */
+var YamlUnescaper = function(){};
+YamlUnescaper.prototype =
+{
+ /**
+ * Unescapes a single quoted string.
+ *
+ * @param string value A single quoted string.
+ *
+ * @return string The unescaped string.
+ */
+ unescapeSingleQuotedString: function(value)
+ {
+ return value.replace(/''/g, "'");
+ },
+
+ /**
+ * Unescapes a double quoted string.
+ *
+ * @param string value A double quoted string.
+ *
+ * @return string The unescaped string.
+ */
+ unescapeDoubleQuotedString: function(value)
+ {
+ var callback = function(m) {
+ return new YamlUnescaper().unescapeCharacter(m);
+ };
+
+ // evaluate the string
+ return value.replace(new RegExp(YamlUnescaper.REGEX_ESCAPED_CHARACTER, 'g'), callback);
+ },
+
+ /**
+ * Unescapes a character that was found in a double-quoted string
+ *
+ * @param string value An escaped character
+ *
+ * @return string The unescaped character
+ */
+ unescapeCharacter: function(value)
+ {
+ switch (value.charAt(1)) {
+ case '0':
+ return String.fromCharCode(0);
+ case 'a':
+ return String.fromCharCode(7);
+ case 'b':
+ return String.fromCharCode(8);
+ case 't':
+ return "\t";
+ case "\t":
+ return "\t";
+ case 'n':
+ return "\n";
+ case 'v':
+ return String.fromCharCode(11);
+ case 'f':
+ return String.fromCharCode(12);
+ case 'r':
+ return String.fromCharCode(13);
+ case 'e':
+ return "\x1b";
+ case ' ':
+ return ' ';
+ case '"':
+ return '"';
+ case '/':
+ return '/';
+ case '\\':
+ return '\\';
+ case 'N':
+ // U+0085 NEXT LINE
+ return "\x00\x85";
+ case '_':
+ // U+00A0 NO-BREAK SPACE
+ return "\x00\xA0";
+ case 'L':
+ // U+2028 LINE SEPARATOR
+ return "\x20\x28";
+ case 'P':
+ // U+2029 PARAGRAPH SEPARATOR
+ return "\x20\x29";
+ case 'x':
+ return this.pack('n', new YamlInline().hexdec(value.substr(2, 2)));
+ case 'u':
+ return this.pack('n', new YamlInline().hexdec(value.substr(2, 4)));
+ case 'U':
+ return this.pack('N', new YamlInline().hexdec(value.substr(2, 8)));
+ }
+ },
+
+ /**
+ * @see http://phpjs.org/functions/pack
+ * @warning only modes used above copied
+ */
+ pack: function(B){var g=0,o=1,m="",l="",z=0,p=[],E,s,C,I,h,c;var d,b,x,H,u,e,A,q,D,t,w,a,G,F,y,v,f;while(g<B.length){E=B.charAt(g);s="";g++;while((g<B.length)&&(B.charAt(g).match(/[\d\*]/)!==null)){s+=B.charAt(g);g++}if(s===""){s="1"}switch(E){case"n":if(s==="*"){s=arguments.length-o}if(s>(arguments.length-o)){throw new Error("Warning: pack() Type "+E+": too few arguments")}for(z=0;z<s;z++){m+=String.fromCharCode(arguments[o]>>8&255);m+=String.fromCharCode(arguments[o]&255);o++}break;case"N":if(s==="*"){s=arguments.length-o}if(s>(arguments.length-o)){throw new Error("Warning: pack() Type "+E+": too few arguments")}for(z=0;z<s;z++){m+=String.fromCharCode(arguments[o]>>24&255);m+=String.fromCharCode(arguments[o]>>16&255);m+=String.fromCharCode(arguments[o]>>8&255);m+=String.fromCharCode(arguments[o]&255);o++}break;default:throw new Error("Warning: pack() Type "+E+": unknown format code")}}if(o<arguments.length){throw new Error("Warning: pack(): "+(arguments.length-o)+" arguments unused")}return m}
+}
+
+// Regex fragment that matches an escaped character in a double quoted
+// string.
+// why escape quotes, ffs!
+YamlUnescaper.REGEX_ESCAPED_CHARACTER = '\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})';
diff --git a/demo.html b/demo.html
index c107c57..cbff773 100644
--- a/demo.html
+++ b/demo.html
@@ -19,60 +19,57 @@
width: 100%;
overflow: hidden;
}
+ #parse {
+ border: none;
+ background-color: white;
+ color: black;
+ z-index: 3;
+ position: absolute;
+ right: 50%;
+ top: 0;
+ width: 100px;
+ }
+ #yaml {
+ color: white;
+ background-color: black;
+ font-family: "Courier New";
+ font-size: 14px;
+ width: 50%;
+ border: none;
+ position: absolute;
+ top: 0;
+ left: 0;
+ z-index: 1;
+ height: 100%;
+ }
+ #result {
+ color: black;
+ background-color: white;
+ font-family: "Courier New";
+ font-size: 15px;
+ width: 50%;
+ border: none;
+ position: absolute;
+ top: 5em;
+ left: 50%;
+ overflow: auto;
+ z-index: 2;
+ height: 100%;
+ }
+ #tests {
+ width: 50%;
+ border: none;
+ position: absolute;
+ top: 0;
+ left: 50%;
+ z-index: 2;
+ }
</style>
<!-- standalone yaml.js library -->
<script type="text/javascript" src="yaml.js"></script>
-
- <!-- encode json with mootools -->
- <script type="text/javascript" src="libs/demo/mootools.js"></script>
-
- <title>yaml.js demo</title>
-
- <script type="text/javascript">
- window.addEvent('domready', function()
- {
- $('parse').setStyles({
- border: 'none',
- backgroundColor: 'white',
- color: 'black',
- zIndex: '3',
- position: 'absolute',
- right: '50%',
- top: '0%',
- width: '100px'
- });
- $('yaml').setStyles({
- color: 'white',
- backgroundColor: 'black',
- fontFamily: 'Courier New',
- fontSize: '14px',
- width: '50%',
- height: parseInt($(document.body).getSize().y)+'px',
- border: 'none',
- position: 'absolute',
- top: '0%',
- left: '0%',
- zIndex: '1'
- });
-
- $('result').setStyles({
- color: 'black',
- backgroundColor: 'white',
- fontFamily: 'Courier New',
- fontSize: '15px',
- width: '50%',
- height: parseInt($(document.body).getSize().y)+'px',
- border: 'none',
- position: 'absolute',
- top: '0%',
- left: '50%',
- overflow: 'auto',
- zIndex: '2'
- });
- });
- </script>
+ <title>yaml.js demo</title>
</head>
<body>
@@ -107,7 +104,8 @@ comments: &gt;
Backup contact is Nancy
Billsmer @ 338-4338.
</textarea>
-<input type="button" id="parse" name="parse" value="Parse &raquo;" onclick="try{$('result').innerHTML=JSON.encode(YAML.decode($('yaml').value))}catch(e){alert(e);}" />
+<input type="button" id="parse" name="parse" value="Parse &raquo;" onclick="try{document.getElementById('result').innerHTML=JSON.stringify(YAML.decode(document.getElementById('yaml').value))}catch(e){alert(e);}" />
+<div id="tests"><span>You could also try to run some <a href="tests.html" title="Jasmine tests">javascript tests</a> based on <a href="http://www.yaml.org/YAML_for_ruby.html">YAML cookbook for Ruby</a>. All tests should pass. Those that don't are commented out; they deal with multiple YAML documents in one stream which is not supported by jaml.js (and Symfony)</span></div>
<div id="result"></div>
</form>
diff --git a/libs/jasmine-1.2.0/MIT.LICENSE b/libs/jasmine-1.2.0/MIT.LICENSE
new file mode 100644
index 0000000..7c435ba
--- /dev/null
+++ b/libs/jasmine-1.2.0/MIT.LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008-2011 Pivotal Labs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/libs/jasmine-1.2.0/YamlSpec.js b/libs/jasmine-1.2.0/YamlSpec.js
new file mode 100644
index 0000000..7f924f1
--- /dev/null
+++ b/libs/jasmine-1.2.0/YamlSpec.js
@@ -0,0 +1,22 @@
+describe("YAML parsing", function() {
+ var t;
+ for ( var i = 0; i < YAML.parseTests.length; i++){
+
+ t = YAML.parseTests[i];
+
+ it(t.title, function() {
+ expect(YAML.decode(t.input)).toEqual(t.output);
+ });
+ }
+});
+describe("YAML dumping and parsing", function() {
+ var t;
+ for ( var i = 0; i < YAML.parseTests.length; i++){
+
+ t = YAML.parseTests[i];
+
+ it(t.title, function() {
+ expect(YAML.decode(YAML.encode(t.output))).toEqual(t.output);
+ });
+ }
+}); \ No newline at end of file
diff --git a/libs/jasmine-1.2.0/YamlTests.js b/libs/jasmine-1.2.0/YamlTests.js
new file mode 100644
index 0000000..fa3aa14
--- /dev/null
+++ b/libs/jasmine-1.2.0/YamlTests.js
@@ -0,0 +1,689 @@
+YAML.parseTests=[
+ {
+ title: "Simple Sequence",
+ input:
+'\
+- apple\n\
+- banana\n\
+- carrot\n\
+',
+ output: ['apple', 'banana', 'carrot']
+ },
+ {
+ title: "Nested Sequences",
+ input:
+'\
+-\n\
+ - foo\n\
+ - bar\n\
+ - baz\n\
+',
+ output: [['foo', 'bar', 'baz']]
+ },
+ {
+ title: "Mixed Sequences",
+ input:
+'\
+- apple\n\
+-\n\
+ - foo\n\
+ - bar\n\
+ - x123\n\
+- banana\n\
+- carrot\n\
+',
+ output: ['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot']
+ },
+ {
+ title: "Deeply Nested Sequences",
+ input:
+'\
+-\n\
+ -\n\
+ - uno\n\
+ - dos\n\
+',
+ output: [[['uno', 'dos']]]
+ },
+ {
+ title: "Simple Mapping",
+ input:
+'\
+foo: whatever\n\
+bar: stuff\n\
+',
+ output: { 'foo' : 'whatever', 'bar' : 'stuff' }
+ },
+ {
+ title: "Sequence in a Mapping",
+ input:
+'\
+foo: whatever\n\
+bar:\n\
+ - uno\n\
+ - dos\n\
+',
+ output: { 'foo' : 'whatever', 'bar' : [ 'uno', 'dos' ] }
+ },
+ {
+ title: "Nested Mappings",
+ input:
+'\
+foo: whatever\n\
+bar:\n\
+ fruit: apple\n\
+ name: steve\n\
+ sport: baseball\n\
+',
+ output:
+ { 'foo' : 'whatever',
+ 'bar' : {
+ 'fruit' : 'apple',
+ 'name' : 'steve',
+ 'sport' : 'baseball'
+ }
+ }
+ },
+ {
+ title: "Mixed Mapping",
+ input:
+'\
+foo: whatever\n\
+bar:\n\
+ -\n\
+ fruit: apple\n\
+ name: steve\n\
+ sport: baseball\n\
+ - more\n\
+ -\n\
+ python: rocks\n\
+ perl: papers\n\
+ ruby: scissorses\n\
+',
+ output:
+ { 'foo' : 'whatever',
+ 'bar' : [
+ {
+ 'fruit' : 'apple',
+ 'name' : 'steve',
+ 'sport' : 'baseball'
+ },
+ 'more',
+ {
+ 'python' : 'rocks',
+ 'perl' : 'papers',
+ 'ruby' : 'scissorses'
+ }
+ ]
+ }
+ },
+ {
+ title: "Mapping-in-Sequence Shortcut",
+ input:
+'\
+- work on YAML.py:\n\
+ - work on Store\n\
+',
+ output: [ { 'work on YAML.py' : ['work on Store'] } ]
+
+ },
+ {
+ title: "Sequence-in-Mapping Shortcut",
+ input:
+"\
+allow:\n\
+- 'localhost'\n\
+- '%.sourceforge.net'\n\
+- '%.freepan.org'\n\
+",
+ output: { 'allow' : [ 'localhost', '%.sourceforge.net', '%.freepan.org' ] }
+
+ },
+ {
+ title: "Merge key",
+ disabled: true,
+ input:
+"\
+mapping:\n\
+ name: Joe\n\
+ job: Accountant\n\
+ <<:\n\
+ age: 38\n\
+",
+ output:
+ { 'mapping' :
+ { 'name' : 'Joe',
+ 'job' : 'Accountant',
+ 'age' : 38
+ }
+ }
+ },
+ {
+ title: "Simple Inline Array",
+ input:
+"\
+--- \n\
+seq: [ a, b, c ]\n\
+",
+ output: { 'seq' : [ 'a', 'b', 'c' ] }
+
+ },
+ {
+ title: "Simple Inline Hash",
+ input:
+"\
+---\n\
+hash: { name: Steve, foo: bar }\n\
+",
+ output: { 'hash' : { 'name' : 'Steve', 'foo' : 'bar' } }
+
+ },
+ {
+ title: "Multi-line Inline Collections",
+ input:
+"\
+languages: [ Ruby,\n\
+ Perl,\n\
+ Python ]\n\
+websites: { YAML: yaml.org,\n\
+ Ruby: ruby-lang.org,\n\
+ Python: python.org,\n\
+ Perl: use.perl.org }\n\
+",
+ output:
+ { 'languages' : [ 'Ruby', 'Perl', 'Python' ],
+ 'websites' : {
+ 'YAML' : 'yaml.org',
+ 'Ruby' : 'ruby-lang.org',
+ 'Python' : 'python.org',
+ 'Perl' : 'use.perl.org'
+ }
+ }
+ },
+ {
+ title: "Commas in Values",
+ input:
+"\
+attendances: [ 45,123, 70,000, 17,222 ]\n\
+",
+ output: { 'attendances' : [ 45123, 70000, 17222 ] }
+
+ },
+ {
+ title: "Strings",
+ input:
+"\
+--- \n\
+String\n\
+",
+ output: 'String'
+
+ },
+ {
+ title: "String characters",
+ input:
+"\
+- What's Yaml?\n\
+- It's for writing data structures in plain text.\n\
+- And?\n\
+- And what? That's not good enough for you?\n\
+- No, I mean, \"And what about Yaml?\"\n\
+- Oh, oh yeah. Uh.. Yaml for Ruby.\n\
+",
+ output:
+ [
+ "What's Yaml?",
+ "It's for writing data structures in plain text.",
+ "And?",
+ "And what? That's not good enough for you?",
+ "No, I mean, \"And what about Yaml?\"",
+ "Oh, oh yeah. Uh.. Yaml for Ruby."
+ ]
+ },
+ {
+ title: "Indicators in Strings",
+ input:
+"\
+the colon followed by space is an indicator: but is a string:right here\n\
+same for the pound sign: here we have it#in a string\n\
+the comma can, honestly, be used in most cases: [ but not in, inline collections ]\n\
+",
+ output:
+ {
+ 'the colon followed by space is an indicator' : 'but is a string:right here',
+ 'same for the pound sign' : 'here we have it#in a string',
+ 'the comma can, honestly, be used in most cases' : [ 'but not in', 'inline collections' ]
+ }
+ },
+ {
+ title: "Forcing Strings",
+ input:
+"\
+date string: !str 2001-08-01\n\
+number string: !str 192\n\
+",
+ output:
+ {
+ 'date string' : '2001-08-01',
+ 'number string' : '192'
+ }
+ },
+ {
+ title: "Single-quoted Strings",
+ input:
+"\
+all my favorite symbols: '#:!/%.)'\n\
+a few i hate: '&(*'\n\
+why do i hate them?: 'it''s very hard to explain'\n\
+",
+ output:
+ {
+ 'all my favorite symbols' : '#:!/%.)',
+ 'a few i hate' : '&(*',
+ 'why do i hate them?' : 'it\'s very hard to explain'
+ }
+ },
+ {
+ title: "Double-quoted Strings",
+ input:
+'\
+i know where i want my line breaks: "one here\\nand another here\\n"\n\
+',
+ output:
+ {
+ 'i know where i want my line breaks' : "one here\nand another here\n"
+ }
+ },
+ {
+ title: "Multi-line Quoted Strings",
+ input:
+"\
+i want a long string: \"so i'm going to\n\
+ let it go on and on to other lines\n\
+ until i end it with a quote.\"\n\
+",
+ output:
+ { 'i want a long string' : "so i'm going to " +
+ "let it go on and on to other lines " +
+ "until i end it with a quote."
+ }
+ },
+ {
+ title: "Plain scalars",
+ input:
+"\
+- My little toe is broken in two places;\n\
+- I'm crazy to have skied this way;\n\
+- I'm not the craziest he's seen, since there was always the German guy\n\
+ who skied for 3 hours on a broken shin bone (just below the kneecap);\n\
+- Nevertheless, second place is respectable, and he doesn't\n\
+ recommend going for the record;\n\
+- He's going to put my foot in plaster for a month;\n\
+- This would impair my skiing ability somewhat for the\n\
+ duration, as can be imagined.\n\
+",
+ output:
+ [
+ "My little toe is broken in two places;",
+ "I'm crazy to have skied this way;",
+ "I'm not the craziest he's seen, since there was always " +
+ "the German guy who skied for 3 hours on a broken shin " +
+ "bone (just below the kneecap);",
+ "Nevertheless, second place is respectable, and he doesn't " +
+ "recommend going for the record;",
+ "He's going to put my foot in plaster for a month;",
+ "This would impair my skiing ability somewhat for the duration, " +
+ "as can be imagined."
+ ]
+ },
+ {
+ title: "Null",
+ input:
+"\
+name: Mr. Show\n\
+hosted by: Bob and David\n\
+date of next season: ~\n\
+",
+ output:
+ {
+ 'name' : 'Mr. Show',
+ 'hosted by' : 'Bob and David',
+ 'date of next season' : null
+ }
+ },
+ {
+ title: "Boolean",
+ input:
+"\
+Is Gus a Liar?: true\n\
+Do I rely on Gus for Sustenance?: false\n\
+",
+ output:
+ {
+ 'Is Gus a Liar?' : true,
+ 'Do I rely on Gus for Sustenance?' : false
+ }
+ },
+ {
+ title: "Integers",
+ input:
+"\
+zero: 0\n\
+simple: 12\n\
+one-thousand: 1,000\n\
+negative one-thousand: -1,000\n\
+",
+ output:
+ {
+ 'zero' : 0,
+ 'simple' : 12,
+ 'one-thousand' : 1000,
+ 'negative one-thousand' : -1000
+ }
+ },
+ {
+ title: "Integers as Map Keys",
+ input:
+"\
+1: one\n\
+2: two\n\
+3: three\n\
+",
+ output:
+ {
+ 1 : 'one',
+ 2 : 'two',
+ 3 : 'three'
+ }
+ },
+ {
+ title: "Floats",
+ input:
+"\
+a simple float: 2.00\n\
+larger float: 1,000.09\n\
+scientific notation: 1.00009e+3\n\
+",
+ output:
+ {
+ 'a simple float' : 2.0,
+ 'larger float' : 1000.09,
+ 'scientific notation' : 1000.09
+ }
+ },
+ {
+ title: "Time",
+ input:
+"\
+iso8601: 2001-12-14t21:59:43.10-05:00\n\
+space seperated: 2001-12-14 21:59:43.10 -05:00\n\
+",
+ output:
+ {
+ 'iso8601' : new Date("2001-12-14t21:59:43.10-05:00"),
+ 'space seperated' : new Date("2001-12-14 21:59:43.10 -05:00")
+ }
+ },
+ {
+ title: "Date",
+ input:
+"\
+1976-07-31\n\
+",
+ output: new Date("1976-07-31"),
+
+ },
+ {
+ title: "Single ending newline",
+ input:
+"\
+---\n\
+this: |\n\
+ Foo\n\
+ Bar\n\
+",
+ output: { 'this' : "Foo\nBar\n" }
+
+ },
+ {
+ title: "The '+' indicator",
+ input:
+"\
+normal: |\n\
+ extra new lines not kept\n\
+\n\
+preserving: |+\n\
+ extra new lines are kept\n\
+\n\
+\n\
+dummy: value\n\
+",
+ output:
+ {
+ 'normal' : "extra new lines not kept\n",
+ 'preserving' : "extra new lines are kept\n\n\n",
+ 'dummy' : 'value'
+ }
+ },
+ {
+ title: "Three trailing newlines in literals",
+ input:
+'\
+clipped: |\n\
+ This has one newline.\n\
+\n\
+\n\
+\n\
+same as "clipped" above: "This has one newline.\n"\n\
+\n\
+stripped: |-\n\
+ This has no newline.\n\
+\n\
+\n\
+\n\
+same as "stripped" above: "This has no newline."\n\
+\n\
+kept: |+\n\
+ This has four newlines.\n\
+\n\
+\n\
+\n\
+same as "kept" above: "This has four newlines.\n\n\n\n"\n\
+',
+ output:
+ {
+ 'clipped' : "This has one newline.\n",
+ 'same as "clipped" above' : "This has one newline.\n",
+ 'stripped' : 'This has no newline.',
+ 'same as "stripped" above' : 'This has no newline.',
+ 'kept' : "This has four newlines.\n\n\n\n",
+ 'same as "kept" above' : "This has four newlines.\n\n\n\n"
+ }
+ },
+ {
+ title: "Extra trailing newlines with spaces",
+ input:
+"\
+---\n\
+this: |\n\
+ Foo\n\
+\n\
+ \n\
+kept: |+\n\
+ Foo\n\
+ \n\
+",
+ output:
+ { 'this' : "Foo\n\n \n",
+ 'kept' : "Foo\n\n \n" }
+ },
+ {
+ title: "Folded Block in a Sequence",
+ input:
+"\
+---\n\
+- apple\n\
+- banana\n\
+- >\n\
+ can't you see\n\
+ the beauty of yaml?\n\
+ hmm\n\
+- dog\n\
+",
+ output:
+ [
+ 'apple',
+ 'banana',
+ "can't you see the beauty of yaml? hmm\n",
+ 'dog'
+ ]
+ },
+ {
+ title: "Folded Block as a Mapping Value",
+ input:
+"\
+---\n\
+quote: >\n\
+ Mark McGwire's\n\
+ year was crippled\n\
+ by a knee injury.\n\
+source: espn\n\
+",
+ output:
+ {
+ 'quote' : "Mark McGwire's year was crippled by a knee injury.\n",
+ 'source' : 'espn'
+ }
+ },
+ {
+ title: "Three trailing newlines in folded blocks",
+ input:
+'\
+clipped: >\n\
+ This has one newline.\n\
+\n\
+\n\
+\n\
+same as "clipped" above: "This has one newline.\\n"\n\
+\n\
+stripped: >-\n\
+ This has no newline.\n\
+\n\
+\n\
+\n\
+same as "stripped" above: "This has no newline."\n\
+\n\
+kept: >+\n\
+ This has four newlines.\n\
+\n\
+\n\
+\n\
+same as "kept" above: "This has four newlines.\\n\\n\\n\\n"\n\
+',
+ output:
+ {
+ 'clipped' : "This has one newline.\n",
+ 'same as "clipped" above' : "This has one newline.\n",
+ 'stripped' : 'This has no newline.',
+ 'same as "stripped" above' : 'This has no newline.',
+ 'kept' : "This has four newlines.\n\n\n\n",
+ 'same as "kept" above' : "This has four newlines.\n\n\n\n"
+ }
+ },
+ {
+ title: "Simple Alias Example",
+ input:
+"\
+- &showell Steve\n\
+- Clark\n\
+- Brian\n\
+- Oren\n\
+- *showell\n\
+",
+ output: [ 'Steve', 'Clark', 'Brian', 'Oren', 'Steve' ]
+
+ },
+ {
+ title: "Alias of a Mapping",
+ input:
+"\
+- &hello\n\
+ Meat: pork\n\
+ Starch: potato\n\
+- banana\n\
+- *hello\n\
+",
+ output:
+ [
+ { 'Meat' : 'pork', 'Starch' : 'potato' },
+ 'banana',
+ { 'Meat' : 'pork', 'Starch' : 'potato' }
+ ]
+ },
+/* {
+ title: "Trailing Document Separator",
+ input:
+"\
+- foo: 1\n\
+ bar: 2\n\
+---\n\
+more: stuff\n\
+",
+ output: [ { 'foo' : 1, 'bar' : 2 } ]
+
+ },*/
+ {
+ title: "Leading Document Separator",
+ input:
+"\
+---\n\
+- foo: 1\n\
+ bar: 2\n\
+# ---\n\
+# more: stuff\n\
+",
+ output: [ { 'foo' : 1, 'bar' : 2 } ]
+
+ },
+ {
+ title: "YAML Header",
+ input:
+"\
+--- %YAML:1.0\n\
+foo: 1\n\
+bar: 2\n\
+",
+ output: { 'foo' : 1, 'bar' : 2 }
+
+ },
+ {
+ title: "Red Herring Document Separator",
+ input:
+"\
+foo: |\n\
+ ---\n\
+",
+ output: { 'foo' : "---\n" }
+
+ },
+ {
+ title: "Strings",
+ input:
+"\
+foo: |\n\
+ ---\n\
+ foo: bar\n\
+ ---\n\
+ yo: baz\n\
+bar: |\n\
+ fooness\n\
+",
+ output:
+ {
+ 'foo' : "---\nfoo: bar\n---\nyo: baz\n",
+ 'bar' : "fooness\n"
+ }
+
+ },
+
+];
diff --git a/libs/jasmine-1.2.0/jasmine-html.js b/libs/jasmine-1.2.0/jasmine-html.js
new file mode 100644
index 0000000..a0b0639
--- /dev/null
+++ b/libs/jasmine-1.2.0/jasmine-html.js
@@ -0,0 +1,616 @@
+jasmine.HtmlReporterHelpers = {};
+
+jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
+ var el = document.createElement(type);
+
+ for (var i = 2; i < arguments.length; i++) {
+ var child = arguments[i];
+
+ if (typeof child === 'string') {
+ el.appendChild(document.createTextNode(child));
+ } else {
+ if (child) {
+ el.appendChild(child);
+ }
+ }
+ }
+
+ for (var attr in attrs) {
+ if (attr == "className") {
+ el[attr] = attrs[attr];
+ } else {
+ el.setAttribute(attr, attrs[attr]);
+ }
+ }
+
+ return el;
+};
+
+jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
+ var results = child.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.skipped) {
+ status = 'skipped';
+ }
+
+ return status;
+};
+
+jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
+ var parentDiv = this.dom.summary;
+ var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
+ var parent = child[parentSuite];
+
+ if (parent) {
+ if (typeof this.views.suites[parent.id] == 'undefined') {
+ this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
+ }
+ parentDiv = this.views.suites[parent.id].element;
+ }
+
+ parentDiv.appendChild(childElement);
+};
+
+
+jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
+ for(var fn in jasmine.HtmlReporterHelpers) {
+ ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
+ }
+};
+
+jasmine.HtmlReporter = function(_doc) {
+ var self = this;
+ var doc = _doc || window.document;
+
+ var reporterView;
+
+ var dom = {};
+
+ // Jasmine Reporter Public Interface
+ self.logRunningSpecs = false;
+
+ self.reportRunnerStarting = function(runner) {
+ var specs = runner.specs() || [];
+
+ if (specs.length == 0) {
+ return;
+ }
+
+ createReporterDom(runner.env.versionString());
+ doc.body.appendChild(dom.reporter);
+
+ reporterView = new jasmine.HtmlReporter.ReporterView(dom);
+ reporterView.addSpecs(specs, self.specFilter);
+ };
+
+ self.reportRunnerResults = function(runner) {
+ reporterView && reporterView.complete();
+ };
+
+ self.reportSuiteResults = function(suite) {
+ reporterView.suiteComplete(suite);
+ };
+
+ self.reportSpecStarting = function(spec) {
+ if (self.logRunningSpecs) {
+ self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
+ }
+ };
+
+ self.reportSpecResults = function(spec) {
+ reporterView.specComplete(spec);
+ };
+
+ self.log = function() {
+ var console = jasmine.getGlobal().console;
+ if (console && console.log) {
+ if (console.log.apply) {
+ console.log.apply(console, arguments);
+ } else {
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
+ }
+ }
+ };
+
+ self.specFilter = function(spec) {
+ if (!focusedSpecName()) {
+ return true;
+ }
+
+ return spec.getFullName().indexOf(focusedSpecName()) === 0;
+ };
+
+ return self;
+
+ function focusedSpecName() {
+ var specName;
+
+ (function memoizeFocusedSpec() {
+ if (specName) {
+ return;
+ }
+
+ var paramMap = [];
+ var params = doc.location.search.substring(1).split('&');
+
+ for (var i = 0; i < params.length; i++) {
+ var p = params[i].split('=');
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
+ }
+
+ specName = paramMap.spec;
+ })();
+
+ return specName;
+ }
+
+ function createReporterDom(version) {
+ dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
+ dom.banner = self.createDom('div', { className: 'banner' },
+ self.createDom('span', { className: 'title' }, "Jasmine "),
+ self.createDom('span', { className: 'version' }, version)),
+
+ dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
+ dom.alert = self.createDom('div', {className: 'alert'}),
+ dom.results = self.createDom('div', {className: 'results'},
+ dom.summary = self.createDom('div', { className: 'summary' }),
+ dom.details = self.createDom('div', { id: 'details' }))
+ );
+ }
+};
+jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporter.ReporterView = function(dom) {
+ this.startedAt = new Date();
+ this.runningSpecCount = 0;
+ this.completeSpecCount = 0;
+ this.passedCount = 0;
+ this.failedCount = 0;
+ this.skippedCount = 0;
+
+ this.createResultsMenu = function() {
+ this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
+ this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
+ ' | ',
+ this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
+
+ this.summaryMenuItem.onclick = function() {
+ dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
+ };
+
+ this.detailsMenuItem.onclick = function() {
+ showDetails();
+ };
+ };
+
+ this.addSpecs = function(specs, specFilter) {
+ this.totalSpecCount = specs.length;
+
+ this.views = {
+ specs: {},
+ suites: {}
+ };
+
+ for (var i = 0; i < specs.length; i++) {
+ var spec = specs[i];
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
+ if (specFilter(spec)) {
+ this.runningSpecCount++;
+ }
+ }
+ };
+
+ this.specComplete = function(spec) {
+ this.completeSpecCount++;
+
+ if (isUndefined(this.views.specs[spec.id])) {
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
+ }
+
+ var specView = this.views.specs[spec.id];
+
+ switch (specView.status()) {
+ case 'passed':
+ this.passedCount++;
+ break;
+
+ case 'failed':
+ this.failedCount++;
+ break;
+
+ case 'skipped':
+ this.skippedCount++;
+ break;
+ }
+
+ specView.refresh();
+ this.refresh();
+ };
+
+ this.suiteComplete = function(suite) {
+ var suiteView = this.views.suites[suite.id];
+ if (isUndefined(suiteView)) {
+ return;
+ }
+ suiteView.refresh();
+ };
+
+ this.refresh = function() {
+
+ if (isUndefined(this.resultsMenu)) {
+ this.createResultsMenu();
+ }
+
+ // currently running UI
+ if (isUndefined(this.runningAlert)) {
+ this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
+ dom.alert.appendChild(this.runningAlert);
+ }
+ this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
+
+ // skipped specs UI
+ if (isUndefined(this.skippedAlert)) {
+ this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
+ }
+
+ this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
+
+ if (this.skippedCount === 1 && isDefined(dom.alert)) {
+ dom.alert.appendChild(this.skippedAlert);
+ }
+
+ // passing specs UI
+ if (isUndefined(this.passedAlert)) {
+ this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
+ }
+ this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
+
+ // failing specs UI
+ if (isUndefined(this.failedAlert)) {
+ this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
+ }
+ this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
+
+ if (this.failedCount === 1 && isDefined(dom.alert)) {
+ dom.alert.appendChild(this.failedAlert);
+ dom.alert.appendChild(this.resultsMenu);
+ }
+
+ // summary info
+ this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
+ this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
+ };
+
+ this.complete = function() {
+ dom.alert.removeChild(this.runningAlert);
+
+ this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
+
+ if (this.failedCount === 0) {
+ dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
+ } else {
+ showDetails();
+ }
+
+ dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
+ };
+
+ return this;
+
+ function showDetails() {
+ if (dom.reporter.className.search(/showDetails/) === -1) {
+ dom.reporter.className += " showDetails";
+ }
+ }
+
+ function isUndefined(obj) {
+ return typeof obj === 'undefined';
+ }
+
+ function isDefined(obj) {
+ return !isUndefined(obj);
+ }
+
+ function specPluralizedFor(count) {
+ var str = count + " spec";
+ if (count > 1) {
+ str += "s"
+ }
+ return str;
+ }
+
+};
+
+jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
+
+
+jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
+ this.spec = spec;
+ this.dom = dom;
+ this.views = views;
+
+ this.symbol = this.createDom('li', { className: 'pending' });
+ this.dom.symbolSummary.appendChild(this.symbol);
+
+ this.summary = this.createDom('div', { className: 'specSummary' },
+ this.createDom('a', {
+ className: 'description',
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
+ title: this.spec.getFullName()
+ }, this.spec.description)
+ );
+
+ this.detail = this.createDom('div', { className: 'specDetail' },
+ this.createDom('a', {
+ className: 'description',
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
+ title: this.spec.getFullName()
+ }, this.spec.getFullName())
+ );
+};
+
+jasmine.HtmlReporter.SpecView.prototype.status = function() {
+ return this.getSpecStatus(this.spec);
+};
+
+jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
+ this.symbol.className = this.status();
+
+ switch (this.status()) {
+ case 'skipped':
+ break;
+
+ case 'passed':
+ this.appendSummaryToSuiteDiv();
+ break;
+
+ case 'failed':
+ this.appendSummaryToSuiteDiv();
+ this.appendFailureDetail();
+ break;
+ }
+};
+
+jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
+ this.summary.className += ' ' + this.status();
+ this.appendToSummary(this.spec, this.summary);
+};
+
+jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
+ this.detail.className += ' ' + this.status();
+
+ var resultItems = this.spec.results().getItems();
+ var messagesDiv = this.createDom('div', { className: 'messages' });
+
+ for (var i = 0; i < resultItems.length; i++) {
+ var result = resultItems[i];
+
+ if (result.type == 'log') {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
+
+ if (result.trace.stack) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
+ }
+ }
+ }
+
+ if (messagesDiv.childNodes.length > 0) {
+ this.detail.appendChild(messagesDiv);
+ this.dom.details.appendChild(this.detail);
+ }
+};
+
+jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
+ this.suite = suite;
+ this.dom = dom;
+ this.views = views;
+
+ this.element = this.createDom('div', { className: 'suite' },
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description)
+ );
+
+ this.appendToSummary(this.suite, this.element);
+};
+
+jasmine.HtmlReporter.SuiteView.prototype.status = function() {
+ return this.getSpecStatus(this.suite);
+};
+
+jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
+ this.element.className += " " + this.status();
+};
+
+jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
+
+/* @deprecated Use jasmine.HtmlReporter instead
+ */
+jasmine.TrivialReporter = function(doc) {
+ this.document = doc || document;
+ this.suiteDivs = {};
+ this.logRunningSpecs = false;
+};
+
+jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
+ var el = document.createElement(type);
+
+ for (var i = 2; i < arguments.length; i++) {
+ var child = arguments[i];
+
+ if (typeof child === 'string') {
+ el.appendChild(document.createTextNode(child));
+ } else {
+ if (child) { el.appendChild(child); }
+ }
+ }
+
+ for (var attr in attrs) {
+ if (attr == "className") {
+ el[attr] = attrs[attr];
+ } else {
+ el.setAttribute(attr, attrs[attr]);
+ }
+ }
+
+ return el;
+};
+
+jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
+ var showPassed, showSkipped;
+
+ this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
+ this.createDom('div', { className: 'banner' },
+ this.createDom('div', { className: 'logo' },
+ this.createDom('span', { className: 'title' }, "Jasmine"),
+ this.createDom('span', { className: 'version' }, runner.env.versionString())),
+ this.createDom('div', { className: 'options' },
+ "Show ",
+ showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
+ showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
+ )
+ ),
+
+ this.runnerDiv = this.createDom('div', { className: 'runner running' },
+ this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
+ this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
+ this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
+ );
+
+ this.document.body.appendChild(this.outerDiv);
+
+ var suites = runner.suites();
+ for (var i = 0; i < suites.length; i++) {
+ var suite = suites[i];
+ var suiteDiv = this.createDom('div', { className: 'suite' },
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
+ this.suiteDivs[suite.id] = suiteDiv;
+ var parentDiv = this.outerDiv;
+ if (suite.parentSuite) {
+ parentDiv = this.suiteDivs[suite.parentSuite.id];
+ }
+ parentDiv.appendChild(suiteDiv);
+ }
+
+ this.startedAt = new Date();
+
+ var self = this;
+ showPassed.onclick = function(evt) {
+ if (showPassed.checked) {
+ self.outerDiv.className += ' show-passed';
+ } else {
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
+ }
+ };
+
+ showSkipped.onclick = function(evt) {
+ if (showSkipped.checked) {
+ self.outerDiv.className += ' show-skipped';
+ } else {
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
+ }
+ };
+};
+
+jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
+ var results = runner.results();
+ var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
+ this.runnerDiv.setAttribute("class", className);
+ //do it twice for IE
+ this.runnerDiv.setAttribute("className", className);
+ var specs = runner.specs();
+ var specCount = 0;
+ for (var i = 0; i < specs.length; i++) {
+ if (this.specFilter(specs[i])) {
+ specCount++;
+ }
+ }
+ var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
+ message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
+ this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
+
+ this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
+};
+
+jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
+ var results = suite.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.totalCount === 0) { // todo: change this to check results.skipped
+ status = 'skipped';
+ }
+ this.suiteDivs[suite.id].className += " " + status;
+};
+
+jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
+ if (this.logRunningSpecs) {
+ this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
+ }
+};
+
+jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
+ var results = spec.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.skipped) {
+ status = 'skipped';
+ }
+ var specDiv = this.createDom('div', { className: 'spec ' + status },
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
+ this.createDom('a', {
+ className: 'description',
+ href: '?spec=' + encodeURIComponent(spec.getFullName()),
+ title: spec.getFullName()
+ }, spec.description));
+
+
+ var resultItems = results.getItems();
+ var messagesDiv = this.createDom('div', { className: 'messages' });
+ for (var i = 0; i < resultItems.length; i++) {
+ var result = resultItems[i];
+
+ if (result.type == 'log') {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
+
+ if (result.trace.stack) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
+ }
+ }
+ }
+
+ if (messagesDiv.childNodes.length > 0) {
+ specDiv.appendChild(messagesDiv);
+ }
+
+ this.suiteDivs[spec.suite.id].appendChild(specDiv);
+};
+
+jasmine.TrivialReporter.prototype.log = function() {
+ var console = jasmine.getGlobal().console;
+ if (console && console.log) {
+ if (console.log.apply) {
+ console.log.apply(console, arguments);
+ } else {
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
+ }
+ }
+};
+
+jasmine.TrivialReporter.prototype.getLocation = function() {
+ return this.document.location;
+};
+
+jasmine.TrivialReporter.prototype.specFilter = function(spec) {
+ var paramMap = {};
+ var params = this.getLocation().search.substring(1).split('&');
+ for (var i = 0; i < params.length; i++) {
+ var p = params[i].split('=');
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
+ }
+
+ if (!paramMap.spec) {
+ return true;
+ }
+ return spec.getFullName().indexOf(paramMap.spec) === 0;
+};
diff --git a/libs/jasmine-1.2.0/jasmine.css b/libs/jasmine-1.2.0/jasmine.css
new file mode 100644
index 0000000..826e575
--- /dev/null
+++ b/libs/jasmine-1.2.0/jasmine.css
@@ -0,0 +1,81 @@
+body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
+
+#HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
+#HTMLReporter a { text-decoration: none; }
+#HTMLReporter a:hover { text-decoration: underline; }
+#HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
+#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
+#HTMLReporter #jasmine_content { position: fixed; right: 100%; }
+#HTMLReporter .version { color: #aaaaaa; }
+#HTMLReporter .banner { margin-top: 14px; }
+#HTMLReporter .duration { color: #aaaaaa; float: right; }
+#HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; }
+#HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
+#HTMLReporter .symbolSummary li.passed { font-size: 14px; }
+#HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; }
+#HTMLReporter .symbolSummary li.failed { line-height: 9px; }
+#HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
+#HTMLReporter .symbolSummary li.skipped { font-size: 14px; }
+#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
+#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
+#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
+#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
+#HTMLReporter .runningAlert { background-color: #666666; }
+#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
+#HTMLReporter .skippedAlert:first-child { background-color: #333333; }
+#HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; }
+#HTMLReporter .passingAlert { background-color: #a6b779; }
+#HTMLReporter .passingAlert:first-child { background-color: #5e7d00; }
+#HTMLReporter .failingAlert { background-color: #cf867e; }
+#HTMLReporter .failingAlert:first-child { background-color: #b03911; }
+#HTMLReporter .results { margin-top: 14px; }
+#HTMLReporter #details { display: none; }
+#HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
+#HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
+#HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
+#HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
+#HTMLReporter.showDetails .summary { display: none; }
+#HTMLReporter.showDetails #details { display: block; }
+#HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
+#HTMLReporter .summary { margin-top: 14px; }
+#HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
+#HTMLReporter .summary .specSummary.passed a { color: #5e7d00; }
+#HTMLReporter .summary .specSummary.failed a { color: #b03911; }
+#HTMLReporter .description + .suite { margin-top: 0; }
+#HTMLReporter .suite { margin-top: 14px; }
+#HTMLReporter .suite a { color: #333333; }
+#HTMLReporter #details .specDetail { margin-bottom: 28px; }
+#HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; }
+#HTMLReporter .resultMessage { padding-top: 14px; color: #333333; }
+#HTMLReporter .resultMessage span.result { display: block; }
+#HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
+
+#TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
+#TrivialReporter a:visited, #TrivialReporter a { color: #303; }
+#TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
+#TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
+#TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
+#TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
+#TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
+#TrivialReporter .runner.running { background-color: yellow; }
+#TrivialReporter .options { text-align: right; font-size: .8em; }
+#TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
+#TrivialReporter .suite .suite { margin: 5px; }
+#TrivialReporter .suite.passed { background-color: #dfd; }
+#TrivialReporter .suite.failed { background-color: #fdd; }
+#TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
+#TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
+#TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
+#TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
+#TrivialReporter .spec.skipped { background-color: #bbb; }
+#TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
+#TrivialReporter .passed { background-color: #cfc; display: none; }
+#TrivialReporter .failed { background-color: #fbb; }
+#TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
+#TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; }
+#TrivialReporter .resultMessage .mismatch { color: black; }
+#TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; }
+#TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; }
+#TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; }
+#TrivialReporter #jasmine_content { position: fixed; right: 100%; }
+#TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; }
diff --git a/libs/jasmine-1.2.0/jasmine.js b/libs/jasmine-1.2.0/jasmine.js
new file mode 100644
index 0000000..03bf89a
--- /dev/null
+++ b/libs/jasmine-1.2.0/jasmine.js
@@ -0,0 +1,2529 @@
+var isCommonJS = typeof window == "undefined";
+
+/**
+ * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
+ *
+ * @namespace
+ */
+var jasmine = {};
+if (isCommonJS) exports.jasmine = jasmine;
+/**
+ * @private
+ */
+jasmine.unimplementedMethod_ = function() {
+ throw new Error("unimplemented method");
+};
+
+/**
+ * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
+ * a plain old variable and may be redefined by somebody else.
+ *
+ * @private
+ */
+jasmine.undefined = jasmine.___undefined___;
+
+/**
+ * Show diagnostic messages in the console if set to true
+ *
+ */
+jasmine.VERBOSE = false;
+
+/**
+ * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
+ *
+ */
+jasmine.DEFAULT_UPDATE_INTERVAL = 250;
+
+/**
+ * Default timeout interval in milliseconds for waitsFor() blocks.
+ */
+jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
+
+jasmine.getGlobal = function() {
+ function getGlobal() {
+ return this;
+ }
+
+ return getGlobal();
+};
+
+/**
+ * Allows for bound functions to be compared. Internal use only.
+ *
+ * @ignore
+ * @private
+ * @param base {Object} bound 'this' for the function
+ * @param name {Function} function to find
+ */
+jasmine.bindOriginal_ = function(base, name) {
+ var original = base[name];
+ if (original.apply) {
+ return function() {
+ return original.apply(base, arguments);
+ };
+ } else {
+ // IE support
+ return jasmine.getGlobal()[name];
+ }
+};
+
+jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
+jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
+jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
+jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
+
+jasmine.MessageResult = function(values) {
+ this.type = 'log';
+ this.values = values;
+ this.trace = new Error(); // todo: test better
+};
+
+jasmine.MessageResult.prototype.toString = function() {
+ var text = "";
+ for (var i = 0; i < this.values.length; i++) {
+ if (i > 0) text += " ";
+ if (jasmine.isString_(this.values[i])) {
+ text += this.values[i];
+ } else {
+ text += jasmine.pp(this.values[i]);
+ }
+ }
+ return text;
+};
+
+jasmine.ExpectationResult = function(params) {
+ this.type = 'expect';
+ this.matcherName = params.matcherName;
+ this.passed_ = params.passed;
+ this.expected = params.expected;
+ this.actual = params.actual;
+ this.message = this.passed_ ? 'Passed.' : params.message;
+
+ var trace = (params.trace || new Error(this.message));
+ this.trace = this.passed_ ? '' : trace;
+};
+
+jasmine.ExpectationResult.prototype.toString = function () {
+ return this.message;
+};
+
+jasmine.ExpectationResult.prototype.passed = function () {
+ return this.passed_;
+};
+
+/**
+ * Getter for the Jasmine environment. Ensures one gets created
+ */
+jasmine.getEnv = function() {
+ var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
+ return env;
+};
+
+/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isArray_ = function(value) {
+ return jasmine.isA_("Array", value);
+};
+
+/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isString_ = function(value) {
+ return jasmine.isA_("String", value);
+};
+
+/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isNumber_ = function(value) {
+ return jasmine.isA_("Number", value);
+};
+
+/**
+ * @ignore
+ * @private
+ * @param {String} typeName
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isA_ = function(typeName, value) {
+ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
+};
+
+/**
+ * Pretty printer for expecations. Takes any object and turns it into a human-readable string.
+ *
+ * @param value {Object} an object to be outputted
+ * @returns {String}
+ */
+jasmine.pp = function(value) {
+ var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
+ stringPrettyPrinter.format(value);
+ return stringPrettyPrinter.string;
+};
+
+/**
+ * Returns true if the object is a DOM Node.
+ *
+ * @param {Object} obj object to check
+ * @returns {Boolean}
+ */
+jasmine.isDomNode = function(obj) {
+ return obj.nodeType > 0;
+};
+
+/**
+ * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
+ *
+ * @example
+ * // don't care about which function is passed in, as long as it's a function
+ * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));
+ *
+ * @param {Class} clazz
+ * @returns matchable object of the type clazz
+ */
+jasmine.any = function(clazz) {
+ return new jasmine.Matchers.Any(clazz);
+};
+
+/**
+ * Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the
+ * attributes on the object.
+ *
+ * @example
+ * // don't care about any other attributes than foo.
+ * expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"});
+ *
+ * @param sample {Object} sample
+ * @returns matchable object for the sample
+ */
+jasmine.objectContaining = function (sample) {
+ return new jasmine.Matchers.ObjectContaining(sample);
+};
+
+/**
+ * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
+ *
+ * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
+ * expectation syntax. Spies can be checked if they were called or not and what the calling params were.
+ *
+ * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs).
+ *
+ * Spies are torn down at the end of every spec.
+ *
+ * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
+ *
+ * @example
+ * // a stub
+ * var myStub = jasmine.createSpy('myStub'); // can be used anywhere
+ *
+ * // spy example
+ * var foo = {
+ * not: function(bool) { return !bool; }
+ * }
+ *
+ * // actual foo.not will not be called, execution stops
+ * spyOn(foo, 'not');
+
+ // foo.not spied upon, execution will continue to implementation
+ * spyOn(foo, 'not').andCallThrough();
+ *
+ * // fake example
+ * var foo = {
+ * not: function(bool) { return !bool; }
+ * }
+ *
+ * // foo.not(val) will return val
+ * spyOn(foo, 'not').andCallFake(function(value) {return value;});
+ *
+ * // mock example
+ * foo.not(7 == 7);
+ * expect(foo.not).toHaveBeenCalled();
+ * expect(foo.not).toHaveBeenCalledWith(true);
+ *
+ * @constructor
+ * @see spyOn, jasmine.createSpy, jasmine.createSpyObj
+ * @param {String} name
+ */
+jasmine.Spy = function(name) {
+ /**
+ * The name of the spy, if provided.
+ */
+ this.identity = name || 'unknown';
+ /**
+ * Is this Object a spy?
+ */
+ this.isSpy = true;
+ /**
+ * The actual function this spy stubs.
+ */
+ this.plan = function() {
+ };
+ /**
+ * Tracking of the most recent call to the spy.
+ * @example
+ * var mySpy = jasmine.createSpy('foo');
+ * mySpy(1, 2);
+ * mySpy.mostRecentCall.args = [1, 2];
+ */
+ this.mostRecentCall = {};
+
+ /**
+ * Holds arguments for each call to the spy, indexed by call count
+ * @example
+ * var mySpy = jasmine.createSpy('foo');
+ * mySpy(1, 2);
+ * mySpy(7, 8);
+ * mySpy.mostRecentCall.args = [7, 8];
+ * mySpy.argsForCall[0] = [1, 2];
+ * mySpy.argsForCall[1] = [7, 8];
+ */
+ this.argsForCall = [];
+ this.calls = [];
+};
+
+/**
+ * Tells a spy to call through to the actual implemenatation.
+ *
+ * @example
+ * var foo = {
+ * bar: function() { // do some stuff }
+ * }
+ *
+ * // defining a spy on an existing property: foo.bar
+ * spyOn(foo, 'bar').andCallThrough();
+ */
+jasmine.Spy.prototype.andCallThrough = function() {
+ this.plan = this.originalValue;
+ return this;
+};
+
+/**
+ * For setting the return value of a spy.
+ *
+ * @example
+ * // defining a spy from scratch: foo() returns 'baz'
+ * var foo = jasmine.createSpy('spy on foo').andReturn('baz');
+ *
+ * // defining a spy on an existing property: foo.bar() returns 'baz'
+ * spyOn(foo, 'bar').andReturn('baz');
+ *
+ * @param {Object} value
+ */
+jasmine.Spy.prototype.andReturn = function(value) {
+ this.plan = function() {
+ return value;
+ };
+ return this;
+};
+
+/**
+ * For throwing an exception when a spy is called.
+ *
+ * @example
+ * // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
+ * var foo = jasmine.createSpy('spy on foo').andThrow('baz');
+ *
+ * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
+ * spyOn(foo, 'bar').andThrow('baz');
+ *
+ * @param {String} exceptionMsg
+ */
+jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
+ this.plan = function() {
+ throw exceptionMsg;
+ };
+ return this;
+};
+
+/**
+ * Calls an alternate implementation when a spy is called.
+ *
+ * @example
+ * var baz = function() {
+ * // do some stuff, return something
+ * }
+ * // defining a spy from scratch: foo() calls the function baz
+ * var foo = jasmine.createSpy('spy on foo').andCall(baz);
+ *
+ * // defining a spy on an existing property: foo.bar() calls an anonymnous function
+ * spyOn(foo, 'bar').andCall(function() { return 'baz';} );
+ *
+ * @param {Function} fakeFunc
+ */
+jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
+ this.plan = fakeFunc;
+ return this;
+};
+
+/**
+ * Resets all of a spy's the tracking variables so that it can be used again.
+ *
+ * @example
+ * spyOn(foo, 'bar');
+ *
+ * foo.bar();
+ *
+ * expect(foo.bar.callCount).toEqual(1);
+ *
+ * foo.bar.reset();
+ *
+ * expect(foo.bar.callCount).toEqual(0);
+ */
+jasmine.Spy.prototype.reset = function() {
+ this.wasCalled = false;
+ this.callCount = 0;
+ this.argsForCall = [];
+ this.calls = [];
+ this.mostRecentCall = {};
+};
+
+jasmine.createSpy = function(name) {
+
+ var spyObj = function() {
+ spyObj.wasCalled = true;
+ spyObj.callCount++;
+ var args = jasmine.util.argsToArray(arguments);
+ spyObj.mostRecentCall.object = this;
+ spyObj.mostRecentCall.args = args;
+ spyObj.argsForCall.push(args);
+ spyObj.calls.push({object: this, args: args});
+ return spyObj.plan.apply(this, arguments);
+ };
+
+ var spy = new jasmine.Spy(name);
+
+ for (var prop in spy) {
+ spyObj[prop] = spy[prop];
+ }
+
+ spyObj.reset();
+
+ return spyObj;
+};
+
+/**
+ * Determines whether an object is a spy.
+ *
+ * @param {jasmine.Spy|Object} putativeSpy
+ * @returns {Boolean}
+ */
+jasmine.isSpy = function(putativeSpy) {
+ return putativeSpy && putativeSpy.isSpy;
+};
+
+/**
+ * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
+ * large in one call.
+ *
+ * @param {String} baseName name of spy class
+ * @param {Array} methodNames array of names of methods to make spies
+ */
+jasmine.createSpyObj = function(baseName, methodNames) {
+ if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
+ throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
+ }
+ var obj = {};
+ for (var i = 0; i < methodNames.length; i++) {
+ obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
+ }
+ return obj;
+};
+
+/**
+ * All parameters are pretty-printed and concatenated together, then written to the current spec's output.
+ *
+ * Be careful not to leave calls to <code>jasmine.log</code> in production code.
+ */
+jasmine.log = function() {
+ var spec = jasmine.getEnv().currentSpec;
+ spec.log.apply(spec, arguments);
+};
+
+/**
+ * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
+ *
+ * @example
+ * // spy example
+ * var foo = {
+ * not: function(bool) { return !bool; }
+ * }
+ * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
+ *
+ * @see jasmine.createSpy
+ * @param obj
+ * @param methodName
+ * @returns a Jasmine spy that can be chained with all spy methods
+ */
+var spyOn = function(obj, methodName) {
+ return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
+};
+if (isCommonJS) exports.spyOn = spyOn;
+
+/**
+ * Creates a Jasmine spec that will be added to the current suite.
+ *
+ * // TODO: pending tests
+ *
+ * @example
+ * it('should be true', function() {
+ * expect(true).toEqual(true);
+ * });
+ *
+ * @param {String} desc description of this specification
+ * @param {Function} func defines the preconditions and expectations of the spec
+ */
+var it = function(desc, func) {
+ return jasmine.getEnv().it(desc, func);
+};
+if (isCommonJS) exports.it = it;
+
+/**
+ * Creates a <em>disabled</em> Jasmine spec.
+ *
+ * A convenience method that allows existing specs to be disabled temporarily during development.
+ *
+ * @param {String} desc description of this specification
+ * @param {Function} func defines the preconditions and expectations of the spec
+ */
+var xit = function(desc, func) {
+ return jasmine.getEnv().xit(desc, func);
+};
+if (isCommonJS) exports.xit = xit;
+
+/**
+ * Starts a chain for a Jasmine expectation.
+ *
+ * It is passed an Object that is the actual value and should chain to one of the many
+ * jasmine.Matchers functions.
+ *
+ * @param {Object} actual Actual value to test against and expected value
+ */
+var expect = function(actual) {
+ return jasmine.getEnv().currentSpec.expect(actual);
+};
+if (isCommonJS) exports.expect = expect;
+
+/**
+ * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
+ *
+ * @param {Function} func Function that defines part of a jasmine spec.
+ */
+var runs = function(func) {
+ jasmine.getEnv().currentSpec.runs(func);
+};
+if (isCommonJS) exports.runs = runs;
+
+/**
+ * Waits a fixed time period before moving to the next block.
+ *
+ * @deprecated Use waitsFor() instead
+ * @param {Number} timeout milliseconds to wait
+ */
+var waits = function(timeout) {
+ jasmine.getEnv().currentSpec.waits(timeout);
+};
+if (isCommonJS) exports.waits = waits;
+
+/**
+ * Waits for the latchFunction to return true before proceeding to the next block.
+ *
+ * @param {Function} latchFunction
+ * @param {String} optional_timeoutMessage
+ * @param {Number} optional_timeout
+ */
+var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
+ jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
+};
+if (isCommonJS) exports.waitsFor = waitsFor;
+
+/**
+ * A function that is called before each spec in a suite.
+ *
+ * Used for spec setup, including validating assumptions.
+ *
+ * @param {Function} beforeEachFunction
+ */
+var beforeEach = function(beforeEachFunction) {
+ jasmine.getEnv().beforeEach(beforeEachFunction);
+};
+if (isCommonJS) exports.beforeEach = beforeEach;
+
+/**
+ * A function that is called after each spec in a suite.
+ *
+ * Used for restoring any state that is hijacked during spec execution.
+ *
+ * @param {Function} afterEachFunction
+ */
+var afterEach = function(afterEachFunction) {
+ jasmine.getEnv().afterEach(afterEachFunction);
+};
+if (isCommonJS) exports.afterEach = afterEach;
+
+/**
+ * Defines a suite of specifications.
+ *
+ * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
+ * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
+ * of setup in some tests.
+ *
+ * @example
+ * // TODO: a simple suite
+ *
+ * // TODO: a simple suite with a nested describe block
+ *
+ * @param {String} description A string, usually the class under test.
+ * @param {Function} specDefinitions function that defines several specs.
+ */
+var describe = function(description, specDefinitions) {
+ return jasmine.getEnv().describe(description, specDefinitions);
+};
+if (isCommonJS) exports.describe = describe;
+
+/**
+ * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
+ *
+ * @param {String} description A string, usually the class under test.
+ * @param {Function} specDefinitions function that defines several specs.
+ */
+var xdescribe = function(description, specDefinitions) {
+ return jasmine.getEnv().xdescribe(description, specDefinitions);
+};
+if (isCommonJS) exports.xdescribe = xdescribe;
+
+
+// Provide the XMLHttpRequest class for IE 5.x-6.x:
+jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
+ function tryIt(f) {
+ try {
+ return f();
+ } catch(e) {
+ }
+ return null;
+ }
+
+ var xhr = tryIt(function() {
+ return new ActiveXObject("Msxml2.XMLHTTP.6.0");
+ }) ||
+ tryIt(function() {
+ return new ActiveXObject("Msxml2.XMLHTTP.3.0");
+ }) ||
+ tryIt(function() {
+ return new ActiveXObject("Msxml2.XMLHTTP");
+ }) ||
+ tryIt(function() {
+ return new ActiveXObject("Microsoft.XMLHTTP");
+ });
+
+ if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
+
+ return xhr;
+} : XMLHttpRequest;
+/**
+ * @namespace
+ */
+jasmine.util = {};
+
+/**
+ * Declare that a child class inherit it's prototype from the parent class.
+ *
+ * @private
+ * @param {Function} childClass
+ * @param {Function} parentClass
+ */
+jasmine.util.inherit = function(childClass, parentClass) {
+ /**
+ * @private
+ */
+ var subclass = function() {
+ };
+ subclass.prototype = parentClass.prototype;
+ childClass.prototype = new subclass();
+};
+
+jasmine.util.formatException = function(e) {
+ var lineNumber;
+ if (e.line) {
+ lineNumber = e.line;
+ }
+ else if (e.lineNumber) {
+ lineNumber = e.lineNumber;
+ }
+
+ var file;
+
+ if (e.sourceURL) {
+ file = e.sourceURL;
+ }
+ else if (e.fileName) {
+ file = e.fileName;
+ }
+
+ var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
+
+ if (file && lineNumber) {
+ message += ' in ' + file + ' (line ' + lineNumber + ')';
+ }
+
+ return message;
+};
+
+jasmine.util.htmlEscape = function(str) {
+ if (!str) return str;
+ return str.replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;');
+};
+
+jasmine.util.argsToArray = function(args) {
+ var arrayOfArgs = [];
+ for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
+ return arrayOfArgs;
+};
+
+jasmine.util.extend = function(destination, source) {
+ for (var property in source) destination[property] = source[property];
+ return destination;
+};
+
+/**
+ * Environment for Jasmine
+ *
+ * @constructor
+ */
+jasmine.Env = function() {
+ this.currentSpec = null;
+ this.currentSuite = null;
+ this.currentRunner_ = new jasmine.Runner(this);
+
+ this.reporter = new jasmine.MultiReporter();
+
+ this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
+ this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
+ this.lastUpdate = 0;
+ this.specFilter = function() {
+ return true;
+ };
+
+ this.nextSpecId_ = 0;
+ this.nextSuiteId_ = 0;
+ this.equalityTesters_ = [];
+
+ // wrap matchers
+ this.matchersClass = function() {
+ jasmine.Matchers.apply(this, arguments);
+ };
+ jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
+
+ jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
+};
+
+
+jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
+jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
+jasmine.Env.prototype.setInterval = jasmine.setInterval;
+jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
+
+/**
+ * @returns an object containing jasmine version build info, if set.
+ */
+jasmine.Env.prototype.version = function () {
+ if (jasmine.version_) {
+ return jasmine.version_;
+ } else {
+ throw new Error('Version not set');
+ }
+};
+
+/**
+ * @returns string containing jasmine version build info, if set.
+ */
+jasmine.Env.prototype.versionString = function() {
+ if (!jasmine.version_) {
+ return "version unknown";
+ }
+
+ var version = this.version();
+ var versionString = version.major + "." + version.minor + "." + version.build;
+ if (version.release_candidate) {
+ versionString += ".rc" + version.release_candidate;
+ }
+ versionString += " revision " + version.revision;
+ return versionString;
+};
+
+/**
+ * @returns a sequential integer starting at 0
+ */
+jasmine.Env.prototype.nextSpecId = function () {
+ return this.nextSpecId_++;
+};
+
+/**
+ * @returns a sequential integer starting at 0
+ */
+jasmine.Env.prototype.nextSuiteId = function () {
+ return this.nextSuiteId_++;
+};
+
+/**
+ * Register a reporter to receive status updates from Jasmine.
+ * @param {jasmine.Reporter} reporter An object which will receive status updates.
+ */
+jasmine.Env.prototype.addReporter = function(reporter) {
+ this.reporter.addReporter(reporter);
+};
+
+jasmine.Env.prototype.execute = function() {
+ this.currentRunner_.execute();
+};
+
+jasmine.Env.prototype.describe = function(description, specDefinitions) {
+ var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
+
+ var parentSuite = this.currentSuite;
+ if (parentSuite) {
+ parentSuite.add(suite);
+ } else {
+ this.currentRunner_.add(suite);
+ }
+
+ this.currentSuite = suite;
+
+ var declarationError = null;
+ try {
+ specDefinitions.call(suite);
+ } catch(e) {
+ declarationError = e;
+ }
+
+ if (declarationError) {
+ this.it("encountered a declaration exception", function() {
+ throw declarationError;
+ });
+ }
+
+ this.currentSuite = parentSuite;
+
+ return suite;
+};
+
+jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
+ if (this.currentSuite) {
+ this.currentSuite.beforeEach(beforeEachFunction);
+ } else {
+ this.currentRunner_.beforeEach(beforeEachFunction);
+ }
+};
+
+jasmine.Env.prototype.currentRunner = function () {
+ return this.currentRunner_;
+};
+
+jasmine.Env.prototype.afterEach = function(afterEachFunction) {
+ if (this.currentSuite) {
+ this.currentSuite.afterEach(afterEachFunction);
+ } else {
+ this.currentRunner_.afterEach(afterEachFunction);
+ }
+
+};
+
+jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
+ return {
+ execute: function() {
+ }
+ };
+};
+
+jasmine.Env.prototype.it = function(description, func) {
+ var spec = new jasmine.Spec(this, this.currentSuite, description);
+ this.currentSuite.add(spec);
+ this.currentSpec = spec;
+
+ if (func) {
+ spec.runs(func);
+ }
+
+ return spec;
+};
+
+jasmine.Env.prototype.xit = function(desc, func) {
+ return {
+ id: this.nextSpecId(),
+ runs: function() {
+ }
+ };
+};
+
+jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
+ if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
+ return true;
+ }
+
+ a.__Jasmine_been_here_before__ = b;
+ b.__Jasmine_been_here_before__ = a;
+
+ var hasKey = function(obj, keyName) {
+ return obj !== null && obj[keyName] !== jasmine.undefined;
+ };
+
+ for (var property in b) {
+ if (!hasKey(a, property) && hasKey(b, property)) {
+ mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
+ }
+ }
+ for (property in a) {
+ if (!hasKey(b, property) && hasKey(a, property)) {
+ mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
+ }
+ }
+ for (property in b) {
+ if (property == '__Jasmine_been_here_before__') continue;
+ if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
+ mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
+ }
+ }
+
+ if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
+ mismatchValues.push("arrays were not the same length");
+ }
+
+ delete a.__Jasmine_been_here_before__;
+ delete b.__Jasmine_been_here_before__;
+ return (mismatchKeys.length === 0 && mismatchValues.length === 0);
+};
+
+jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
+ mismatchKeys = mismatchKeys || [];
+ mismatchValues = mismatchValues || [];
+
+ for (var i = 0; i < this.equalityTesters_.length; i++) {
+ var equalityTester = this.equalityTesters_[i];
+ var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
+ if (result !== jasmine.undefined) return result;
+ }
+
+ if (a === b) return true;
+
+ if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
+ return (a == jasmine.undefined && b == jasmine.undefined);
+ }
+
+ if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
+ return a === b;
+ }
+
+ if (a instanceof Date && b instanceof Date) {
+ return a.getTime() == b.getTime();
+ }
+
+ if (a.jasmineMatches) {
+ return a.jasmineMatches(b);
+ }
+
+ if (b.jasmineMatches) {
+ return b.jasmineMatches(a);
+ }
+
+ if (a instanceof jasmine.Matchers.ObjectContaining) {
+ return a.matches(b);
+ }
+
+ if (b instanceof jasmine.Matchers.ObjectContaining) {
+ return b.matches(a);
+ }
+
+ if (jasmine.isString_(a) && jasmine.isString_(b)) {
+ return (a == b);
+ }
+
+ if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
+ return (a == b);
+ }
+
+ if (typeof a === "object" && typeof b === "object") {
+ return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
+ }
+
+ //Straight check
+ return (a === b);
+};
+
+jasmine.Env.prototype.contains_ = function(haystack, needle) {
+ if (jasmine.isArray_(haystack)) {
+ for (var i = 0; i < haystack.length; i++) {
+ if (this.equals_(haystack[i], needle)) return true;
+ }
+ return false;
+ }
+ return haystack.indexOf(needle) >= 0;
+};
+
+jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
+ this.equalityTesters_.push(equalityTester);
+};
+/** No-op base class for Jasmine reporters.
+ *
+ * @constructor
+ */
+jasmine.Reporter = function() {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.Reporter.prototype.reportSpecStarting = function(spec) {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.Reporter.prototype.reportSpecResults = function(spec) {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.Reporter.prototype.log = function(str) {
+};
+
+/**
+ * Blocks are functions with executable code that make up a spec.
+ *
+ * @constructor
+ * @param {jasmine.Env} env
+ * @param {Function} func
+ * @param {jasmine.Spec} spec
+ */
+jasmine.Block = function(env, func, spec) {
+ this.env = env;
+ this.func = func;
+ this.spec = spec;
+};
+
+jasmine.Block.prototype.execute = function(onComplete) {
+ try {
+ this.func.apply(this.spec);
+ } catch (e) {
+ this.spec.fail(e);
+ }
+ onComplete();
+};
+/** JavaScript API reporter.
+ *
+ * @constructor
+ */
+jasmine.JsApiReporter = function() {
+ this.started = false;
+ this.finished = false;
+ this.suites_ = [];
+ this.results_ = {};
+};
+
+jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
+ this.started = true;
+ var suites = runner.topLevelSuites();
+ for (var i = 0; i < suites.length; i++) {
+ var suite = suites[i];
+ this.suites_.push(this.summarize_(suite));
+ }
+};
+
+jasmine.JsApiReporter.prototype.suites = function() {
+ return this.suites_;
+};
+
+jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
+ var isSuite = suiteOrSpec instanceof jasmine.Suite;
+ var summary = {
+ id: suiteOrSpec.id,
+ name: suiteOrSpec.description,
+ type: isSuite ? 'suite' : 'spec',
+ children: []
+ };
+
+ if (isSuite) {
+ var children = suiteOrSpec.children();
+ for (var i = 0; i < children.length; i++) {
+ summary.children.push(this.summarize_(children[i]));
+ }
+ }
+ return summary;
+};
+
+jasmine.JsApiReporter.prototype.results = function() {
+ return this.results_;
+};
+
+jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
+ return this.results_[specId];
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
+ this.finished = true;
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
+ this.results_[spec.id] = {
+ messages: spec.results().getItems(),
+ result: spec.results().failedCount > 0 ? "failed" : "passed"
+ };
+};
+
+//noinspection JSUnusedLocalSymbols
+jasmine.JsApiReporter.prototype.log = function(str) {
+};
+
+jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
+ var results = {};
+ for (var i = 0; i < specIds.length; i++) {
+ var specId = specIds[i];
+ results[specId] = this.summarizeResult_(this.results_[specId]);
+ }
+ return results;
+};
+
+jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
+ var summaryMessages = [];
+ var messagesLength = result.messages.length;
+ for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
+ var resultMessage = result.messages[messageIndex];
+ summaryMessages.push({
+ text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined,
+ passed: resultMessage.passed ? resultMessage.passed() : true,
+ type: resultMessage.type,
+ message: resultMessage.message,
+ trace: {
+ stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
+ }
+ });
+ }
+
+ return {
+ result : result.result,
+ messages : summaryMessages
+ };
+};
+
+/**
+ * @constructor
+ * @param {jasmine.Env} env
+ * @param actual
+ * @param {jasmine.Spec} spec
+ */
+jasmine.Matchers = function(env, actual, spec, opt_isNot) {
+ this.env = env;
+ this.actual = actual;
+ this.spec = spec;
+ this.isNot = opt_isNot || false;
+ this.reportWasCalled_ = false;
+};
+
+// todo: @deprecated as of Jasmine 0.11, remove soon [xw]
+jasmine.Matchers.pp = function(str) {
+ throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
+};
+
+// todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw]
+jasmine.Matchers.prototype.report = function(result, failing_message, details) {
+ throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs");
+};
+
+jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
+ for (var methodName in prototype) {
+ if (methodName == 'report') continue;
+ var orig = prototype[methodName];
+ matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);
+ }
+};
+
+jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
+ return function() {
+ var matcherArgs = jasmine.util.argsToArray(arguments);
+ var result = matcherFunction.apply(this, arguments);
+
+ if (this.isNot) {
+ result = !result;
+ }
+
+ if (this.reportWasCalled_) return result;
+
+ var message;
+ if (!result) {
+ if (this.message) {
+ message = this.message.apply(this, arguments);
+ if (jasmine.isArray_(message)) {
+ message = message[this.isNot ? 1 : 0];
+ }
+ } else {
+ var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
+ message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
+ if (matcherArgs.length > 0) {
+ for (var i = 0; i < matcherArgs.length; i++) {
+ if (i > 0) message += ",";
+ message += " " + jasmine.pp(matcherArgs[i]);
+ }
+ }
+ message += ".";
+ }
+ }
+ var expectationResult = new jasmine.ExpectationResult({
+ matcherName: matcherName,
+ passed: result,
+ expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
+ actual: this.actual,
+ message: message
+ });
+ this.spec.addMatcherResult(expectationResult);
+ return jasmine.undefined;
+ };
+};
+
+
+
+
+/**
+ * toBe: compares the actual to the expected using ===
+ * @param expected
+ */
+jasmine.Matchers.prototype.toBe = function(expected) {
+ return this.actual === expected;
+};
+
+/**
+ * toNotBe: compares the actual to the expected using !==
+ * @param expected
+ * @deprecated as of 1.0. Use not.toBe() instead.
+ */
+jasmine.Matchers.prototype.toNotBe = function(expected) {
+ return this.actual !== expected;
+};
+
+/**
+ * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc.
+ *
+ * @param expected
+ */
+jasmine.Matchers.prototype.toEqual = function(expected) {
+ return this.env.equals_(this.actual, expected);
+};
+
+/**
+ * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
+ * @param expected
+ * @deprecated as of 1.0. Use not.toEqual() instead.
+ */
+jasmine.Matchers.prototype.toNotEqual = function(expected) {
+ return !this.env.equals_(this.actual, expected);
+};
+
+/**
+ * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes
+ * a pattern or a String.
+ *
+ * @param expected
+ */
+jasmine.Matchers.prototype.toMatch = function(expected) {
+ return new RegExp(expected).test(this.actual);
+};
+
+/**
+ * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
+ * @param expected
+ * @deprecated as of 1.0. Use not.toMatch() instead.
+ */
+jasmine.Matchers.prototype.toNotMatch = function(expected) {
+ return !(new RegExp(expected).test(this.actual));
+};
+
+/**
+ * Matcher that compares the actual to jasmine.undefined.
+ */
+jasmine.Matchers.prototype.toBeDefined = function() {
+ return (this.actual !== jasmine.undefined);
+};
+
+/**
+ * Matcher that compares the actual to jasmine.undefined.
+ */
+jasmine.Matchers.prototype.toBeUndefined = function() {
+ return (this.actual === jasmine.undefined);
+};
+
+/**
+ * Matcher that compares the actual to null.
+ */
+jasmine.Matchers.prototype.toBeNull = function() {
+ return (this.actual === null);
+};
+
+/**
+ * Matcher that boolean not-nots the actual.
+ */
+jasmine.Matchers.prototype.toBeTruthy = function() {
+ return !!this.actual;
+};
+
+
+/**
+ * Matcher that boolean nots the actual.
+ */
+jasmine.Matchers.prototype.toBeFalsy = function() {
+ return !this.actual;
+};
+
+
+/**
+ * Matcher that checks to see if the actual, a Jasmine spy, was called.
+ */
+jasmine.Matchers.prototype.toHaveBeenCalled = function() {
+ if (arguments.length > 0) {
+ throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
+ }
+
+ if (!jasmine.isSpy(this.actual)) {
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
+ }
+
+ this.message = function() {
+ return [
+ "Expected spy " + this.actual.identity + " to have been called.",
+ "Expected spy " + this.actual.identity + " not to have been called."
+ ];
+ };
+
+ return this.actual.wasCalled;
+};
+
+/** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
+jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
+
+/**
+ * Matcher that checks to see if the actual, a Jasmine spy, was not called.
+ *
+ * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
+ */
+jasmine.Matchers.prototype.wasNotCalled = function() {
+ if (arguments.length > 0) {
+ throw new Error('wasNotCalled does not take arguments');
+ }
+
+ if (!jasmine.isSpy(this.actual)) {
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
+ }
+
+ this.message = function() {
+ return [
+ "Expected spy " + this.actual.identity + " to not have been called.",
+ "Expected spy " + this.actual.identity + " to have been called."
+ ];
+ };
+
+ return !this.actual.wasCalled;
+};
+
+/**
+ * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
+ *
+ * @example
+ *
+ */
+jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
+ var expectedArgs = jasmine.util.argsToArray(arguments);
+ if (!jasmine.isSpy(this.actual)) {
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
+ }
+ this.message = function() {
+ if (this.actual.callCount === 0) {
+ // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
+ return [
+ "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
+ "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
+ ];
+ } else {
+ return [
+ "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
+ "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
+ ];
+ }
+ };
+
+ return this.env.contains_(this.actual.argsForCall, expectedArgs);
+};
+
+/** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
+jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
+
+/** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
+jasmine.Matchers.prototype.wasNotCalledWith = function() {
+ var expectedArgs = jasmine.util.argsToArray(arguments);
+ if (!jasmine.isSpy(this.actual)) {
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
+ }
+
+ this.message = function() {
+ return [
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
+ ];
+ };
+
+ return !this.env.contains_(this.actual.argsForCall, expectedArgs);
+};
+
+/**
+ * Matcher that checks that the expected item is an element in the actual Array.
+ *
+ * @param {Object} expected
+ */
+jasmine.Matchers.prototype.toContain = function(expected) {
+ return this.env.contains_(this.actual, expected);
+};
+
+/**
+ * Matcher that checks that the expected item is NOT an element in the actual Array.
+ *
+ * @param {Object} expected
+ * @deprecated as of 1.0. Use not.toContain() instead.
+ */
+jasmine.Matchers.prototype.toNotContain = function(expected) {
+ return !this.env.contains_(this.actual, expected);
+};
+
+jasmine.Matchers.prototype.toBeLessThan = function(expected) {
+ return this.actual < expected;
+};
+
+jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
+ return this.actual > expected;
+};
+
+/**
+ * Matcher that checks that the expected item is equal to the actual item
+ * up to a given level of decimal precision (default 2).
+ *
+ * @param {Number} expected
+ * @param {Number} precision
+ */
+jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
+ if (!(precision === 0)) {
+ precision = precision || 2;
+ }
+ var multiplier = Math.pow(10, precision);
+ var actual = Math.round(this.actual * multiplier);
+ expected = Math.round(expected * multiplier);
+ return expected == actual;
+};
+
+/**
+ * Matcher that checks that the expected exception was thrown by the actual.
+ *
+ * @param {String} expected
+ */
+jasmine.Matchers.prototype.toThrow = function(expected) {
+ var result = false;
+ var exception;
+ if (typeof this.actual != 'function') {
+ throw new Error('Actual is not a function');
+ }
+ try {
+ this.actual();
+ } catch (e) {
+ exception = e;
+ }
+ if (exception) {
+ result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
+ }
+
+ var not = this.isNot ? "not " : "";
+
+ this.message = function() {
+ if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
+ return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
+ } else {
+ return "Expected function to throw an exception.";
+ }
+ };
+
+ return result;
+};
+
+jasmine.Matchers.Any = function(expectedClass) {
+ this.expectedClass = expectedClass;
+};
+
+jasmine.Matchers.Any.prototype.jasmineMatches = function(other) {
+ if (this.expectedClass == String) {
+ return typeof other == 'string' || other instanceof String;
+ }
+
+ if (this.expectedClass == Number) {
+ return typeof other == 'number' || other instanceof Number;
+ }
+
+ if (this.expectedClass == Function) {
+ return typeof other == 'function' || other instanceof Function;
+ }
+
+ if (this.expectedClass == Object) {
+ return typeof other == 'object';
+ }
+
+ return other instanceof this.expectedClass;
+};
+
+jasmine.Matchers.Any.prototype.jasmineToString = function() {
+ return '<jasmine.any(' + this.expectedClass + ')>';
+};
+
+jasmine.Matchers.ObjectContaining = function (sample) {
+ this.sample = sample;
+};
+
+jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
+ mismatchKeys = mismatchKeys || [];
+ mismatchValues = mismatchValues || [];
+
+ var env = jasmine.getEnv();
+
+ var hasKey = function(obj, keyName) {
+ return obj != null && obj[keyName] !== jasmine.undefined;
+ };
+
+ for (var property in this.sample) {
+ if (!hasKey(other, property) && hasKey(this.sample, property)) {
+ mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
+ }
+ else if (!env.equals_(this.sample[property], other[property], mismatchKeys, mismatchValues)) {
+ mismatchValues.push("'" + property + "' was '" + (other[property] ? jasmine.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? jasmine.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual.");
+ }
+ }
+
+ return (mismatchKeys.length === 0 && mismatchValues.length === 0);
+};
+
+jasmine.Matchers.ObjectContaining.prototype.jasmineToString = function () {
+ return "<jasmine.objectContaining(" + jasmine.pp(this.sample) + ")>";
+};
+// Mock setTimeout, clearTimeout
+// Contributed by Pivotal Computer Systems, www.pivotalsf.com
+
+jasmine.FakeTimer = function() {
+ this.reset();
+
+ var self = this;
+ self.setTimeout = function(funcToCall, millis) {
+ self.timeoutsMade++;
+ self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
+ return self.timeoutsMade;
+ };
+
+ self.setInterval = function(funcToCall, millis) {
+ self.timeoutsMade++;
+ self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
+ return self.timeoutsMade;
+ };
+
+ self.clearTimeout = function(timeoutKey) {
+ self.scheduledFunctions[timeoutKey] = jasmine.undefined;
+ };
+
+ self.clearInterval = function(timeoutKey) {
+ self.scheduledFunctions[timeoutKey] = jasmine.undefined;
+ };
+
+};
+
+jasmine.FakeTimer.prototype.reset = function() {
+ this.timeoutsMade = 0;
+ this.scheduledFunctions = {};
+ this.nowMillis = 0;
+};
+
+jasmine.FakeTimer.prototype.tick = function(millis) {
+ var oldMillis = this.nowMillis;
+ var newMillis = oldMillis + millis;
+ this.runFunctionsWithinRange(oldMillis, newMillis);
+ this.nowMillis = newMillis;
+};
+
+jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
+ var scheduledFunc;
+ var funcsToRun = [];
+ for (var timeoutKey in this.scheduledFunctions) {
+ scheduledFunc = this.scheduledFunctions[timeoutKey];
+ if (scheduledFunc != jasmine.undefined &&
+ scheduledFunc.runAtMillis >= oldMillis &&
+ scheduledFunc.runAtMillis <= nowMillis) {
+ funcsToRun.push(scheduledFunc);
+ this.scheduledFunctions[timeoutKey] = jasmine.undefined;
+ }
+ }
+
+ if (funcsToRun.length > 0) {
+ funcsToRun.sort(function(a, b) {
+ return a.runAtMillis - b.runAtMillis;
+ });
+ for (var i = 0; i < funcsToRun.length; ++i) {
+ try {
+ var funcToRun = funcsToRun[i];
+ this.nowMillis = funcToRun.runAtMillis;
+ funcToRun.funcToCall();
+ if (funcToRun.recurring) {
+ this.scheduleFunction(funcToRun.timeoutKey,
+ funcToRun.funcToCall,
+ funcToRun.millis,
+ true);
+ }
+ } catch(e) {
+ }
+ }
+ this.runFunctionsWithinRange(oldMillis, nowMillis);
+ }
+};
+
+jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
+ this.scheduledFunctions[timeoutKey] = {
+ runAtMillis: this.nowMillis + millis,
+ funcToCall: funcToCall,
+ recurring: recurring,
+ timeoutKey: timeoutKey,
+ millis: millis
+ };
+};
+
+/**
+ * @namespace
+ */
+jasmine.Clock = {
+ defaultFakeTimer: new jasmine.FakeTimer(),
+
+ reset: function() {
+ jasmine.Clock.assertInstalled();
+ jasmine.Clock.defaultFakeTimer.reset();
+ },
+
+ tick: function(millis) {
+ jasmine.Clock.assertInstalled();
+ jasmine.Clock.defaultFakeTimer.tick(millis);
+ },
+
+ runFunctionsWithinRange: function(oldMillis, nowMillis) {
+ jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
+ },
+
+ scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
+ jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
+ },
+
+ useMock: function() {
+ if (!jasmine.Clock.isInstalled()) {
+ var spec = jasmine.getEnv().currentSpec;
+ spec.after(jasmine.Clock.uninstallMock);
+
+ jasmine.Clock.installMock();
+ }
+ },
+
+ installMock: function() {
+ jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
+ },
+
+ uninstallMock: function() {
+ jasmine.Clock.assertInstalled();
+ jasmine.Clock.installed = jasmine.Clock.real;
+ },
+
+ real: {
+ setTimeout: jasmine.getGlobal().setTimeout,
+ clearTimeout: jasmine.getGlobal().clearTimeout,
+ setInterval: jasmine.getGlobal().setInterval,
+ clearInterval: jasmine.getGlobal().clearInterval
+ },
+
+ assertInstalled: function() {
+ if (!jasmine.Clock.isInstalled()) {
+ throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
+ }
+ },
+
+ isInstalled: function() {
+ return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
+ },
+
+ installed: null
+};
+jasmine.Clock.installed = jasmine.Clock.real;
+
+//else for IE support
+jasmine.getGlobal().setTimeout = function(funcToCall, millis) {
+ if (jasmine.Clock.installed.setTimeout.apply) {
+ return jasmine.Clock.installed.setTimeout.apply(this, arguments);
+ } else {
+ return jasmine.Clock.installed.setTimeout(funcToCall, millis);
+ }
+};
+
+jasmine.getGlobal().setInterval = function(funcToCall, millis) {
+ if (jasmine.Clock.installed.setInterval.apply) {
+ return jasmine.Clock.installed.setInterval.apply(this, arguments);
+ } else {
+ return jasmine.Clock.installed.setInterval(funcToCall, millis);
+ }
+};
+
+jasmine.getGlobal().clearTimeout = function(timeoutKey) {
+ if (jasmine.Clock.installed.clearTimeout.apply) {
+ return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
+ } else {
+ return jasmine.Clock.installed.clearTimeout(timeoutKey);
+ }
+};
+
+jasmine.getGlobal().clearInterval = function(timeoutKey) {
+ if (jasmine.Clock.installed.clearTimeout.apply) {
+ return jasmine.Clock.installed.clearInterval.apply(this, arguments);
+ } else {
+ return jasmine.Clock.installed.clearInterval(timeoutKey);
+ }
+};
+
+/**
+ * @constructor
+ */
+jasmine.MultiReporter = function() {
+ this.subReporters_ = [];
+};
+jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
+
+jasmine.MultiReporter.prototype.addReporter = function(reporter) {
+ this.subReporters_.push(reporter);
+};
+
+(function() {
+ var functionNames = [
+ "reportRunnerStarting",
+ "reportRunnerResults",
+ "reportSuiteResults",
+ "reportSpecStarting",
+ "reportSpecResults",
+ "log"
+ ];
+ for (var i = 0; i < functionNames.length; i++) {
+ var functionName = functionNames[i];
+ jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
+ return function() {
+ for (var j = 0; j < this.subReporters_.length; j++) {
+ var subReporter = this.subReporters_[j];
+ if (subReporter[functionName]) {
+ subReporter[functionName].apply(subReporter, arguments);
+ }
+ }
+ };
+ })(functionName);
+ }
+})();
+/**
+ * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
+ *
+ * @constructor
+ */
+jasmine.NestedResults = function() {
+ /**
+ * The total count of results
+ */
+ this.totalCount = 0;
+ /**
+ * Number of passed results
+ */
+ this.passedCount = 0;
+ /**
+ * Number of failed results
+ */
+ this.failedCount = 0;
+ /**
+ * Was this suite/spec skipped?
+ */
+ this.skipped = false;
+ /**
+ * @ignore
+ */
+ this.items_ = [];
+};
+
+/**
+ * Roll up the result counts.
+ *
+ * @param result
+ */
+jasmine.NestedResults.prototype.rollupCounts = function(result) {
+ this.totalCount += result.totalCount;
+ this.passedCount += result.passedCount;
+ this.failedCount += result.failedCount;
+};
+
+/**
+ * Adds a log message.
+ * @param values Array of message parts which will be concatenated later.
+ */
+jasmine.NestedResults.prototype.log = function(values) {
+ this.items_.push(new jasmine.MessageResult(values));
+};
+
+/**
+ * Getter for the results: message & results.
+ */
+jasmine.NestedResults.prototype.getItems = function() {
+ return this.items_;
+};
+
+/**
+ * Adds a result, tracking counts (total, passed, & failed)
+ * @param {jasmine.ExpectationResult|jasmine.NestedResults} result
+ */
+jasmine.NestedResults.prototype.addResult = function(result) {
+ if (result.type != 'log') {
+ if (result.items_) {
+ this.rollupCounts(result);
+ } else {
+ this.totalCount++;
+ if (result.passed()) {
+ this.passedCount++;
+ } else {
+ this.failedCount++;
+ }
+ }
+ }
+ this.items_.push(result);
+};
+
+/**
+ * @returns {Boolean} True if <b>everything</b> below passed
+ */
+jasmine.NestedResults.prototype.passed = function() {
+ return this.passedCount === this.totalCount;
+};
+/**
+ * Base class for pretty printing for expectation results.
+ */
+jasmine.PrettyPrinter = function() {
+ this.ppNestLevel_ = 0;
+};
+
+/**
+ * Formats a value in a nice, human-readable string.
+ *
+ * @param value
+ */
+jasmine.PrettyPrinter.prototype.format = function(value) {
+ if (this.ppNestLevel_ > 40) {
+ throw new Error('jasmine.PrettyPrinter: format() nested too deeply!');
+ }
+
+ this.ppNestLevel_++;
+ try {
+ if (value === jasmine.undefined) {
+ this.emitScalar('undefined');
+ } else if (value === null) {
+ this.emitScalar('null');
+ } else if (value === jasmine.getGlobal()) {
+ this.emitScalar('<global>');
+ } else if (value.jasmineToString) {
+ this.emitScalar(value.jasmineToString());
+ } else if (typeof value === 'string') {
+ this.emitString(value);
+ } else if (jasmine.isSpy(value)) {
+ this.emitScalar("spy on " + value.identity);
+ } else if (value instanceof RegExp) {
+ this.emitScalar(value.toString());
+ } else if (typeof value === 'function') {
+ this.emitScalar('Function');
+ } else if (typeof value.nodeType === 'number') {
+ this.emitScalar('HTMLNode');
+ } else if (value instanceof Date) {
+ this.emitScalar('Date(' + value + ')');
+ } else if (value.__Jasmine_been_here_before__) {
+ this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
+ } else if (jasmine.isArray_(value) || typeof value == 'object') {
+ value.__Jasmine_been_here_before__ = true;
+ if (jasmine.isArray_(value)) {
+ this.emitArray(value);
+ } else {
+ this.emitObject(value);
+ }
+ delete value.__Jasmine_been_here_before__;
+ } else {
+ this.emitScalar(value.toString());
+ }
+ } finally {
+ this.ppNestLevel_--;
+ }
+};
+
+jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
+ for (var property in obj) {
+ if (property == '__Jasmine_been_here_before__') continue;
+ fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
+ obj.__lookupGetter__(property) !== null) : false);
+ }
+};
+
+jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
+jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
+jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
+jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
+
+jasmine.StringPrettyPrinter = function() {
+ jasmine.PrettyPrinter.call(this);
+
+ this.string = '';
+};
+jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter);
+
+jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
+ this.append(value);
+};
+
+jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
+ this.append("'" + value + "'");
+};
+
+jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
+ this.append('[ ');
+ for (var i = 0; i < array.length; i++) {
+ if (i > 0) {
+ this.append(', ');
+ }
+ this.format(array[i]);
+ }
+ this.append(' ]');
+};
+
+jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) {
+ var self = this;
+ this.append('{ ');
+ var first = true;
+
+ this.iterateObject(obj, function(property, isGetter) {
+ if (first) {
+ first = false;
+ } else {
+ self.append(', ');
+ }
+
+ self.append(property);
+ self.append(' : ');
+ if (isGetter) {
+ self.append('<getter>');
+ } else {
+ self.format(obj[property]);
+ }
+ });
+
+ this.append(' }');
+};
+
+jasmine.StringPrettyPrinter.prototype.append = function(value) {
+ this.string += value;
+};
+jasmine.Queue = function(env) {
+ this.env = env;
+ this.blocks = [];
+ this.running = false;
+ this.index = 0;
+ this.offset = 0;
+ this.abort = false;
+};
+
+jasmine.Queue.prototype.addBefore = function(block) {
+ this.blocks.unshift(block);
+};
+
+jasmine.Queue.prototype.add = function(block) {
+ this.blocks.push(block);
+};
+
+jasmine.Queue.prototype.insertNext = function(block) {
+ this.blocks.splice((this.index + this.offset + 1), 0, block);
+ this.offset++;
+};
+
+jasmine.Queue.prototype.start = function(onComplete) {
+ this.running = true;
+ this.onComplete = onComplete;
+ this.next_();
+};
+
+jasmine.Queue.prototype.isRunning = function() {
+ return this.running;
+};
+
+jasmine.Queue.LOOP_DONT_RECURSE = true;
+
+jasmine.Queue.prototype.next_ = function() {
+ var self = this;
+ var goAgain = true;
+
+ while (goAgain) {
+ goAgain = false;
+
+ if (self.index < self.blocks.length && !this.abort) {
+ var calledSynchronously = true;
+ var completedSynchronously = false;
+
+ var onComplete = function () {
+ if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
+ completedSynchronously = true;
+ return;
+ }
+
+ if (self.blocks[self.index].abort) {
+ self.abort = true;
+ }
+
+ self.offset = 0;
+ self.index++;
+
+ var now = new Date().getTime();
+ if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
+ self.env.lastUpdate = now;
+ self.env.setTimeout(function() {
+ self.next_();
+ }, 0);
+ } else {
+ if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
+ goAgain = true;
+ } else {
+ self.next_();
+ }
+ }
+ };
+ self.blocks[self.index].execute(onComplete);
+
+ calledSynchronously = false;
+ if (completedSynchronously) {
+ onComplete();
+ }
+
+ } else {
+ self.running = false;
+ if (self.onComplete) {
+ self.onComplete();
+ }
+ }
+ }
+};
+
+jasmine.Queue.prototype.results = function() {
+ var results = new jasmine.NestedResults();
+ for (var i = 0; i < this.blocks.length; i++) {
+ if (this.blocks[i].results) {
+ results.addResult(this.blocks[i].results());
+ }
+ }
+ return results;
+};
+
+
+/**
+ * Runner
+ *
+ * @constructor
+ * @param {jasmine.Env} env
+ */
+jasmine.Runner = function(env) {
+ var self = this;
+ self.env = env;
+ self.queue = new jasmine.Queue(env);
+ self.before_ = [];
+ self.after_ = [];
+ self.suites_ = [];
+};
+
+jasmine.Runner.prototype.execute = function() {
+ var self = this;
+ if (self.env.reporter.reportRunnerStarting) {
+ self.env.reporter.reportRunnerStarting(this);
+ }
+ self.queue.start(function () {
+ self.finishCallback();
+ });
+};
+
+jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
+ beforeEachFunction.typeName = 'beforeEach';
+ this.before_.splice(0,0,beforeEachFunction);
+};
+
+jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
+ afterEachFunction.typeName = 'afterEach';
+ this.after_.splice(0,0,afterEachFunction);
+};
+
+
+jasmine.Runner.prototype.finishCallback = function() {
+ this.env.reporter.reportRunnerResults(this);
+};
+
+jasmine.Runner.prototype.addSuite = function(suite) {
+ this.suites_.push(suite);
+};
+
+jasmine.Runner.prototype.add = function(block) {
+ if (block instanceof jasmine.Suite) {
+ this.addSuite(block);
+ }
+ this.queue.add(block);
+};
+
+jasmine.Runner.prototype.specs = function () {
+ var suites = this.suites();
+ var specs = [];
+ for (var i = 0; i < suites.length; i++) {
+ specs = specs.concat(suites[i].specs());
+ }
+ return specs;
+};
+
+jasmine.Runner.prototype.suites = function() {
+ return this.suites_;
+};
+
+jasmine.Runner.prototype.topLevelSuites = function() {
+ var topLevelSuites = [];
+ for (var i = 0; i < this.suites_.length; i++) {
+ if (!this.suites_[i].parentSuite) {
+ topLevelSuites.push(this.suites_[i]);
+ }
+ }
+ return topLevelSuites;
+};
+
+jasmine.Runner.prototype.results = function() {
+ return this.queue.results();
+};
+/**
+ * Internal representation of a Jasmine specification, or test.
+ *
+ * @constructor
+ * @param {jasmine.Env} env
+ * @param {jasmine.Suite} suite
+ * @param {String} description
+ */
+jasmine.Spec = function(env, suite, description) {
+ if (!env) {
+ throw new Error('jasmine.Env() required');
+ }
+ if (!suite) {
+ throw new Error('jasmine.Suite() required');
+ }
+ var spec = this;
+ spec.id = env.nextSpecId ? env.nextSpecId() : null;
+ spec.env = env;
+ spec.suite = suite;
+ spec.description = description;
+ spec.queue = new jasmine.Queue(env);
+
+ spec.afterCallbacks = [];
+ spec.spies_ = [];
+
+ spec.results_ = new jasmine.NestedResults();
+ spec.results_.description = description;
+ spec.matchersClass = null;
+};
+
+jasmine.Spec.prototype.getFullName = function() {
+ return this.suite.getFullName() + ' ' + this.description + '.';
+};
+
+
+jasmine.Spec.prototype.results = function() {
+ return this.results_;
+};
+
+/**
+ * All parameters are pretty-printed and concatenated together, then written to the spec's output.
+ *
+ * Be careful not to leave calls to <code>jasmine.log</code> in production code.
+ */
+jasmine.Spec.prototype.log = function() {
+ return this.results_.log(arguments);
+};
+
+jasmine.Spec.prototype.runs = function (func) {
+ var block = new jasmine.Block(this.env, func, this);
+ this.addToQueue(block);
+ return this;
+};
+
+jasmine.Spec.prototype.addToQueue = function (block) {
+ if (this.queue.isRunning()) {
+ this.queue.insertNext(block);
+ } else {
+ this.queue.add(block);
+ }
+};
+
+/**
+ * @param {jasmine.ExpectationResult} result
+ */
+jasmine.Spec.prototype.addMatcherResult = function(result) {
+ this.results_.addResult(result);
+};
+
+jasmine.Spec.prototype.expect = function(actual) {
+ var positive = new (this.getMatchersClass_())(this.env, actual, this);
+ positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
+ return positive;
+};
+
+/**
+ * Waits a fixed time period before moving to the next block.
+ *
+ * @deprecated Use waitsFor() instead
+ * @param {Number} timeout milliseconds to wait
+ */
+jasmine.Spec.prototype.waits = function(timeout) {
+ var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
+ this.addToQueue(waitsFunc);
+ return this;
+};
+
+/**
+ * Waits for the latchFunction to return true before proceeding to the next block.
+ *
+ * @param {Function} latchFunction
+ * @param {String} optional_timeoutMessage
+ * @param {Number} optional_timeout
+ */
+jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
+ var latchFunction_ = null;
+ var optional_timeoutMessage_ = null;
+ var optional_timeout_ = null;
+
+ for (var i = 0; i < arguments.length; i++) {
+ var arg = arguments[i];
+ switch (typeof arg) {
+ case 'function':
+ latchFunction_ = arg;
+ break;
+ case 'string':
+ optional_timeoutMessage_ = arg;
+ break;
+ case 'number':
+ optional_timeout_ = arg;
+ break;
+ }
+ }
+
+ var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
+ this.addToQueue(waitsForFunc);
+ return this;
+};
+
+jasmine.Spec.prototype.fail = function (e) {
+ var expectationResult = new jasmine.ExpectationResult({
+ passed: false,
+ message: e ? jasmine.util.formatException(e) : 'Exception',
+ trace: { stack: e.stack }
+ });
+ this.results_.addResult(expectationResult);
+};
+
+jasmine.Spec.prototype.getMatchersClass_ = function() {
+ return this.matchersClass || this.env.matchersClass;
+};
+
+jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
+ var parent = this.getMatchersClass_();
+ var newMatchersClass = function() {
+ parent.apply(this, arguments);
+ };
+ jasmine.util.inherit(newMatchersClass, parent);
+ jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
+ this.matchersClass = newMatchersClass;
+};
+
+jasmine.Spec.prototype.finishCallback = function() {
+ this.env.reporter.reportSpecResults(this);
+};
+
+jasmine.Spec.prototype.finish = function(onComplete) {
+ this.removeAllSpies();
+ this.finishCallback();
+ if (onComplete) {
+ onComplete();
+ }
+};
+
+jasmine.Spec.prototype.after = function(doAfter) {
+ if (this.queue.isRunning()) {
+ this.queue.add(new jasmine.Block(this.env, doAfter, this));
+ } else {
+ this.afterCallbacks.unshift(doAfter);
+ }
+};
+
+jasmine.Spec.prototype.execute = function(onComplete) {
+ var spec = this;
+ if (!spec.env.specFilter(spec)) {
+ spec.results_.skipped = true;
+ spec.finish(onComplete);
+ return;
+ }
+
+ this.env.reporter.reportSpecStarting(this);
+
+ spec.env.currentSpec = spec;
+
+ spec.addBeforesAndAftersToQueue();
+
+ spec.queue.start(function () {
+ spec.finish(onComplete);
+ });
+};
+
+jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
+ var runner = this.env.currentRunner();
+ var i;
+
+ for (var suite = this.suite; suite; suite = suite.parentSuite) {
+ for (i = 0; i < suite.before_.length; i++) {
+ this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
+ }
+ }
+ for (i = 0; i < runner.before_.length; i++) {
+ this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
+ }
+ for (i = 0; i < this.afterCallbacks.length; i++) {
+ this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
+ }
+ for (suite = this.suite; suite; suite = suite.parentSuite) {
+ for (i = 0; i < suite.after_.length; i++) {
+ this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
+ }
+ }
+ for (i = 0; i < runner.after_.length; i++) {
+ this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
+ }
+};
+
+jasmine.Spec.prototype.explodes = function() {
+ throw 'explodes function should not have been called';
+};
+
+jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
+ if (obj == jasmine.undefined) {
+ throw "spyOn could not find an object to spy upon for " + methodName + "()";
+ }
+
+ if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
+ throw methodName + '() method does not exist';
+ }
+
+ if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
+ throw new Error(methodName + ' has already been spied upon');
+ }
+
+ var spyObj = jasmine.createSpy(methodName);
+
+ this.spies_.push(spyObj);
+ spyObj.baseObj = obj;
+ spyObj.methodName = methodName;
+ spyObj.originalValue = obj[methodName];
+
+ obj[methodName] = spyObj;
+
+ return spyObj;
+};
+
+jasmine.Spec.prototype.removeAllSpies = function() {
+ for (var i = 0; i < this.spies_.length; i++) {
+ var spy = this.spies_[i];
+ spy.baseObj[spy.methodName] = spy.originalValue;
+ }
+ this.spies_ = [];
+};
+
+/**
+ * Internal representation of a Jasmine suite.
+ *
+ * @constructor
+ * @param {jasmine.Env} env
+ * @param {String} description
+ * @param {Function} specDefinitions
+ * @param {jasmine.Suite} parentSuite
+ */
+jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
+ var self = this;
+ self.id = env.nextSuiteId ? env.nextSuiteId() : null;
+ self.description = description;
+ self.queue = new jasmine.Queue(env);
+ self.parentSuite = parentSuite;
+ self.env = env;
+ self.before_ = [];
+ self.after_ = [];
+ self.children_ = [];
+ self.suites_ = [];
+ self.specs_ = [];
+};
+
+jasmine.Suite.prototype.getFullName = function() {
+ var fullName = this.description;
+ for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
+ fullName = parentSuite.description + ' ' + fullName;
+ }
+ return fullName;
+};
+
+jasmine.Suite.prototype.finish = function(onComplete) {
+ this.env.reporter.reportSuiteResults(this);
+ this.finished = true;
+ if (typeof(onComplete) == 'function') {
+ onComplete();
+ }
+};
+
+jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
+ beforeEachFunction.typeName = 'beforeEach';
+ this.before_.unshift(beforeEachFunction);
+};
+
+jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
+ afterEachFunction.typeName = 'afterEach';
+ this.after_.unshift(afterEachFunction);
+};
+
+jasmine.Suite.prototype.results = function() {
+ return this.queue.results();
+};
+
+jasmine.Suite.prototype.add = function(suiteOrSpec) {
+ this.children_.push(suiteOrSpec);
+ if (suiteOrSpec instanceof jasmine.Suite) {
+ this.suites_.push(suiteOrSpec);
+ this.env.currentRunner().addSuite(suiteOrSpec);
+ } else {
+ this.specs_.push(suiteOrSpec);
+ }
+ this.queue.add(suiteOrSpec);
+};
+
+jasmine.Suite.prototype.specs = function() {
+ return this.specs_;
+};
+
+jasmine.Suite.prototype.suites = function() {
+ return this.suites_;
+};
+
+jasmine.Suite.prototype.children = function() {
+ return this.children_;
+};
+
+jasmine.Suite.prototype.execute = function(onComplete) {
+ var self = this;
+ this.queue.start(function () {
+ self.finish(onComplete);
+ });
+};
+jasmine.WaitsBlock = function(env, timeout, spec) {
+ this.timeout = timeout;
+ jasmine.Block.call(this, env, null, spec);
+};
+
+jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
+
+jasmine.WaitsBlock.prototype.execute = function (onComplete) {
+ if (jasmine.VERBOSE) {
+ this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
+ }
+ this.env.setTimeout(function () {
+ onComplete();
+ }, this.timeout);
+};
+/**
+ * A block which waits for some condition to become true, with timeout.
+ *
+ * @constructor
+ * @extends jasmine.Block
+ * @param {jasmine.Env} env The Jasmine environment.
+ * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
+ * @param {Function} latchFunction A function which returns true when the desired condition has been met.
+ * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
+ * @param {jasmine.Spec} spec The Jasmine spec.
+ */
+jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
+ this.timeout = timeout || env.defaultTimeoutInterval;
+ this.latchFunction = latchFunction;
+ this.message = message;
+ this.totalTimeSpentWaitingForLatch = 0;
+ jasmine.Block.call(this, env, null, spec);
+};
+jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
+
+jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
+
+jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
+ if (jasmine.VERBOSE) {
+ this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
+ }
+ var latchFunctionResult;
+ try {
+ latchFunctionResult = this.latchFunction.apply(this.spec);
+ } catch (e) {
+ this.spec.fail(e);
+ onComplete();
+ return;
+ }
+
+ if (latchFunctionResult) {
+ onComplete();
+ } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
+ var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
+ this.spec.fail({
+ name: 'timeout',
+ message: message
+ });
+
+ this.abort = true;
+ onComplete();
+ } else {
+ this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
+ var self = this;
+ this.env.setTimeout(function() {
+ self.execute(onComplete);
+ }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
+ }
+};
+
+jasmine.version_= {
+ "major": 1,
+ "minor": 2,
+ "build": 0,
+ "revision": 1337005947
+};
diff --git a/make b/make
index 1d25648..a619cf5 100755
--- a/make
+++ b/make
@@ -8,13 +8,25 @@ file="yaml.js"
echo Compiling $file ...
+echo " - LICENSE"
+
+echo "/*" >> $file
+cat LICENSE >> $file
+echo "\n*/" >> $file
+
+echo " - YamlParseException.js"
+$cmd com/jeremyfa/yaml/YamlParseException.js >> $file
echo " - Yaml.js"
$cmd com/jeremyfa/yaml/Yaml.js >> $file
echo " - YamlInline.js"
$cmd com/jeremyfa/yaml/YamlInline.js >> $file
echo " - YamlParser.js"
$cmd com/jeremyfa/yaml/YamlParser.js >> $file
+echo " - YamlEscaper.js"
+$cmd com/jeremyfa/yaml/YamlEscaper.js >> $file
+echo " - YamlUnescaper.js"
+$cmd com/jeremyfa/yaml/YamlUnescaper.js >> $file
echo " - YamlDumper.js"
$cmd com/jeremyfa/yaml/YamlDumper.js >> $file
-echo $file compiled. \ No newline at end of file
+echo $file compiled.
diff --git a/tests.html b/tests.html
new file mode 100644
index 0000000..ed59766
--- /dev/null
+++ b/tests.html
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <title>Jasmine YAML tests</title>
+
+ <link rel="shortcut icon" type="image/png" href="libs/jasmine-1.2.0/jasmine_favicon.png">
+ <link rel="stylesheet" type="text/css" href="libs/jasmine-1.2.0/jasmine.css">
+ <script type="text/javascript" src="libs/jasmine-1.2.0/jasmine.js"></script>
+ <script type="text/javascript" src="libs/jasmine-1.2.0/jasmine-html.js"></script>
+
+ <!-- include source files here... -->
+ <script type="text/javascript" src="yaml.js"></script>
+ <script type="text/javascript" src="libs/jasmine-1.2.0/YamlTests.js"></script>
+ <!-- include spec files here... -->
+ <script type="text/javascript" src="libs/jasmine-1.2.0/YamlSpec.js"></script>
+
+ <script type="text/javascript">
+ (function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+ })();
+ </script>
+
+</head>
+
+<body>
+</body>
+</html>
diff --git a/yaml.js b/yaml.js
index 549bdcc..924e888 100644
--- a/yaml.js
+++ b/yaml.js
@@ -1 +1,22 @@
-var Yaml=function(){};Yaml.prototype={spec:"1.2",setSpecVersion:function(a){if(a!="1.1"&&a!="1.2"){throw new InvalidArgumentException("Version "+a+" of the YAML specifications is not supported")}this.spec=a},getSpecVersion:function(){return this.spec},loadFile:function(a,b){if(b==undefined){input=this.getFileContents(a);return this.load(input)}this.getFileContents(a,function(c){b(new Yaml().load(c))})},load:function(a){var c=new YamlParser();var b=null;try{b=c.parse(a)}catch(d){if(d.name!=undefined&&d.name.toString=="TypeError"){throw d}throw"Syntax error: "+d.message}return b},dump:function(b,a){if(a==undefined){a=2}yaml=new YamlDumper();return yaml.dump(b,a)},getXHR:function(){if(window.XMLHttpRequest){return new XMLHttpRequest()}if(window.ActiveXObject){var c=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];for(var a=0;a<4;a++){try{return new ActiveXObject(c[a])}catch(b){}}}return null},getFileContents:function(a,c){var b=this.getXHR();if(c==undefined){b.open("GET",a,false);b.send(null);if(b.status==200||b.status==0){return b.responseText}return null}b.onreadystatechange=function(){if(b.readyState==4){if(b.status==200||b.status==0){c(b.responseText)}else{c(null)}}};b.open("GET",a,true);b.send(null)}};var YAML={encode:function(a){return new Yaml().dump(a)},decode:function(a){return new Yaml().load(a)},load:function(a,b){return new Yaml().loadFile(a,b)}};if(typeof(InvalidArgumentException)=="undefined"){InvalidArgumentException=function(a){this.name="InvalidArgumentException";this.message=a}};var YamlInline=function(){};YamlInline.prototype={i:null,load:function(b){var a=null;b=this.trim(b);if(0==b.length){return""}switch(b.charAt(0)){case"[":a=this.parseSequence(b);break;case"{":a=this.parseMapping(b);break;default:a=this.parseScalar(b)}return a},dump:function(d){var b;var a;var c=new Yaml();if("1.1"==c.getSpecVersion()){b=["true","on","+","yes","y"];a=["false","off","-","no","n"]}else{b=["true"];a=["false"]}if(typeof(d)=="object"&&null!=d){return this.dumpObject(d)}if(undefined==d||null==d){return"null"}if(typeof(d)=="boolean"){return d?"true":"false"}if(/^\d+/.test(d)){return typeof(d)=="string"?"'"+d+"'":parseInt(d)}if(this.isNumeric(d)){return typeof(d)=="string"?"'"+d+"'":parseFloat(d)}if(typeof(d)=="number"){return d==Infinity?".Inf":(d==-Infinity?"-.Inf":(isNaN(d)?".NAN":d))}if((d+"").indexOf("\n")!=-1||(d+"").indexOf("\r")!=-1){return'"'+d.split('"').join('\\"').split("\n").join("\\n").split("\r").join("\\r")+'"'}if((/[\s\'"\:\{\}\[\],&\*\#\?]/.test(d))||(/^[-?|<>=!%@`]/.test(d))){return"'"+d.split("'").join("''")+"'"}if(""==d){return"''"}if(this.getTimestampRegex().test(d)){return"'"+d+"'"}if(this.inArray(d.toLowerCase(),b)){return"'"+d+"'"}if(this.inArray(d.toLowerCase(),a)){return"'"+d+"'"}if(this.inArray(d.toLowerCase(),["null","~"])){return"'"+d+"'"}return d},dumpObject:function(e){var d=this.getKeys(e);var b=null;var c;var a=d.length;if(e instanceof Array){b=[];for(c=0;c<a;c++){b.push(this.dump(e[d[c]]))}return"["+b.join(", ")+"]"}b=[];for(c=0;c<a;c++){b.push(this.dump(d[c])+": "+this.dump(e[d[c]]))}return"{ "+b.join(", ")+" }"},parseScalar:function(b,g,e,d,f){if(g==undefined){g=null}if(e==undefined){e=['"',"'"]}if(d==undefined){d=0}if(f==undefined){f=true}var a=null;var h=null;var c=null;if(this.inArray(b[d],e)){a=this.parseQuotedScalar(b,d);d=this.i}else{if(!g){a=(b+"").substring(d);d+=a.length;h=a.indexOf(" #");if(h!=-1){a=a.substr(0,h).replace(/\s+$/g,"")}}else{if(c=new RegExp("^(.+?)("+g.join("|")+")").exec((b+"").substring(d))){a=c[1];d+=a.length}else{throw new InvalidArgumentException("Malformed inline YAML string ("+b+").")}}a=f?this.evaluateScalar(a):a}this.i=d;return a},parseQuotedScalar:function(b,d){var c=null;if(!(c=new RegExp("^"+YamlInline.REGEX_QUOTED_STRING).exec((b+"").substring(d)))){throw new InvalidArgumentException("Malformed inline YAML string ("+(b+"").substring(d)+").")}var a=c[0].substr(1,c[0].length-2);if('"'==(b+"").charAt(d)){a=a.split('\\"').join('"').split("\\n").join("\n").split("\\r").join("\r")}else{a=a.split("''").join("'")}d+=c[0].length;this.i=d;return a},parseSequence:function(g,c){if(c==undefined){c=0}var b=[];var a=g.length;c+=1;while(c<a){switch(g.charAt(c)){case"[":b.push(this.parseSequence(g,c));c=this.i;break;case"{":b.push(this.parseMapping(g,c));c=this.i;break;case"]":this.i=c;return b;case",":case" ":break;default:isQuoted=this.inArray(g.charAt(c),['"',"'"]);var d=this.parseScalar(g,[",","]"],['"',"'"],c);c=this.i;if(!isQuoted&&(d+"").indexOf(": ")!=-1){try{d=this.parseMapping("{"+d+"}")}catch(f){if(!(f instanceof InvalidArgumentException)){throw f}}}b.push(d);c--}c++}throw new InvalidArgumentException("Malformed inline YAML string "+g)},parseMapping:function(d,f){if(f==undefined){f=0}var c={};var a=d.length;f+=1;var b=false;var g=false;while(f<a){g=false;switch(d.charAt(f)){case" ":case",":f++;g=true;break;case"}":this.i=f;return c}if(g){continue}var e=this.parseScalar(d,[":"," "],['"',"'"],f,false);f=this.i;b=false;while(f<a){switch(d.charAt(f)){case"[":c[e]=this.parseSequence(d,f);f=this.i;b=true;break;case"{":c[e]=this.parseMapping(d,f);f=this.i;b=true;break;case":":case" ":break;default:c[e]=this.parseScalar(d,[",","}"],['"',"'"],f);f=this.i;b=true;f--}++f;if(b){g=true;break}}if(g){continue}}throw new InvalidArgumentException("Malformed inline YAML string "+d)},evaluateScalar:function(b){b=this.trim(b);var e;var d;var f=new Yaml();if("1.1"==f.getSpecVersion()){e=["true","on","+","yes","y"];d=["false","off","-","no","n"]}else{e=["true"];d=["false"]}var c=null;var a=null;if(("null"==b.toLowerCase())||(""==b)||("~"==b)){return null}if((b+"").indexOf("!str")!=-1){return(""+b).substring(5)}if((b+"").indexOf("! ")!=-1){return parseInt(this.parseScalar((b+"").substring(2)))}if(/^\d+/.test(b)){c=b;a=parseInt(b);return"0"==b.charAt(0)?this.octdec(b):((""+c==""+a)?a:c)}if(this.inArray(b.toLowerCase(),e)){return true}if(this.inArray(b.toLowerCase(),d)){return false}if(this.isNumeric(b)){return"0x"==(b+"").substr(0,2)?hexdec($scalar):floatval($scalar)}if(b.toLowerCase()==".inf"){return Infinity}if(b.toLowerCase()==".nan"){return NaN}if(b.toLowerCase()=="-.inf"){return -Infinity}if(/^(-|\+)?[0-9,]+(\.[0-9]+)?$/.test(b)){return parseFloat(b.split(",").join(""))}if(this.getTimestampRegex().test(b)){return this.strtodate(b)}return""+b},getTimestampRegex:function(){return new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:(?:[Tt]|[ \t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:.([0-9]*))?(?:[ \t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?)?$","gi")},trim:function(a){return(a+"").replace(/^\s+/,"").replace(/\s+$/,"")},isNumeric:function(a){return(a-0)==a&&a.length>0&&a.replace(/\s+/g,"")!=""},inArray:function(c,d){var b;var a=d.length;for(b=0;b<a;b++){if(c==d[b]){return true}}return false},getKeys:function(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(a)}}return b},octdec:function(a){return parseInt((a+"").replace(/[^0-7]/gi,""),8)},hexdec:function(a){a=this.trim(a);if((a+"").substr(0,2)=="0x"){a=(a+"").substring(2)}return parseInt((a+"").replace(/[^a-f0-9]/gi,""),16)},strtodate:function(a){var b=new Date();b.setTime(this.strtotime(a,new Date().getTime()));return b},strtotime:function(o,t){var q,p,i,m="",s="";m=o;m=m.replace(/\s{2,}|^\s|\s$/g," ");m=m.replace(/[\t\r\n]/g,"");if(m=="now"){return(new Date()).getTime()/1000}else{if(!isNaN(s=Date.parse(m))){return(s/1000)}else{if(t){t=new Date(t*1000)}else{t=new Date()}}}m=m.toLowerCase();var r={day:{sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},mon:{jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11}};var v=this.strtotime;var u=function(a){var c=(a[2]&&a[2]=="ago");var d=(d=a[0]=="last"?-1:1)*(c?-1:1);switch(a[0]){case"last":case"next":switch(a[1].substring(0,3)){case"yea":t.setFullYear(t.getFullYear()+d);break;case"mon":t.setMonth(t.getMonth()+d);break;case"wee":t.setDate(t.getDate()+(d*7));break;case"day":t.setDate(t.getDate()+d);break;case"hou":t.setHours(t.getHours()+d);break;case"min":t.setMinutes(t.getMinutes()+d);break;case"sec":t.setSeconds(t.getSeconds()+d);break;default:var e;if(typeof(e=r.day[a[1].substring(0,3)])!="undefined"){var b=e-t.getDay();if(b==0){b=7*d}else{if(b>0){if(a[0]=="last"){b-=7}}else{if(a[0]=="next"){b+=7}}}t.setDate(t.getDate()+b)}}break;default:if(/\d+/.test(a[0])){d*=parseInt(a[0],10);switch(a[1].substring(0,3)){case"yea":t.setFullYear(t.getFullYear()+d);break;case"mon":t.setMonth(t.getMonth()+d);break;case"wee":t.setDate(t.getDate()+(d*7));break;case"day":t.setDate(t.getDate()+d);break;case"hou":t.setHours(t.getHours()+d);break;case"min":t.setMinutes(t.getMinutes()+d);break;case"sec":t.setSeconds(t.getSeconds()+d);break}}else{return false}break}return true};p=m.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(p!=null){if(!p[2]){p[2]="00:00:00"}else{if(!p[3]){p[2]+=":00"}}i=p[1].split(/-/g);for(q in r.mon){if(r.mon[q]==i[1]-1){i[1]=q}}i[0]=parseInt(i[0],10);i[0]=(i[0]>=0&&i[0]<=69)?"20"+(i[0]<10?"0"+i[0]:i[0]+""):(i[0]>=70&&i[0]<=99)?"19"+i[0]:i[0]+"";return parseInt(v(i[2]+" "+i[1]+" "+i[0]+" "+p[2])+(p[4]?p[4]/1000:""),10)}var n="([+-]?\\d+\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)|(last|next)\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))(\\sago)?";p=m.match(new RegExp(n,"gi"));if(p==null){return false}for(q=0;q<p.length;q++){if(!u(p[q].split(" "))){return false}}return(t.getTime()/1000)}};YamlInline.REGEX_QUOTED_STRING="(?:\"(?:[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"|'(?:[^']*(?:''[^']*)*)')";var YamlParser=function(a){this.offset=this.isDefined(a)?a:0};YamlParser.prototype={offset:0,lines:[],currentLineNb:-1,currentLine:"",refs:{},parse:function(m){this.currentLineNb=-1;this.currentLine="";this.lines=this.cleanup(m).split("\n");var u=null;while(this.moveToNextLine()){if(this.isCurrentLineEmpty()){continue}if(/^\t+/.test(this.currentLine)){throw new InvalidArgumentException("A YAML file cannot contain tabs as indentation at line "+(this.getRealCurrentLineNb()+1)+" ("+this.currentLine+")")}var j=false;var r=false;var q=false;var b=null;var a=null;var t=null;var d=null;var e=null;var v=null;var h=null;var p=null;var f=null;if(b=/^\-((\s+)(.+?))?\s*$/.exec(this.currentLine)){if(!this.isDefined(u)){u=[]}if(!(u instanceof Array)){throw new InvalidArgumentException("Non array entry at line "+(this.getRealCurrentLineNb()+1)+".")}b={leadspaces:b[2],value:b[3]};if(this.isDefined(b.value)&&(a=/^&([^ ]+) *(.*)/.exec(b.value))){a={ref:a[1],value:a[2]};j=a.ref;b.value=a.value}if(!this.isDefined(b.value)||""==b.value.split(" ").join("")||this.trim(b.value).charAt(0)=="#"){t=this.getRealCurrentLineNb()+1;d=new YamlParser(t);d.refs=this.refs;u.push(d.parse(this.getNextEmbedBlock()));this.refs=d.refs}else{if(this.isDefined(b.leadspaces)&&" "==b.leadspaces&&(a=new RegExp("^("+YamlInline.REGEX_QUOTED_STRING+"|[^ '\"{].*?) *:(\\s+(.+?))?\\s*$").exec(b.value))){a={key:a[1],value:a[3]};t=this.getRealCurrentLineNb();d=new YamlParser(t);d.refs=this.refs;e=b.value;if(!this.isNextLineIndented()){e+="\n"+this.getNextEmbedBlock(this.getCurrentLineIndentation()+2)}u.push(d.parse(e));this.refs=d.refs}else{u.push(this.parseValue(b.value))}}}else{if(b=new RegExp("^("+YamlInline.REGEX_QUOTED_STRING+"|[^ '\"].*?) *:(\\s+(.+?))?\\s*$").exec(this.currentLine)){if(!this.isDefined(u)){u={}}if(u instanceof Array){throw new InvalidArgumentException("Non mapped entry at line "+(this.getRealCurrentLineNb()+1)+".")}b={key:b[1],value:b[3]};v=(new YamlInline()).parseScalar(b.key);if("<<"==v){if(this.isDefined(b.value)&&"*"==(b.value+"").charAt(0)){r=b.value.substring(1)}else{if(this.isDefined(b.value)&&b.value!=""){m=b.value}else{m=this.getNextEmbedBlock()}t=this.getRealCurrentLineNb()+1;d=new YamlParser(t);d.refs=this.refs;h=d.parse(m);this.refs=d.refs;var s=[];if(!this.isObject(h)){throw new InvalidArgumentException("YAML merge keys used with a scalar value instead of an array at line "+(this.getRealCurrentLineNb()+1)+" ("+this.currentLine+")")}else{if(this.isDefined(h[0])){f=this.reverseArray(h);p=f.length;for(var o=0;o<p;o++){var l=f[o];if(!this.isObject(f[o])){throw new InvalidArgumentException("Merge items must be arrays at line "+(this.getRealCurrentLineNb()+1)+" ("+f[o]+").")}s=this.mergeObject(f[o],s)}}else{s=this.mergeObject(s,h)}}q=s}}else{if(this.isDefined(b.value)&&(a=/^&([^ ]+) *(.*)/.exec(b.value))){a={ref:a[1],value:a[2]};j=a.ref;b.value=a.value}}if(q){u=q}else{if(!this.isDefined(b.value)||""==b.value.split(" ").join("")||this.trim(b.value).charAt(0)=="#"){if(this.isNextLineIndented()){u[v]=null}else{t=this.getRealCurrentLineNb()+1;d=new YamlParser(t);d.refs=this.refs;u[v]=d.parse(this.getNextEmbedBlock());this.refs=d.refs}}else{if(r){u=this.refs[r]}else{u[v]=this.parseValue(b.value)}}}}else{if(2==this.lines.length&&this.isEmpty(this.lines[1])){m=(new YamlInline()).load(this.lines[0]);if(this.isObject(m)){first=m[0];if("*"==(first+"").substr(0,1)){u=[];p=m.length;for(var o=0;o<p;o++){u.push(this.refs[m[o].substring(1)])}m=u}}return m}throw new InvalidArgumentException('"'+this.currentLine+'" at line '+(this.getRealCurrentLineNb()+1))}}if(j){if(u instanceof Array){this.refs[j]=u[u.length-1]}else{var g=null;for(var n in u){if(u.hasOwnProperty(n)){g=n}}this.refs[j]=u[n]}}}return this.isEmpty(u)?null:u},getRealCurrentLineNb:function(){return this.currentLineNb+this.offset},getCurrentLineIndentation:function(){return this.currentLine.length-this.currentLine.replace(/^ +/g,"").length},getNextEmbedBlock:function(d){this.moveToNextLine();var b=null;var a=null;if(!this.isDefined(d)){b=this.getCurrentLineIndentation();if(!this.isCurrentLineEmpty()&&0==b){throw new InvalidArgumentException("A Indentation problem at line "+(this.getRealCurrentLineNb()+1)+" ("+this.currentLine+")")}}else{b=d}var e=[this.currentLine.substring(b)];while(this.moveToNextLine()){if(this.isCurrentLineEmpty()){if(this.isCurrentLineBlank()){e.push(this.currentLine.substring(b))}continue}a=this.getCurrentLineIndentation();var c;if(c=/^( *)$/.exec(this.currentLine)){e.push(c[1])}else{if(a>=b){e.push(this.currentLine.substring(b))}else{if(0==a){this.moveToPreviousLine();break}else{throw new InvalidArgumentException("B Indentation problem at line "+(this.getRealCurrentLineNb()+1)+" ("+this.currentLine+")")}}}}return e.join("\n")},moveToNextLine:function(){if(this.currentLineNb>=this.lines.length-1){return false}this.currentLineNb++;this.currentLine=this.lines[this.currentLineNb];return true},moveToPreviousLine:function(){this.currentLineNb--;this.currentLine=this.lines[this.currentLineNb]},parseValue:function(c){if("*"==(c+"").charAt(0)){if(this.trim(c).charAt(0)=="#"){c=(c+"").substr(1,c.indexOf("#")-2)}else{c=(c+"").substring(1)}if(this.refs[c]==undefined){throw new InvalidArgumentException('Reference "'+c+'" does not exist ('+this.currentLine+").")}return this.refs[c]}var b=null;if(b=/^(\||>)(\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?( +#.*)?$/.exec(c)){b={separator:b[1],modifiers:b[2],comments:b[3]};var a=this.isDefined(b.modifiers)?b.modifiers:"";return this.parseFoldedScalar(b.separator,a.replace(/\d+/g,""),Math.abs(parseInt(a)))}else{return(new YamlInline()).load(c)}},parseFoldedScalar:function(c,h,f){if(h==undefined){h=""}if(f==undefined){f=0}c="|"==c?"\n":" ";var j="";var g=null;var b=this.moveToNextLine();while(b&&this.isCurrentLineBlank()){j+="\n";b=this.moveToNextLine()}if(!b){return""}var d=null;if(!(d=new RegExp("^("+(f?this.strRepeat(" ",f):" +")+")(.*)$").exec(this.currentLine))){this.moveToPreviousLine();return""}d={indent:d[1],text:d[2]};var a=d.indent;var e=0;j+=d.text+c;while(this.currentLineNb+1<this.lines.length){this.moveToNextLine();if(d=new RegExp("^( {"+a.length+",})(.+)$").exec(this.currentLine)){d={indent:d[1],text:d[2]};if(" "==c&&e!=d.indent){j=j.substr(0,j.length-1)+"\n"}e=d.indent;g=d.indent.length-a.length;j+=this.strRepeat(" ",g)+d.text+(g!=0?"\n":c)}else{if(d=/^( *)$/.exec(this.currentLine)){j+=d[1].replace(new RegExp("^ {1,"+a.length+"}","g"),"",d[1])+"\n"}else{this.moveToPreviousLine();break}}}if(" "==c){j=j.replace(/ (\n*)$/g,"\n$1")}switch(h){case"":j=j.replace(/\n+$/g,"\n");break;case"+":break;case"-":j=j.replace(/\n+$/g,"");break}return j},isNextLineIndented:function(){var b=this.getCurrentLineIndentation();var c=this.moveToNextLine();while(c&&this.isCurrentLineEmpty()){c=this.moveToNextLine()}if(false==c){return false}var a=false;if(this.getCurrentLineIndentation()<=b){a=true}this.moveToPreviousLine();return a},isCurrentLineEmpty:function(){return this.isCurrentLineBlank()||this.isCurrentLineComment()},isCurrentLineBlank:function(){return""==this.currentLine.split(" ").join("")},isCurrentLineComment:function(){var a=this.currentLine.replace(/^ +/g,"");return a.charAt(0)=="#"},cleanup:function(c){c=c.split("\r\n").join("\n").split("\r").join("\n");if(!/\n$/.test(c)){c+="\n"}var b=0;var a=/^\%YAML[: ][\d\.]+.*\n/;while(a.test(c)){c=c.replace(a,"");b++}this.offset+=b;a=/^(#.*?\n)+/;if(a.test(c)){trimmedValue=c.replace(a,"");this.offset+=this.subStrCount(c,"\n")-this.subStrCount(trimmedValue,"\n");c=trimmedValue}a=/^\-\-\-.*?\n/;if(a.test(c)){trimmedValue=c.replace(a,"");this.offset+=this.subStrCount(c,"\n")-this.subStrCount(trimmedValue,"\n");c=trimmedValue;c=c.replace(/\.\.\.\s*$/g,"")}return c},isObject:function(a){return typeof(a)=="object"&&this.isDefined(a)},isEmpty:function(a){return a==undefined||a==null||a==""||a==0||a=="0"||a==false},isDefined:function(a){return a!=undefined&&a!=null},reverseArray:function(c){var b=[];var a=c.length;for(var d=a-1;d>=0;d--){b.push(c[d])}return b},merge:function(e,d){var f={};for(i in e){if(/^\d+$/.test(i)){f.push(e)}else{f[i]=e[i]}}for(i in d){if(/^\d+$/.test(i)){f.push(d)}else{f[i]=d[i]}}return f},strRepeat:function(d,c){var b;var a="";for(b=0;b<c;b++){a+=d}return d},subStrCount:function(d,b,j,f){var h=0;d=""+d;b=""+b;if(j!=undefined){d=d.substr(j)}if(f!=undefined){d=d.substr(0,f)}var a=d.length;var g=b.length;for(var e=0;e<a;e++){if(b==d.substr(e,g)){h++}}return h},trim:function(a){return(a+"").replace(/^\s+/,"").replace(/\s+$/,"")}};YamlDumper=function(){};YamlDumper.prototype={dump:function(g,f,c){if(f==undefined){f=0}if(c==undefined){c=0}var b="";var e=c?this.strRepeat(" ",c):"";var i;if(f<=0||!this.isObject(g)||this.isEmpty(g)){i=new YamlInline();b+=e+i.dump(g)}else{var d=!this.arrayEquals(this.getKeys(g),this.range(0,g.length-1));var a;for(var h in g){if(g.hasOwnProperty(h)){a=f-1<=0||!this.isObject(g[h])||this.isEmpty(g[h]);if(d){i=new YamlInline()}b+=e+""+(d?i.dump(h)+":":"-")+""+(a?" ":"\n")+""+this.dump(g[h],f-1,(a?0:c+2))+""+(a?"\n":"")}}}return b},strRepeat:function(d,c){var b;var a="";for(b=0;b<c;b++){a+=d}return d},isObject:function(a){return typeof(a)=="object"&&this.isDefined(a)},isEmpty:function(a){return a==undefined||a==null||a==""||a==0||a=="0"||a==false},isDefined:function(a){return a!=undefined&&a!=null},getKeys:function(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(a)}}return b},range:function(d,a){if(d>a){return[]}var b=[];for(var c=d;c<=a;c++){b.push(c)}return b},arrayEquals:function(e,d){if(e.length!=d.length){return false}var c=e.length;for(var f=0;f<c;f++){if(e[f]!=d[f]){return false}}return true}}; \ No newline at end of file
+/*
+Copyright (c) 2010 Jeremy Faivre
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+var YamlParseException=function(d,a,c,b){this.rawMessage=d;this.parsedLine=(a!==undefined)?a:-1;this.snippet=(c!==undefined)?c:null;this.parsedFile=(b!==undefined)?b:null;this.updateRepr();this.message=d};YamlParseException.prototype={name:"YamlParseException",message:null,parsedFile:null,parsedLine:-1,snippet:null,rawMessage:null,isDefined:function(a){return a!=undefined&&a!=null},getSnippet:function(){return this.snippet},setSnippet:function(a){this.snippet=a;this.updateRepr()},getParsedFile:function(){return this.parsedFile},setParsedFile:function(a){this.parsedFile=a;this.updateRepr()},getParsedLine:function(){return this.parsedLine},setParsedLine:function(a){this.parsedLine=a;this.updateRepr()},updateRepr:function(){this.message=this.rawMessage;dot=false;if("."===this.message.charAt(this.message.length-1)){this.message=this.message.substring(0,this.message.length-1);dot=true}if(null!==this.parsedFile){this.message+=" in "+JSON.stringify(this.parsedFile)}if(this.parsedLine>=0){this.message+=" at line "+this.parsedLine}if(this.snippet){this.message+=' (near "'+this.snippet+'")'}if(dot){this.message+="."}}};var Yaml=function(){};Yaml.prototype={parseFile:function(c,f){if(f==undefined){var a=this.getFileContents(c);var b=null;try{b=this.parse(a)}catch(d){if(d instanceof YamlParseException){d.setParsedFile(c)}throw d}return b}this.getFileContents(c,function(e){f(new Yaml().parse(e))})},parse:function(a){var b=new YamlParser();return b.parse(a)},dump:function(c,b){if(b==undefined){b=2}var a=new YamlDumper();return a.dump(c,b)},getXHR:function(){if(window.XMLHttpRequest){return new XMLHttpRequest()}if(window.ActiveXObject){var c=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];for(var a=0;a<4;a++){try{return new ActiveXObject(c[a])}catch(b){}}}return null},getFileContents:function(a,c){var b=this.getXHR();if(c==undefined){b.open("GET",a,false);b.send(null);if(b.status==200||b.status==0){return b.responseText}return null}b.onreadystatechange=function(){if(b.readyState==4){if(b.status==200||b.status==0){c(b.responseText)}else{c(null)}}};b.open("GET",a,true);b.send(null)}};var YAML={encode:function(a,b){return new Yaml().dump(a,b)},decode:function(a){return new Yaml().parse(a)},load:function(a,b){return new Yaml().parseFile(a,b)}};var YamlInline=function(){};YamlInline.prototype={i:null,parse:function(b){var a=null;b=this.trim(b);if(0==b.length){return""}switch(b.charAt(0)){case"[":a=this.parseSequence(b);break;case"{":a=this.parseMapping(b);break;default:a=this.parseScalar(b);if(b.substr(this.i).replace(/^\s+#.*$/,"")){throw new YamlParseException('Unexpected characters near "'+b.substr(this.i)+'".')}}return a},dump:function(b){if(undefined==b||null==b){return"null"}if(b instanceof Date){return b.toISOString()}if(typeof(b)=="object"){return this.dumpObject(b)}if(typeof(b)=="boolean"){return b?"true":"false"}if(/^\d+$/.test(b)){return typeof(b)=="string"?"'"+b+"'":parseInt(b)}if(this.isNumeric(b)){return typeof(b)=="string"?"'"+b+"'":parseFloat(b)}if(typeof(b)=="number"){return b==Infinity?".Inf":(b==-Infinity?"-.Inf":(isNaN(b)?".NAN":b))}var a=new YamlEscaper();if(a.requiresDoubleQuoting(b)){return a.escapeWithDoubleQuotes(b)}if(a.requiresSingleQuoting(b)){return a.escapeWithSingleQuotes(b)}if(""==b){return""}if(this.getTimestampRegex().test(b)){return"'"+b+"'"}if(this.inArray(b.toLowerCase(),["null","~","true","false"])){return"'"+b+"'"}return b},dumpObject:function(e){var d=this.getKeys(e);var b=null;var c;var a=d.length;if(e instanceof Array){b=[];for(c=0;c<a;c++){b.push(this.dump(e[d[c]]))}return"["+b.join(", ")+"]"}b=[];for(c=0;c<a;c++){b.push(this.dump(d[c])+": "+this.dump(e[d[c]]))}return"{ "+b.join(", ")+" }"},parseScalar:function(a,h,j,e,b){if(h==undefined){h=null}if(j==undefined){j=['"',"'"]}if(e==undefined){e=0}if(b==undefined){b=true}var c=null;var g=null;var f=null;if(this.inArray(a[e],j)){c=this.parseQuotedScalar(a,e);e=this.i;if(null!==h){var d=a.substr(e).replace(/^\s+/,"");if(!this.inArray(d.charAt(0),h)){throw new YamlParseException("Unexpected characters ("+a.substr(e)+").")}}}else{if(!h){c=(a+"").substring(e);e+=c.length;g=c.indexOf(" #");if(g!=-1){c=c.substr(0,g).replace(/\s+$/g,"")}}else{if(f=new RegExp("^(.+?)("+h.join("|")+")").exec((a+"").substring(e))){c=f[1];e+=c.length}else{throw new YamlParseException("Malformed inline YAML string ("+a+").")}}c=b?this.evaluateScalar(c):c}this.i=e;return c},parseQuotedScalar:function(b,c){var e=null;if(!(e=new RegExp("^"+YamlInline.REGEX_QUOTED_STRING).exec((b+"").substring(c)))){throw new YamlParseException("Malformed inline YAML string ("+(b+"").substring(c)+").")}var a=e[0].substr(1,e[0].length-2);var d=new YamlUnescaper();if('"'==(b+"").charAt(c)){a=d.unescapeDoubleQuotedString(a)}else{a=d.unescapeSingleQuotedString(a)}c+=e[0].length;this.i=c;return a},parseSequence:function(g,c){if(c==undefined){c=0}var b=[];var a=g.length;c+=1;while(c<a){switch(g.charAt(c)){case"[":b.push(this.parseSequence(g,c));c=this.i;break;case"{":b.push(this.parseMapping(g,c));c=this.i;break;case"]":this.i=c;return b;case",":case" ":break;default:isQuoted=this.inArray(g.charAt(c),['"',"'"]);var d=this.parseScalar(g,[",","]"],['"',"'"],c);c=this.i;if(!isQuoted&&(d+"").indexOf(": ")!=-1){try{d=this.parseMapping("{"+d+"}")}catch(f){if(!(f instanceof YamlParseException)){throw f}}}b.push(d);c--}c++}throw new YamlParseException('Malformed inline YAML string "'+g+'"')},parseMapping:function(d,f){if(f==undefined){f=0}var c={};var a=d.length;f+=1;var b=false;var g=false;while(f<a){g=false;switch(d.charAt(f)){case" ":case",":f++;g=true;break;case"}":this.i=f;return c}if(g){continue}var e=this.parseScalar(d,[":"," "],['"',"'"],f,false);f=this.i;b=false;while(f<a){switch(d.charAt(f)){case"[":c[e]=this.parseSequence(d,f);f=this.i;b=true;break;case"{":c[e]=this.parseMapping(d,f);f=this.i;b=true;break;case":":case" ":break;default:c[e]=this.parseScalar(d,[",","}"],['"',"'"],f);f=this.i;b=true;f--}++f;if(b){g=true;break}}if(g){continue}}throw new YamlParseException('Malformed inline YAML string "'+d+'"')},evaluateScalar:function(b){b=this.trim(b);var c=null;var a=null;if(("null"==b.toLowerCase())||(""==b)||("~"==b)){return null}if((b+"").indexOf("!str ")==0){return(""+b).substring(5)}if((b+"").indexOf("! ")==0){return parseInt(this.parseScalar((b+"").substr(2)))}if(/^\d+$/.test(b)){c=b;a=parseInt(b);return"0"==b.charAt(0)?this.octdec(b):((""+c==""+a)?a:c)}if("true"==(b+"").toLowerCase()){return true}if("false"==(b+"").toLowerCase()){return false}if(this.isNumeric(b)){return"0x"==(b+"").substr(0,2)?this.hexdec(b):parseFloat(b)}if(b.toLowerCase()==".inf"){return Infinity}if(b.toLowerCase()==".nan"){return NaN}if(b.toLowerCase()=="-.inf"){return -Infinity}if(/^(-|\+)?[0-9,]+(\.[0-9]+)?$/.test(b)){return parseFloat(b.split(",").join(""))}if(this.getTimestampRegex().test(b)){return new Date(this.strtotime(b))}return""+b},getTimestampRegex:function(){return new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:(?:[Tt]|[ \t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:.([0-9]*))?(?:[ \t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?)?$","gi")},trim:function(a){return(a+"").replace(/^\s+/,"").replace(/\s+$/,"")},isNumeric:function(a){return(a-0)==a&&a.length>0&&a.replace(/\s+/g,"")!=""},inArray:function(c,d){var b;var a=d.length;for(b=0;b<a;b++){if(c==d[b]){return true}}return false},getKeys:function(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(a)}}return b},octdec:function(a){return parseInt((a+"").replace(/[^0-7]/gi,""),8)},hexdec:function(a){a=this.trim(a);if((a+"").substr(0,2)=="0x"){a=(a+"").substring(2)}return parseInt((a+"").replace(/[^a-f0-9]/gi,""),16)},strtotime:function(m,s){var o,r,n,i,q="";m=(m+"").replace(/\s{2,}|^\s|\s$/g," ").replace(/[\t\r\n]/g,"");if(m==="now"){return s===null||isNaN(s)?new Date().getTime()||0:s||0}else{if(!isNaN(q=Date.parse(m))){return q||0}else{if(s){s=new Date(s)}else{s=new Date()}}}m=m.toLowerCase();var p={day:{sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},mon:["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]};var t=function(b){var d=(b[2]&&b[2]==="ago");var e=(e=b[0]==="last"?-1:1)*(d?-1:1);switch(b[0]){case"last":case"next":switch(b[1].substring(0,3)){case"yea":s.setFullYear(s.getFullYear()+e);break;case"wee":s.setDate(s.getDate()+(e*7));break;case"day":s.setDate(s.getDate()+e);break;case"hou":s.setHours(s.getHours()+e);break;case"min":s.setMinutes(s.getMinutes()+e);break;case"sec":s.setSeconds(s.getSeconds()+e);break;case"mon":if(b[1]==="month"){s.setMonth(s.getMonth()+e);break}default:var a=p.day[b[1].substring(0,3)];if(typeof a!=="undefined"){var c=a-s.getDay();if(c===0){c=7*e}else{if(c>0){if(b[0]==="last"){c-=7}}else{if(b[0]==="next"){c+=7}}}s.setDate(s.getDate()+c);s.setHours(0,0,0,0)}}break;default:if(/\d+/.test(b[0])){e*=parseInt(b[0],10);switch(b[1].substring(0,3)){case"yea":s.setFullYear(s.getFullYear()+e);break;case"mon":s.setMonth(s.getMonth()+e);break;case"wee":s.setDate(s.getDate()+(e*7));break;case"day":s.setDate(s.getDate()+e);break;case"hou":s.setHours(s.getHours()+e);break;case"min":s.setMinutes(s.getMinutes()+e);break;case"sec":s.setSeconds(s.getSeconds()+e);break}}else{return false}break}return true};n=m.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(n!==null){if(!n[2]){n[2]="00:00:00"}else{if(!n[3]){n[2]+=":00"}}i=n[1].split(/-/g);i[1]=p.mon[i[1]-1]||i[1];i[0]=+i[0];i[0]=(i[0]>=0&&i[0]<=69)?"20"+(i[0]<10?"0"+i[0]:i[0]+""):(i[0]>=70&&i[0]<=99)?"19"+i[0]:i[0]+"";return parseInt(this.strtotime(i[2]+" "+i[1]+" "+i[0]+" "+n[2])+(n[4]?n[4]:""),10)}var l="([+-]?\\d+\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)|(last|next)\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))(\\sago)?";n=m.match(new RegExp(l,"gi"));if(n===null){return false}for(o=0,r=n.length;o<r;o++){if(!t(n[o].split(" "))){return false}}return s.getTime()||0}};YamlInline.REGEX_QUOTED_STRING="(?:\"(?:[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"|'(?:[^']*(?:''[^']*)*)')";var YamlParser=function(a){this.offset=(a!==undefined)?a:0};YamlParser.prototype={offset:0,lines:[],currentLineNb:-1,currentLine:"",refs:{},parse:function(o){this.currentLineNb=-1;this.currentLine="";this.lines=this.cleanup(o).split("\n");var x=null;var d=null;while(this.moveToNextLine()){if(this.isCurrentLineEmpty()){continue}if(this.currentLine.charAt(0)=="\t"){throw new YamlParseException("A YAML file cannot contain tabs as indentation.",this.getRealCurrentLineNb()+1,this.currentLine)}var m=false;var u=false;var t=false;var b=null;var a=null;var w=null;var f=null;var g=null;var y=null;var l=null;var r=null;var h=null;if(b=/^\-((\s+)(.+?))?\s*$/.exec(this.currentLine)){if(d&&"mapping"==d){throw new YamlParseException("You cannot define a sequence item when in a mapping",this.getRealCurrentLineNb()+1,this.currentLine)}d="sequence";if(!this.isDefined(x)){x=[]}b={leadspaces:b[2],value:b[3]};if(this.isDefined(b.value)&&(a=/^&([^ ]+) *(.*)/.exec(b.value))){a={ref:a[1],value:a[2]};m=a.ref;b.value=a.value}if(!this.isDefined(b.value)||""==this.trim(b.value)||b.value.replace(/^ +/,"").charAt(0)=="#"){w=this.getRealCurrentLineNb()+1;f=new YamlParser(w);f.refs=this.refs;x.push(f.parse(this.getNextEmbedBlock()));this.refs=f.refs}else{if(this.isDefined(b.leadspaces)&&" "==b.leadspaces&&(a=new RegExp("^("+YamlInline.REGEX_QUOTED_STRING+"|[^ '\"{[].*?) *:(\\s+(.+?))?\\s*$").exec(b.value))){a={key:a[1],value:a[3]};w=this.getRealCurrentLineNb();f=new YamlParser(w);f.refs=this.refs;g=b.value;if(!this.isNextLineIndented()){g+="\n"+this.getNextEmbedBlock(this.getCurrentLineIndentation()+2)}x.push(f.parse(g));this.refs=f.refs}else{x.push(this.parseValue(b.value))}}}else{if(b=new RegExp("^("+YamlInline.REGEX_QUOTED_STRING+"|[^ '\"[{].*?) *:(\\s+(.+?))?\\s*$").exec(this.currentLine)){if(!this.isDefined(x)){x={}}if(d&&"sequence"==d){throw new YamlParseException("You cannot define a mapping item when in a sequence",this.getRealCurrentLineNb()+1,this.currentLine)}d="mapping";b={key:b[1],value:b[3]};try{y=new YamlInline().parseScalar(b.key)}catch(s){if(s instanceof YamlParseException){s.setParsedLine(this.getRealCurrentLineNb()+1);s.setSnippet(this.currentLine)}throw s}if("<<"==y){if(this.isDefined(b.value)&&"*"==(b.value+"").charAt(0)){u=b.value.substr(1);if(this.refs[u]==undefined){throw new YamlParseException('Reference "'+o+'" does not exist',this.getRealCurrentLineNb()+1,this.currentLine)}}else{if(this.isDefined(b.value)&&b.value!=""){o=b.value}else{o=this.getNextEmbedBlock()}w=this.getRealCurrentLineNb()+1;f=new YamlParser(w);f.refs=this.refs;l=f.parse(o);this.refs=f.refs;var v=[];if(!this.isObject(l)){throw new YamlParseException("YAML merge keys used with a scalar value instead of an array",this.getRealCurrentLineNb()+1,this.currentLine)}else{if(this.isDefined(l[0])){h=this.reverseArray(l);r=h.length;for(var q=0;q<r;q++){var n=h[q];if(!this.isObject(h[q])){throw new YamlParseException("Merge items must be arrays",this.getRealCurrentLineNb()+1,this.currentLine)}v=this.mergeObject(h[q],v)}}else{v=this.mergeObject(v,l)}}t=v}}else{if(this.isDefined(b.value)&&(a=/^&([^ ]+) *(.*)/.exec(b.value))){a={ref:a[1],value:a[2]};m=a.ref;b.value=a.value}}if(t){x=t}else{if(!this.isDefined(b.value)||""==this.trim(b.value)||this.trim(b.value).charAt(0)=="#"){if(this.isNextLineIndented()&&!this.isNextLineUnIndentedCollection()){x[y]=null}else{w=this.getRealCurrentLineNb()+1;f=new YamlParser(w);f.refs=this.refs;x[y]=f.parse(this.getNextEmbedBlock());this.refs=f.refs}}else{if(u){x=this.refs[u]}else{x[y]=this.parseValue(b.value)}}}}else{if(2==this.lines.length&&this.isEmpty(this.lines[1])){try{o=new YamlInline().parse(this.lines[0])}catch(s){if(s instanceof YamlParseException){s.setParsedLine(this.getRealCurrentLineNb()+1);s.setSnippet(this.currentLine)}throw s}if(this.isObject(o)){first=o[0];if(typeof(o)=="string"&&"*"==first.charAt(0)){x=[];r=o.length;for(var q=0;q<r;q++){x.push(this.refs[o[q].substr(1)])}o=x}}return o}throw new YamlParseException("Unable to parse.",this.getRealCurrentLineNb()+1,this.currentLine)}}if(m){if(x instanceof Array){this.refs[m]=x[x.length-1]}else{var j=null;for(var p in x){if(x.hasOwnProperty(p)){j=p}}this.refs[m]=x[p]}}}return this.isEmpty(x)?null:x},getRealCurrentLineNb:function(){return this.currentLineNb+this.offset},getCurrentLineIndentation:function(){return this.currentLine.length-this.currentLine.replace(/^ +/g,"").length},getNextEmbedBlock:function(c){this.moveToNextLine();var b=null;var a=null;if(!this.isDefined(c)){b=this.getCurrentLineIndentation();var g=this.isStringUnIndentedCollectionItem(this.currentLine);if(!this.isCurrentLineEmpty()&&0==b&&!g){throw new YamlParseException("Indentation problem A",this.getRealCurrentLineNb()+1,this.currentLine)}}else{b=c}var f=[this.currentLine.substr(b)];var d=this.isStringUnIndentedCollectionItem(this.currentLine);while(this.moveToNextLine()){if(d&&!this.isStringUnIndentedCollectionItem(this.currentLine)){this.moveToPreviousLine();break}if(this.isCurrentLineEmpty()){if(this.isCurrentLineBlank()){f.push(this.currentLine.substr(b))}continue}a=this.getCurrentLineIndentation();var e;if(e=/^( *)$/.exec(this.currentLine)){f.push(e[1])}else{if(a>=b){f.push(this.currentLine.substr(b))}else{if(0==a){this.moveToPreviousLine();break}else{throw new YamlParseException("Indentation problem B",this.getRealCurrentLineNb()+1,this.currentLine)}}}}return f.join("\n")},moveToNextLine:function(){if(this.currentLineNb>=this.lines.length-1){return false}this.currentLineNb++;this.currentLine=this.lines[this.currentLineNb];return true},moveToPreviousLine:function(){this.currentLineNb--;this.currentLine=this.lines[this.currentLineNb]},parseValue:function(c){if("*"==(c+"").charAt(0)){if(this.trim(c).charAt(0)=="#"){c=(c+"").substr(1,c.indexOf("#")-2)}else{c=(c+"").substr(1)}if(this.refs[c]==undefined){throw new YamlParseException('Reference "'+c+'" does not exist',this.getRealCurrentLineNb()+1,this.currentLine)}return this.refs[c]}var b=null;if(b=/^(\||>)(\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?( +#.*)?$/.exec(c)){b={separator:b[1],modifiers:b[2],comments:b[3]};var a=this.isDefined(b.modifiers)?b.modifiers:"";return this.parseFoldedScalar(b.separator,a.replace(/\d+/g,""),Math.abs(parseInt(a)))}try{return new YamlInline().parse(c)}catch(d){if(d instanceof YamlParseException){d.setParsedLine(this.getRealCurrentLineNb()+1);d.setSnippet(this.currentLine)}throw d}},parseFoldedScalar:function(c,h,f){if(h==undefined){h=""}if(f==undefined){f=0}c="|"==c?"\n":" ";var i="";var g=null;var b=this.moveToNextLine();while(b&&this.isCurrentLineBlank()){i+="\n";b=this.moveToNextLine()}if(!b){return""}var d=null;if(!(d=new RegExp("^("+(f?this.strRepeat(" ",f):" +")+")(.*)$").exec(this.currentLine))){this.moveToPreviousLine();return""}d={indent:d[1],text:d[2]};var a=d.indent;var e=0;i+=d.text+c;while(this.currentLineNb+1<this.lines.length){this.moveToNextLine();if(d=new RegExp("^( {"+a.length+",})(.+)$").exec(this.currentLine)){d={indent:d[1],text:d[2]};if(" "==c&&e!=d.indent){i=i.substr(0,i.length-1)+"\n"}e=d.indent;g=d.indent.length-a.length;i+=this.strRepeat(" ",g)+d.text+(g!=0?"\n":c)}else{if(d=/^( *)$/.exec(this.currentLine)){i+=d[1].replace(new RegExp("^ {1,"+a.length+"}","g"),"")+"\n"}else{this.moveToPreviousLine();break}}}if(" "==c){i=i.replace(/ (\n*)$/g,"\n$1")}switch(h){case"":i=i.replace(/\n+$/g,"\n");break;case"+":break;case"-":i=i.replace(/\n+$/g,"");break}return i},isNextLineIndented:function(){var b=this.getCurrentLineIndentation();var c=this.moveToNextLine();while(c&&this.isCurrentLineEmpty()){c=this.moveToNextLine()}if(false==c){return false}var a=false;if(this.getCurrentLineIndentation()<=b){a=true}this.moveToPreviousLine();return a},isCurrentLineEmpty:function(){return this.isCurrentLineBlank()||this.isCurrentLineComment()},isCurrentLineBlank:function(){return""==this.trim(this.currentLine)},isCurrentLineComment:function(){var a=this.currentLine.replace(/^ +/g,"");return a.charAt(0)=="#"},cleanup:function(d){d=d.split("\r\n").join("\n").split("\r").join("\n");if(!/\n$/.test(d)){d+="\n"}var c=0;var b=/^\%YAML[: ][\d\.]+.*\n/;while(b.test(d)){d=d.replace(b,"");c++}this.offset+=c;b=/^(#.*?\n)+/;if(b.test(d)){var a=d.replace(b,"");this.offset+=this.subStrCount(d,"\n")-this.subStrCount(a,"\n");d=a}b=/^\-\-\-.*?\n/;if(b.test(d)){a=d.replace(b,"");this.offset+=this.subStrCount(d,"\n")-this.subStrCount(a,"\n");d=a;d=d.replace(/\.\.\.\s*$/g,"")}return d},isNextLineUnIndentedCollection:function(){var b=this.getCurrentLineIndentation();var c=this.moveToNextLine();while(c&&this.isCurrentLineEmpty()){c=this.moveToNextLine()}if(false===c){return false}var a=false;if(this.getCurrentLineIndentation()==b&&this.isStringUnIndentedCollectionItem(this.currentLine)){a=true}this.moveToPreviousLine();return a},isStringUnIndentedCollectionItem:function(a){return(0===this.currentLine.indexOf("- "))},isObject:function(a){return typeof(a)=="object"&&this.isDefined(a)},isEmpty:function(a){return a==undefined||a==null||a==""||a==0||a=="0"||a==false},isDefined:function(a){return a!=undefined&&a!=null},reverseArray:function(c){var b=[];var a=c.length;for(var d=a-1;d>=0;d--){b.push(c[d])}return b},merge:function(e,d){var g={};var f;for(f in e){if(e.hasOwnProperty(f)){if(/^\d+$/.test(f)){g.push(e)}else{g[f]=e[f]}}}for(f in d){if(d.hasOwnProperty(f)){if(/^\d+$/.test(f)){g.push(d)}else{g[f]=d[f]}}}return g},strRepeat:function(d,c){var b;var a="";for(b=0;b<c;b++){a+=d}return a},subStrCount:function(d,b,j,f){var h=0;d=""+d;b=""+b;if(j!=undefined){d=d.substr(j)}if(f!=undefined){d=d.substr(0,f)}var a=d.length;var g=b.length;for(var e=0;e<a;e++){if(b==d.substr(e,g)){h++}e+=g-1}return h},trim:function(a){return(a+"").replace(/^ +/,"").replace(/ +$/,"")}};YamlEscaper=function(){};YamlEscaper.prototype={requiresDoubleQuoting:function(a){return new RegExp(YamlEscaper.REGEX_CHARACTER_TO_ESCAPE).test(a)},escapeWithDoubleQuotes:function(f){f=f+"";var a=YamlEscaper.escapees.length;var e=YamlEscaper.escaped.length;var b=YamlEscaper.escaped;for(var d=0;d<a;++d){if(d>=e){b.push("")}}var c="";c=f.replace(new RegExp(YamlEscaper.escapees.join("|"),"g"),function(h){for(var g=0;g<a;++g){if(h==YamlEscaper.escapees[g]){return b[g]}}});return'"'+c+'"'},requiresSingleQuoting:function(a){return/[\s'":{}[\],&*#?]|^[-?|<>=!%@`]/.test(a)},escapeWithSingleQuotes:function(a){return"'"+a.replace(/'/g,"''")+"'"}};YamlEscaper.REGEX_CHARACTER_TO_ESCAPE="[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9";YamlEscaper.escapees=["\\\\",'\\"','"',"\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09","\x0a","\x0b","\x0c","\x0d","\x0e","\x0f","\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17","\x18","\x19","\x1a","\x1b","\x1c","\x1d","\x1e","\x1f","\xc2\x85","\xc2\xa0","\xe2\x80\xa8","\xe2\x80\xa9"];YamlEscaper.escaped=['\\"',"\\\\",'\\"',"\\0","\\x01","\\x02","\\x03","\\x04","\\x05","\\x06","\\a","\\b","\\t","\\n","\\v","\\f","\\r","\\x0e","\\x0f","\\x10","\\x11","\\x12","\\x13","\\x14","\\x15","\\x16","\\x17","\\x18","\\x19","\\x1a","\\e","\\x1c","\\x1d","\\x1e","\\x1f","\\N","\\_","\\L","\\P"];var YamlUnescaper=function(){};YamlUnescaper.prototype={unescapeSingleQuotedString:function(a){return a.replace(/''/g,"'")},unescapeDoubleQuotedString:function(a){var b=function(c){return new YamlUnescaper().unescapeCharacter(c)};return a.replace(new RegExp(YamlUnescaper.REGEX_ESCAPED_CHARACTER,"g"),b)},unescapeCharacter:function(a){switch(a.charAt(1)){case"0":return String.fromCharCode(0);case"a":return String.fromCharCode(7);case"b":return String.fromCharCode(8);case"t":return"\t";case"\t":return"\t";case"n":return"\n";case"v":return String.fromCharCode(11);case"f":return String.fromCharCode(12);case"r":return String.fromCharCode(13);case"e":return"\x1b";case" ":return" ";case'"':return'"';case"/":return"/";case"\\":return"\\";case"N":return"\x00\x85";case"_":return"\x00\xA0";case"L":return"\x20\x28";case"P":return"\x20\x29";case"x":return this.pack("n",new YamlInline().hexdec(a.substr(2,2)));case"u":return this.pack("n",new YamlInline().hexdec(a.substr(2,4)));case"U":return this.pack("N",new YamlInline().hexdec(a.substr(2,8)))}},pack:function(U){var ab=0,X=1,Y="",Z="",i=0,W=[],P,R,S,k,aa,af;var ae,ag,n,J,N,ad,V,T,Q,O,r,ah,L,M,j,K,ac;while(ab<U.length){P=U.charAt(ab);R="";ab++;while((ab<U.length)&&(U.charAt(ab).match(/[\d\*]/)!==null)){R+=U.charAt(ab);ab++}if(R===""){R="1"}switch(P){case"n":if(R==="*"){R=arguments.length-X}if(R>(arguments.length-X)){throw new Error("Warning: pack() Type "+P+": too few arguments")}for(i=0;i<R;i++){Y+=String.fromCharCode(arguments[X]>>8&255);Y+=String.fromCharCode(arguments[X]&255);X++}break;case"N":if(R==="*"){R=arguments.length-X}if(R>(arguments.length-X)){throw new Error("Warning: pack() Type "+P+": too few arguments")}for(i=0;i<R;i++){Y+=String.fromCharCode(arguments[X]>>24&255);Y+=String.fromCharCode(arguments[X]>>16&255);Y+=String.fromCharCode(arguments[X]>>8&255);Y+=String.fromCharCode(arguments[X]&255);X++}break;default:throw new Error("Warning: pack() Type "+P+": unknown format code")}}if(X<arguments.length){throw new Error("Warning: pack(): "+(arguments.length-X)+" arguments unused")}return Y}};YamlUnescaper.REGEX_ESCAPED_CHARACTER='\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})';var YamlDumper=function(){};YamlDumper.prototype={dump:function(g,f,c){if(f==undefined){f=0}if(c==undefined){c=0}var b="";var e=c?this.strRepeat(" ",c):"";var i;if(f<=0||!this.isObject(g)||this.isEmpty(g)){i=new YamlInline();b+=e+i.dump(g)}else{var d=!this.arrayEquals(this.getKeys(g),this.range(0,g.length-1));var a;for(var h in g){if(g.hasOwnProperty(h)){a=f-1<=0||!this.isObject(g[h])||this.isEmpty(g[h]);if(d){i=new YamlInline()}b+=e+""+(d?i.dump(h)+":":"-")+""+(a?" ":"\n")+""+this.dump(g[h],f-1,(a?0:c+2))+""+(a?"\n":"")}}}return b},strRepeat:function(d,c){var b;var a="";for(b=0;b<c;b++){a+=d}return a},isObject:function(a){return this.isDefined(a)&&typeof(a)=="object"},isEmpty:function(a){var b=a==undefined||a==null||a==""||a==0||a=="0"||a==false;if(!b&&typeof(a)=="object"&&!(a instanceof Array)){var d=0;for(var c in a){if(a.hasOwnProperty(c)){d++}}b=!d}return b},isDefined:function(a){return a!=undefined&&a!=null},getKeys:function(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(a)}}return b},range:function(d,a){if(d>a){return[]}var b=[];for(var c=d;c<=a;c++){b.push(c)}return b},arrayEquals:function(e,d){if(e.length!=d.length){return false}var c=e.length;for(var f=0;f<c;f++){if(e[f]!=d[f]){return false}}return true}}; \ No newline at end of file