~singpolyma/dhall-ruby

ref: 7274a86b64cd761f0c0c3d0bddb790f2d5aba1fc dhall-ruby/test/test_load.rb -rw-r--r-- 1.1 KiB
7274a86bStephen Paul Weber Add Dhall.load 3 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
# frozen_string_literal: true

require "minitest/autorun"

require "dhall"

class TestLoad < Minitest::Test
	def test_load_natural_source
		assert_equal Dhall::Natural.new(value: 1), Dhall.load("1").sync
	end

	def test_load_natural_source_mislabeled_encoding
		assert_equal Dhall::Natural.new(value: 1), Dhall.load("1".b).sync
	end

	def test_load_natural_binary
		assert_equal(
			Dhall::Natural.new(value: 1),
			Dhall.load("\x82\x0f\x01".b).sync
		)
	end

	def test_load_normalizes
		assert_equal(
			Dhall::Natural.new(value: 2),
			Dhall.load("1 + 1").sync
		)
	end

	def test_load_resolves
		assert_equal(
			Dhall::Natural.new(value: 2),
			Dhall.load(
				"/path/to/source.dhall",
				resolver: Dhall::Resolvers::Default.new(
					path_reader: ->(s) { s.map { "1 + 1" } }
				)
			).sync
		)
	end

	def test_load_typechecks
		assert_raises TypeError do
			Dhall.load("1 + \"hai\"").sync
		end
	end

	def test_load_raw_not_normalizes_or_typechecks
		assert_equal(
			Dhall::Operator::Plus.new(
				lhs: Dhall::Natural.new(value: 1),
				rhs: Dhall::Text.new(value: "hai")
			),
			Dhall.load_raw("1 + \"hai\"")
		)
	end
end