~singpolyma/dhall-ruby

ref: ebd4b252393c58b8d82af9d886bb059df73db1a6 dhall-ruby/test/test_resolvers.rb -rw-r--r-- 2.5 KiB
ebd4b252Stephen Paul Weber Always encode OptionalNone in new style 2 years ago
                                                                                
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true

require "minitest/autorun"

require "dhall/resolve"

class TestResolvers < Minitest::Test
	def test_default_resolver_path
		resolver = Dhall::Resolvers::Default.new(
			path_reader: lambda do |sources|
				sources.map { |source| Promise.resolve(source) }
			end
		)
		source = Dhall::Import::AbsolutePath.new("dhall", "common", "x.dhall")
		promise = source.resolve(resolver)
		resolver.finish!
		assert_equal source, promise.sync
	end

	def test_default_resolver_path_from_env
		ENV["__DHALL_IMPORT_TEST"] = "/dhall/common/x.dhall"
		resolver = Dhall::Resolvers::Default.new(
			path_reader: lambda do |sources|
				sources.map { |source| Promise.resolve(source) }
			end
		)
		source = Dhall::Import::EnvironmentVariable.new("__DHALL_IMPORT_TEST")
		promise = source.resolve(resolver)
		resolver.finish!

		expected = Dhall::Import::AbsolutePath.new("dhall", "common", "x.dhall")
		assert_equal expected, promise.sync
	end

	def test_default_resolver_http
		resolver = Dhall::Resolvers::Default.new(
			http_reader: lambda do |sources|
				sources.map { |source| Promise.resolve(source) }
			end
		)
		source = Dhall::Import::Http.new(nil, "example.com", "x.dhall", nil, nil)
		promise = source.resolve(resolver)
		resolver.finish!
		assert_equal source, promise.sync
	end

	def test_default_resolver_https
		resolver = Dhall::Resolvers::Default.new(
			https_reader: lambda do |sources|
				sources.map { |source| Promise.resolve(source) }
			end
		)
		source = Dhall::Import::Https.new(nil, "example.com", "x.dhall", nil, nil)
		promise = source.resolve(resolver)
		resolver.finish!
		assert_equal source, promise.sync
	end

	def test_default_resolver_https_uses_http
		resolver = Dhall::Resolvers::Default.new(
			http_reader: lambda do |sources|
				sources.map { |source| Promise.resolve(source) }
			end
		)
		source = Dhall::Import::Https.new(nil, "example.com", "x.dhall", nil, nil)
		promise = source.resolve(resolver)
		resolver.finish!
		assert_equal source, promise.sync
	end

	def test_local_only_resolver_rejects_http
		resolver = Dhall::Resolvers::LocalOnly.new
		source = Dhall::Import::Http.new(nil, "example.com", "x.dhall", nil, nil)
		promise = source.resolve(resolver)
		resolver.finish!
		assert_raises Dhall::ImportBannedException do
			promise.sync
		end
	end

	def test_none_resolver_rejects_local
		resolver = Dhall::Resolvers::None.new
		source = Dhall::Import::AbsolutePath.new("dhall", "common", "x.dhall")
		promise = source.resolve(resolver)
		resolver.finish!
		assert_raises Dhall::ImportBannedException do
			promise.sync
		end
	end
end