Sha256: 7b6528bf10abb9c2ca706513578c8fc62a44624722e56dc97d8278a9d8e3fbd6

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'test_helper'

class TestJason < MiniTest::Unit::TestCase
  test '.render without binding' do
    template = <<-EOF
{
  "message": "OK",
  "user": {
    "id": <%= 'test' %>,
    "name": <%= 'blah' %>,
    <% if true %>
      "link": [
        <% if true %>
          {
            "rel": "self",
            "href": <%= 'hablaba' %>
          },
        <% end %>
        {
          "rel": "checkins",
          "href": <%= 'hablaba' %>
        }
      ]
    <% end %>
  }
}
EOF
    
    assert_equal({
      'message' => 'OK',
      'user' => {
        'id' => 'test',
        'name' => 'blah',
        'link' => [
          {
            'rel' => 'self',
            'href' => 'hablaba'
          },
          {
            'rel' => 'checkins',
            'href' => 'hablaba'
          }
        ]
      }
    }, JSON.load(Jason.render(template)))
  end
  
  test '.render with binding' do
    test_string = 'bar'
    template = <<-EOF
      { "foo": <%= test_string %>, }
    EOF
    
    assert_equal({ 'foo' => 'bar' }, JSON.load(Jason.render(template, binding)))
  end
  
  test '.compile' do
    test_string = 'bar'
    template = <<-EOF
      { "foo": "<%== test_string %>", }
    EOF
    
    assert_equal({ 'foo' => 'bar' }, JSON.load(eval(Jason.compile(template))))
  end
  
  test '.process' do
    template = <<-EOF
      {
        "foo": "bar",
        "baz": [
          "quz",
          "quuz",
        ],
      }
    EOF
    
    assert_equal({ 'foo' => 'bar', 'baz' => ['quz', 'quuz'] }, JSON.load(Jason.process(template)))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jason-0.3.1 test/test_jason.rb