Sha256: c3abf32af1e3cdc36c83cb5d5e1dfb93a11042abdbea8e76df3a77ba81088e9b

Contents?: true

Size: 1.86 KB

Versions: 37

Compression:

Stored size: 1.86 KB

Contents

require "test_helper"

require "json_pointer"

describe JsonPointer::Evaluator do
  before do
    @evaluator = JsonPointer::Evaluator.new(data)
  end

  it "evaluates pointers according to spec" do
    assert_equal data,           @evaluator.evaluate("")
    assert_equal ["bar", "baz"], @evaluator.evaluate("/foo")
    assert_equal "bar",          @evaluator.evaluate("/foo/0")
    assert_equal 0,              @evaluator.evaluate("/")
    assert_equal 1,              @evaluator.evaluate("/a~1b")
    assert_equal 2,              @evaluator.evaluate("/c%d")
    assert_equal 3,              @evaluator.evaluate("/e^f")
    assert_equal 4,              @evaluator.evaluate("/g|h")
    assert_equal 5,              @evaluator.evaluate("/i\\j")
    assert_equal 6,              @evaluator.evaluate("/k\"l")
    assert_equal 7,              @evaluator.evaluate("/ ")
    assert_equal 8,              @evaluator.evaluate("/m~0n")
  end

  it "takes a leading #" do
    assert_equal 0, @evaluator.evaluate("#/")
  end

  it "returns nils on missing values" do
    assert_nil @evaluator.evaluate("/bar")
  end

  it "raises when a path doesn't being with /" do
    e = assert_raises(RuntimeError) { @evaluator.evaluate("foo") }
    assert_equal %{Path must begin with a leading "/": foo.}, e.message
    e = assert_raises(RuntimeError) { @evaluator.evaluate("#foo") }
    assert_equal %{Path must begin with a leading "/": #foo.}, e.message
  end

  it "raises when a non-digit is specified on an array" do
    e = assert_raises(RuntimeError) { @evaluator.evaluate("/foo/bar") }
    assert_equal %{Key operating on an array must be a digit or "-": bar.},
      e.message
  end

  def data
   {
      "foo"  => ["bar", "baz"],
      ""     => 0,
      "a/b"  => 1,
      "c%d"  => 2,
      "e^f"  => 3,
      "g|h"  => 4,
      "i\\j" => 5,
      "k\"l" => 6,
      " "    => 7,
      "m~n"  => 8
   }
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
json_schema-0.11.0 test/json_pointer/evaluator_test.rb
json_schema-0.10.0 test/json_pointer/evaluator_test.rb
json_schema-0.9.0 test/json_pointer/evaluator_test.rb
json_schema-0.8.0 test/json_pointer/evaluator_test.rb
json_schema-0.7.1 test/json_pointer/evaluator_test.rb
json_schema-0.7.0 test/json_pointer/evaluator_test.rb
json_schema-0.6.2 test/json_pointer/evaluator_test.rb
json_schema-0.6.1 test/json_pointer/evaluator_test.rb
json_schema-0.6.0 test/json_pointer/evaluator_test.rb
json_schema-0.5.0 test/json_pointer/evaluator_test.rb
json_schema-0.4.0 test/json_pointer/evaluator_test.rb
json_schema-0.3.1 test/json_pointer/evaluator_test.rb
json_schema-0.3.0 test/json_pointer/evaluator_test.rb
json_schema-0.2.0 test/json_pointer/evaluator_test.rb
json_schema-0.1.9 test/json_pointer/evaluator_test.rb
json_schema-0.1.8 test/json_pointer/evaluator_test.rb
json_schema-0.1.7 test/json_pointer/evaluator_test.rb
json_schema-0.1.6 test/json_pointer/evaluator_test.rb
json_schema-0.1.5 test/json_pointer/evaluator_test.rb
json_schema-0.1.4 test/json_pointer/evaluator_test.rb