github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

osteele / jcon

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Conformance checking of JSON values against ECMAScript 4.0 types — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

use jeweler for gemspec 
osteele (author)
Sun Mar 22 19:41:26 -0700 2009
commit  97d29d361704fe105f753ffb7a34cca59719e967
tree    8ed9a1654f96a4ad429f32d3b5d935d85a7bec5c
parent  58bc5234ba4449f10c0348b566dd9c5456a73787
jcon /
name age
history
message
file .gitignore Loading commit data...
file LICENSE
file README.rdoc
file Rakefile
file TODO
file VERSION.yml
file jcon.gemspec
directory lib/
directory spec/
README.rdoc

JCon — JavaScript Type Conformance Checking

JCON (the "JavaScript Conformance" gem), is a companion to JSON. It tests JSON values against ECMAScript 4.0-style type definitions (PDF), such as string?, (int, boolean), or [string, (int, boolean), {x:double, y:double}?].

JCON also defines an RSpec matcher, conforms_to_js.

Use JCON together with the JavaScript Fu Rails plugin to test the argument values in generated JavaScript function calls.

Install

  gem install rcon

Usage

  type = JCON::parse "[string, int]"
  type.contains?(['a', 1]) # => true
  type.contains?(['a', 'b']) # => false
  type.contains?(['a', 1, 2]) # => true

  type = JCON::parse "type S = (string, int); {a: [S], b: int}"
  type.contains?({:a => [1, 'b'], :b => 2}) # => true

RSpec Matcher

  [1, 'xyzzy'].should conform_to_js('[int, string]')
  [1, 2, 'xyzzy'].should_not conform_to_js('[int, string]')
  {:x => 1}.should conform_to_js('{x: int}')

Use this with the JavaScript Fu Rails plugin to test JSON arguments:

  '<script>fn("id", {x:1, y:2}, true)</script>'.should call_js('fn') do |args|
    args[0].should conform_to_js('string')
    args[1].should conform_to_js('{x:int, y:int}')
    args[2].should conform_to_js('boolean')
    # or:
    args.should conform_to_js('[string, {x:int, y:int}, boolean]')
  end

License

Copyright 2008 by Oliver Steele. All rights reserved. Released under the MIT License.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server