Sha256: 4881b1586fd1e4659a9cd890e222af83f19d561ceee88ec255d7b150436b9ada

Contents?: true

Size: 1.81 KB

Versions: 20

Compression:

Stored size: 1.81 KB

Contents

# coding: utf-8
$:.unshift "."
require 'spec_helper'
require 'rdf/spec/format'

describe JSON::LD::Format do
  before :each do
    @format_class = JSON::LD::Format
  end

  include RDF_Format

  describe ".for" do
    formats = [
      :jsonld,
      "etc/doap.jsonld",
      {:file_name      => 'etc/doap.jsonld'},
      {:file_extension => 'jsonld'},
      {:content_type   => 'application/ld+json'},
      {:content_type   => 'application/x-ld+json'},
    ].each do |arg|
      it "discovers with #{arg.inspect}" do
        RDF::Format.for(arg).should == @format_class
      end
    end

    {
      :jsonld   => '{"@context" => "foo"}',
      :context  => %({\n"@context": {),
      :id       => %({\n"@id": {),
      :type     => %({\n"@type": {),
    }.each do |sym, str|
      it "detects #{sym}" do
        @format_class.for {str}.should == @format_class
      end
    end

    it "should discover 'jsonld'" do
      RDF::Format.for(:jsonld).reader.should == JSON::LD::Reader
    end
  end

  describe "#to_sym" do
    specify {@format_class.to_sym.should == :jsonld}
  end

  describe ".detect" do
    {
      :jsonld => '{"@context" => "foo"}',
    }.each do |sym, str|
      it "detects #{sym}" do
        @format_class.detect(str).should be_true
      end
    end

    {
      :n3             => "@prefix foo: <bar> .\nfoo:bar = {<a> <b> <c>} .",
      :nquads => "<a> <b> <c> <d> . ",
      :rdfxml => '<rdf:RDF about="foo"></rdf:RDF>',
      :rdfa   => '<div about="foo"></div>',
      :microdata => '<div itemref="bar"></div>',
      :ntriples         => "<a> <b> <c> .",
      :multi_line       => '<a>\n  <b>\n  "literal"\n .',
      :turtle           => "@prefix foo: <bar> .\n foo:a foo:b <c> .",
    }.each do |sym, str|
      it "does not detect #{sym}" do
        @format_class.detect(str).should be_false
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
json-ld-1.1.5 spec/format_spec.rb
json-ld-1.1.4 spec/format_spec.rb
json-ld-1.1.3.1 spec/format_spec.rb
json-ld-1.1.3 spec/format_spec.rb
json-ld-1.1.2 spec/format_spec.rb
json-ld-1.1.1 spec/format_spec.rb
json-ld-1.1.0 spec/format_spec.rb
json-ld-1.0.8.1 spec/format_spec.rb
json-ld-1.0.8 spec/format_spec.rb
json-ld-1.0.7 spec/format_spec.rb
json-ld-1.0.6 spec/format_spec.rb
json-ld-1.0.5 spec/format_spec.rb
json-ld-1.0.4 spec/format_spec.rb
json-ld-1.0.3 spec/format_spec.rb
json-ld-1.0.1.1 spec/format_spec.rb
json-ld-1.0.1 spec/format_spec.rb
json-ld-1.0.0 spec/format_spec.rb
json-ld-0.9.1 spec/format_spec.rb
json-ld-0.9.0 spec/format_spec.rb
json-ld-0.3.2 spec/format_spec.rb