~singpolyma/dhall-ruby

ref: 0.2.0 dhall-ruby/test/test_resolvers.rb -rw-r--r-- 2.5 KiB View raw
a49a8991Stephen Paul Weber Customizable cache 1 year, 1 month 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
# frozen_string_literal: true

require "minitest/autorun"

require "dhall/resolve"
require "dhall/normalize"

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.to_s) }
			end
		)
		source = Dhall::Import::AbsolutePath.new("dhall", "common", "x.dhall")
		promise = source.resolve(resolver)
		resolver.finish!
		assert_equal source.to_s, promise.sync
	end

	def test_default_resolver_env
		resolver = Dhall::Resolvers::Default.new(
			environment_reader: lambda do |sources|
				sources.map { |source| Promise.resolve(source.to_s) }
			end
		)
		source = Dhall::Import::EnvironmentVariable.new("__DHALL_IMPORT_TEST")
		promise = source.resolve(resolver)
		resolver.finish!
		assert_equal source.to_s, promise.sync
	end

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

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