~singpolyma/dhall-ruby

63e418cb0233ced297405b2579b85a5b7a42d799 — Stephen Paul Weber 5 years ago 831a391
Fix unit tests
M lib/dhall/ast.rb => lib/dhall/ast.rb +1 -2
@@ 323,8 323,7 @@ module Dhall

	class RecordType < Expression
		include(ValueSemantics.for_attributes do
			# The nil is not allowed in Dhall
			record Util::HashOf.new(Either(nil, Expression), min: 1)
			record Util::HashOf.new(Expression, min: 1)
		end)

		def deep_merge_type(other)

M lib/dhall/builtins.rb => lib/dhall/builtins.rb +51 -21
@@ 220,28 220,40 @@ module Dhall
		end

		class List_head < Builtin
			include(ValueSemantics.for_attributes do
				type Either(nil, Expression), default: nil
			end)

			def call(arg)
				if arg.is_a?(List)
					arg.first
				else
					super
				fill_or_call(arg) do
					if arg.is_a?(List)
						arg.first
					else
						super
					end
				end
			end
		end

		class List_indexed < Builtin
			include(ValueSemantics.for_attributes do
				type Either(nil, Expression), default: nil
			end)

			def call(arg)
				if arg.is_a?(List)
					_call(arg)
				else
					super
				fill_or_call(arg) do
					if arg.is_a?(List)
						_call(arg)
					else
						super
					end
				end
			end

			protected

			def _call(arg)
				arg.map(type: indexed_type(arg.type)) do |x, idx|
				arg.map(type: indexed_type(type)) do |x, idx|
					Record.new(
						record: {
							"index" => Natural.new(value: idx),


@@ 262,31 274,49 @@ module Dhall
		end

		class List_last < Builtin
			include(ValueSemantics.for_attributes do
				type Either(nil, Expression), default: nil
			end)

			def call(arg)
				if arg.is_a?(List)
					arg.last
				else
					super
				fill_or_call(arg) do
					if arg.is_a?(List)
						arg.last
					else
						super
					end
				end
			end
		end

		class List_length < Builtin
			include(ValueSemantics.for_attributes do
				type Either(nil, Expression), default: nil
			end)

			def call(arg)
				if arg.is_a?(List)
					Natural.new(value: arg.length)
				else
					super
				fill_or_call(arg) do
					if arg.is_a?(List)
						Natural.new(value: arg.length)
					else
						super
					end
				end
			end
		end

		class List_reverse < Builtin
			include(ValueSemantics.for_attributes do
				type Either(nil, Expression), default: nil
			end)

			def call(arg)
				if arg.is_a?(List)
					arg.reverse
				else
					super
				fill_or_call(arg) do
					if arg.is_a?(List)
						arg.reverse
					else
						super
					end
				end
			end
		end

M test/normalization/beta/ListHeadEmptyA.dhallb => test/normalization/beta/ListHeadEmptyA.dhallb +0 -0
M test/normalization/beta/ListHeadOneA.dhallb => test/normalization/beta/ListHeadOneA.dhallb +0 -0
M test/normalization/beta/ListIndexedEmptyA.dhallb => test/normalization/beta/ListIndexedEmptyA.dhallb +0 -0
M test/normalization/beta/ListIndexedOneA.dhallb => test/normalization/beta/ListIndexedOneA.dhallb +0 -0
M test/normalization/beta/ListLastEmptyA.dhallb => test/normalization/beta/ListLastEmptyA.dhallb +0 -0
M test/normalization/beta/ListLastOneA.dhallb => test/normalization/beta/ListLastOneA.dhallb +0 -0
M test/normalization/beta/ListLengthEmptyA.dhallb => test/normalization/beta/ListLengthEmptyA.dhallb +0 -0
M test/normalization/beta/ListLengthOneA.dhallb => test/normalization/beta/ListLengthOneA.dhallb +0 -0
M test/normalization/beta/ListReverseEmptyA.dhallb => test/normalization/beta/ListReverseEmptyA.dhallb +0 -0
M test/normalization/beta/ListReverseTwoA.dhallb => test/normalization/beta/ListReverseTwoA.dhallb +0 -0