File: reference_test.rb

package info (click to toggle)
ruby-brandur-json-schema 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: ruby: 4,082; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require "test_helper"

require "json_reference"

describe JsonReference::Reference do
  it "expands a reference without a URI" do
    ref = reference("#/definitions")
    assert_nil ref.uri
    assert_equal "#/definitions", ref.pointer
  end

  it "expands a reference with a URI" do
    ref = reference("http://example.com#/definitions")
    assert_equal URI.parse("http://example.com"), ref.uri
    assert_equal "#/definitions", ref.pointer
  end

  it "expands just a root sign" do
    ref = reference("#")
    assert_nil ref.uri
    assert_equal "#", ref.pointer
  end

  it "expands a URI with just a root sign" do
    ref = reference("http://example.com#")
    assert_equal URI.parse("http://example.com"), ref.uri
    assert_equal "#", ref.pointer
  end

  it "normalizes pointers by adding a root sign prefix" do
    ref = reference("/definitions")
    assert_nil ref.uri
    assert_equal "#/definitions", ref.pointer
  end

  it "normalizes pointers by stripping a trailing slash" do
    ref = reference("#/definitions/")
    assert_nil ref.uri
    assert_equal "#/definitions", ref.pointer
  end

  def reference(str)
    JsonReference::Reference.new(str)
  end
end