Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added bools

  • Loading branch information...
commit 0e99409d64acbfc2200e3a4b6a8584abe559c5d1 1 parent 4698d2b
@tj authored
Showing with 49 additions and 2 deletions.
  1. +3 −2 Readme.md
  2. +8 −0 lib/yaml.js
  3. +38 −0 spec/spec.core.js
View
5 Readme.md
@@ -11,11 +11,12 @@ fork the project and submit a patch :)
# Currently Supports
- * Sequences
- * Maps
* Comments
+ * Sequences (arrays)
+ * Maps (hashes)
* Nesting
* Primitive scalars (integers, floats, booleans, etc)
+ * Extended bools (enabled, disabled, yes, no, on, off, true, false)
* Inline sequences ([foo, bar])
* Inline maps ({ foo: bar })
View
8 lib/yaml.js
@@ -15,6 +15,8 @@ var tokens = [
['comment', /^#[^\n]*/],
['indent', /^\n( *)/],
['space', /^ +/],
+ ['true', /^(enabled|true|yes|on)/],
+ ['false', /^(disabled|false|no|off)/],
['string', /^"(.*?)"/],
['float', /^(\d+\.\d+)/],
['int', /^(\d+)/],
@@ -167,6 +169,8 @@ Parser.prototype.ignoreSpace = function() {
* | string
* | float
* | int
+ * | true
+ * | false
*/
Parser.prototype.parse = function() {
@@ -181,6 +185,10 @@ Parser.prototype.parse = function() {
return parseFloat(this.advanceValue())
case 'int':
return parseInt(this.advanceValue())
+ case 'true':
+ return true
+ case 'false':
+ return false
}
}
View
38 spec/spec.core.js
@@ -50,6 +50,44 @@ describe 'yaml'
end
end
+ describe 'bools'
+ describe 'true'
+ it 'true'
+ yaml.eval('true').should.equal true
+ end
+
+ it 'yes'
+ yaml.eval('yes').should.equal true
+ end
+
+ it 'on'
+ yaml.eval('on').should.equal true
+ end
+
+ it 'enabled'
+ yaml.eval('enabled').should.equal true
+ end
+ end
+
+ describe 'false'
+ it 'false'
+ yaml.eval('false').should.equal false
+ end
+
+ it 'no'
+ yaml.eval('no').should.equal false
+ end
+
+ it 'off'
+ yaml.eval('off').should.equal false
+ end
+
+ it 'disabled'
+ yaml.eval('disabled').should.equal false
+ end
+ end
+ end
+
describe 'indentation'
describe 'when invalid'
it 'should throw an error'
Please sign in to comment.
Something went wrong with that request. Please try again.