From 9a8ad3a23c693e3d2dac10793f201857667b96eb Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sat, 13 Apr 2019 21:12:25 -0500 Subject: [PATCH] as_dhall for Symbol --- lib/dhall/as_dhall.rb | 10 ++++++++++ test/test_as_dhall.rb | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/dhall/as_dhall.rb b/lib/dhall/as_dhall.rb index d3607fe..60fd4ff 100644 --- a/lib/dhall/as_dhall.rb +++ b/lib/dhall/as_dhall.rb @@ -39,6 +39,16 @@ module Dhall end end + refine ::Symbol do + def as_dhall + Dhall::Union.new( + tag: to_s, + value: nil, + alternatives: Dhall::UnionType.new(alternatives: {}) + ) + end + end + refine ::Integer do def as_dhall if negative? diff --git a/test/test_as_dhall.rb b/test/test_as_dhall.rb index f1ce339..15e4ee2 100644 --- a/test/test_as_dhall.rb +++ b/test/test_as_dhall.rb @@ -2,7 +2,7 @@ require "minitest/autorun" -require "dhall/as_dhall" +require "dhall" class TestAsDhall < Minitest::Test using Dhall::AsDhall @@ -24,6 +24,17 @@ class TestAsDhall < Minitest::Test end end + def test_symbol + assert_equal( + Dhall::Union.new( + tag: "hai", + value: nil, + alternatives: Dhall::UnionType.new(alternatives: {}) + ), + :hai.as_dhall + ) + end + def test_natural assert_equal Dhall::Natural.new(value: 1), 1.as_dhall end -- 2.45.2