~singpolyma/dhall-ruby

1358c357949aea8cb52cf7b8c690ce0bdb206ff1 — Stephen Paul Weber 3 years ago 2232998
Encoding binary string as List Natural

Certainly better than an error, and gives the dhall side access to the
individual bytes.
2 files changed, 9 insertions(+), 4 deletions(-)

M lib/dhall/as_dhall.rb
M test/test_as_dhall.rb
M lib/dhall/as_dhall.rb => lib/dhall/as_dhall.rb +5 -1
@@ 35,7 35,11 @@ module Dhall

		refine ::String do
			def as_dhall
				Text.new(value: self)
				if encoding == Encoding::BINARY
					bytes.as_dhall
				else
					Text.new(value: self)
				end
			end
		end


M test/test_as_dhall.rb => test/test_as_dhall.rb +4 -3
@@ 18,10 18,11 @@ class TestAsDhall < Minitest::Test
		)
	end

	def test_string_failure
		assert_raises Encoding::UndefinedConversionError do
	def test_string_binary
		assert_equal(
			Dhall::List.new(elements: [Dhall::Natural.new(value: 0xff)]),
			"\xff".b.as_dhall
		end
		)
	end

	def test_symbol