Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4f8ea4272fa6abd3e8b6f18fb6c9ffa7b32ecce9 @tj committed
Showing with 191 additions and 0 deletions.
  1. +4 −0 History.rdoc
  2. +29 −0 README.rdoc
  3. +35 −0 lib/yaml.js
  4. +16 −0 spec/fixtures/config.yml
  5. +4 −0 spec/server.rb
  6. +59 −0 spec/spec.core.js
  7. +20 −0 spec/spec.dom.html
  8. +8 −0 spec/spec.rhino.js
  9. +16 −0 spec/spec.server.html
4 History.rdoc
@@ -0,0 +1,4 @@
+
+=== 0.0.1 / YYYY-MM-DD
+
+* Initial release
29 README.rdoc
@@ -0,0 +1,29 @@
+
+= YourLib
+
+Description
+
+== License
+
+(The MIT License)
+
+Copyright (c) 2009 Your Name <Your Email>
+
+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.
35 lib/yaml.js
@@ -0,0 +1,35 @@
+
+;(function(){
+ YAML = {
+ valueOf: function(token) {
+ return eval('(' + token + ')')
+ },
+
+ tokenize: function(str) {
+ return str.match(/(---|true|false|null|#(.*)|\[(.*?)\]|\{(.*?)\}|[\w\-]+:|-(.+)|\d+\.\d+|\d+|\n+)/g)
+ },
+
+ strip: function(str) {
+ return str.replace(/^\s*|\s*$/, '')
+ },
+
+ parse: function(tokens) {
+ var token, list = /^-(.*)/, key = /^([\w\-]+):/, stack = {}
+ while (token = tokens.shift())
+ if (token[0] == '#' || token == '---' || token == "\n")
+ continue
+ else if (key.exec(token) && tokens[0] == "\n")
+ stack[RegExp.$1] = this.parse(tokens)
+ else if (key.exec(token))
+ stack[RegExp.$1] = this.valueOf(tokens.shift())
+ else if (list.exec(token))
+ (stack.constructor == Array ?
+ stack : (stack = [])).push(this.strip(RegExp.$1))
+ return stack
+ },
+
+ eval: function(str) {
+ return this.parse(this.tokenize(str))
+ }
+ }
+})()
16 spec/fixtures/config.yml
@@ -0,0 +1,16 @@
+---
+ # just a comment
+ list: ['foo', 'bar']
+ hash: { foo: "bar", n: 1 }
+ lib:
+ - lib/cart.js
+ - lib/cart.foo.js
+ specs:
+ - spec/cart.spec.js
+ - spec/cart.foo.spec.js
+ # - Commented out
+ environments:
+ all:
+ options:
+ failuresOnly: true
+ verbose: false
4 spec/server.rb
@@ -0,0 +1,4 @@
+
+get '/lib/*' do |path|
+ send_file File.dirname(__FILE__) + '/../lib/' + path
+end
59 spec/spec.core.js
@@ -0,0 +1,59 @@
+
+describe 'YAML'
+ describe '.eval()'
+ it 'should ignore comments'
+ yml = '--- \n\
+ # enabled: true \n\
+ '
+ YAML.eval(yml).should.eql {}
+ end
+
+ describe 'should parse'
+ it 'pairs'
+ yml = '--- \n\
+ enabled: true \n\
+ '
+ YAML.eval(yml).should.eql { enabled: true }
+ end
+
+ it 'lists'
+ yml = '--- \n\
+ specs: \n\
+ - foo.spec.js \n\
+ - bar.spec.js \n\
+ '
+ YAML.eval(yml).should.eql { specs: ['foo.spec.js', 'bar.spec.js'] }
+ end
+
+ it 'several lists'
+ yml = '--- \n\
+ one: \n\
+ - a \n\
+ - b \n\
+ - c \n\
+ two: \n\
+ - 1 \n\
+ - 2 \n\
+ '
+ YAML.eval(yml).should.eql { one: ['a', 'b', 'c'], two: [1, 2] }
+ end
+
+ it 'several pairs'
+ yml = '--- \n\
+ boot: false \n\
+ enabled: true \n\
+ '
+ YAML.eval(yml).should.eql { boot: false, enabled: true }
+ end
+
+ it 'nested values'
+ yml = '--- \n\
+ foo: \n\
+ bar: \n\
+ baz: "yay" \n\
+ '
+ YAML.eval(yml).should.eql { foo: { bar: { baz: "yay" }}}
+ end
+ end
+ end
+end
20 spec/spec.dom.html
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <link type="text/css" rel="stylesheet" href="/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.11.2/lib/jspec.css" />
+ <script src="/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.11.2/lib/jspec.js"></script>
+ <script src="../lib/yourlib.core.js"></script>
+ <script>
+ function runSuites() {
+ JSpec
+ .exec('spec.core.js')
+ .run()
+ .report()
+ }
+ </script>
+ </head>
+ <body class="jspec" onLoad="runSuites();">
+ <div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
+ <div id="jspec"></div>
+ <div id="jspec-bottom"></div>
+ </body>
+</html>
8 spec/spec.rhino.js
@@ -0,0 +1,8 @@
+
+load('/Library/Ruby/Gems/1.8/gems/visionmedia-jspec-2.11.2/lib/jspec.js')
+load('lib/yaml.js')
+
+JSpec
+.exec('spec/spec.core.js')
+.run({ formatter: JSpec.formatters.Terminal })
+.report()
16 spec/spec.server.html
@@ -0,0 +1,16 @@
+<html>
+ <head>
+ <script src="/jspec/jspec.js"></script>
+ <script src="/lib/yourlib.core.js"></script>
+ <script>
+ function runSuites() {
+ JSpec
+ .exec('spec.core.js')
+ .run({ formatter : JSpec.formatters.Server, verbose: true, failuresOnly: true })
+ .report()
+ }
+ </script>
+ </head>
+ <body class="jspec" onLoad="runSuites();">
+ </body>
+</html>

0 comments on commit 4f8ea42

Please sign in to comment.
Something went wrong with that request. Please try again.