~singpolyma/dhall-ruby

ref: 43890aec4916d92fd9f40b523d1024c824ebb7ac dhall-ruby/test/test_parser.rb -rw-r--r-- 1.1 KiB View raw
43890aecStephen Paul Weber Typecheck while resolving 11 months 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
# frozen_string_literal: true

require "minitest/autorun"
require "pathname"

require "dhall/parser"
require "dhall/binary"

class TestParser < Minitest::Test
	DIRPATH = Pathname.new(File.dirname(__FILE__))
	TESTS = DIRPATH + "../dhall-lang/tests/parser/"

	Pathname.glob(TESTS + "success/**/*A.dhall").each do |path|
		test = path.relative_path_from(TESTS).to_s.sub(/A\.dhall$/, "")
		define_method("test_#{test}") do
			skip "deprecated syntax" if test =~ /collectionImportType|annotations/
			skip "deprecated syntax" if test =~ /pathTerminationUnion/
			skip "very slow" if !ENV.key?("CI") && test =~ /largeExpression/
			match = Dhall::Parser.parse_file(path)
			assert(match)
			assert_kind_of(Dhall::Expression, match.value)
			assert_equal(
				(TESTS + "#{test}B.dhallb").binread,
				match.value.to_cbor
			)
		end
	end

	Pathname.glob(TESTS + "failure/**/*.dhall").each do |path|
		test = path.relative_path_from(TESTS).to_s.sub(/A\.dhall$/, "")
		define_method("test_#{test}") do
			# ArgumentError for non-utf8
			assert_raises Citrus::ParseError, ArgumentError do
				Dhall::Parser.parse_file(path).value
			end
		end
	end
end