File: class_library/union/option_test.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Test#8
  module: Library#10
  module: Class#12
  module: Union#14
  module: Option#16
  class: NoneTest#18
inherits from
  Test ( Minitest )
has properties
method: setup #19
method: test_cmeth_make #24
method: test_imeth_show #30
method: test_imeth_to_s #37
method: test_imeth_is_none #44
method: test_imeth_is_some #51
method: test_imess_equal #58
method: test_imess_less_than #80
  class: SomeTest#97
inherits from
  Test ( Minitest )
has properties
method: setup #98
method: test_cmeth_make #103
method: test_imeth_show #111
method: test_imeth_to_s #118
method: test_imeth_is_none #125
method: test_imeth_is_some #132
method: test_imess_equal #139
method: test_imess_less_than #161

Code

   1  # frozen_string_literal: true
   2 
   3  require "test_helper"
   4 
   5 
   6  module Umu
   7 
   8  module Test
   9 
  10  module Library
  11 
  12  module Class
  13 
  14  module Union
  15 
  16  module Option
  17 
  18  class NoneTest < Minitest::Test
  19      def setup
  20          @interp = Api.setup_interpreter
  21      end
  22 
  23 
  24      def test_cmeth_make
  25          value = Api.eval_expr @interp, "&None.make"
  26          assert_instance_of VCU::Option::None,   value
  27      end
  28 
  29 
  30      def test_imeth_show
  31          value = Api.eval_expr @interp, "&None.make.show"
  32          assert_instance_of VCA::String, value
  33          assert_equal       '&None ()',  value.val
  34      end
  35 
  36 
  37      def test_imeth_to_s
  38          value = Api.eval_expr @interp, "&None.make.to-s"
  39          assert_instance_of VCA::String,  value
  40          assert_equal       '&None ()',   value.val
  41      end
  42 
  43 
  44      def test_imeth_is_none
  45          value = Api.eval_expr @interp, "&None.make.None?"
  46          assert_instance_of VCA::Bool,   value
  47          assert_equal       true,        value.val
  48      end
  49 
  50 
  51      def test_imeth_is_some
  52          value = Api.eval_expr @interp, "&None.make.Some?"
  53          assert_instance_of VCA::Bool,   value
  54          assert_equal       false,       value.val
  55      end
  56 
  57 
  58      def test_imess_equal
  59          interp_1 = Api.eval_decls @interp, <<-EOS
  60              val n1 = &None.make
  61              val n2 = &None.make
  62              EOS
  63 
  64          value = Api.eval_expr interp_1, "n1.== n1"
  65          assert_instance_of VCA::Bool,   value
  66          assert_equal       true,        value.val
  67 
  68          value = Api.eval_expr interp_1, "n1.== 4"
  69          assert_instance_of VCA::Bool,   value
  70          assert_equal       false,       value.val
  71 
  72          value = Api.eval_expr interp_1, <<-EOS
  73              n1.== (&Some.make @Apple)
  74              EOS
  75          assert_instance_of VCA::Bool,   value
  76          assert_equal       false,       value.val
  77      end
  78 
  79 
  80      def test_imess_less_than
  81          interp_1 = Api.eval_decls @interp, <<-EOS
  82              val n = &None.make
  83              EOS
  84 
  85          value = Api.eval_expr interp_1, "n.< n"
  86          assert_instance_of VCA::Bool,   value
  87          assert_equal       false,       value.val
  88 
  89          value = Api.eval_expr interp_1, "n.< (&Some.make @Apple)"
  90          assert_instance_of VCA::Bool,   value
  91          assert_equal       true,        value.val
  92      end
  93  end
  94 
  95 
  96 
  97  class SomeTest < Minitest::Test
  98      def setup
  99          @interp = Api.setup_interpreter
 100      end
 101 
 102 
 103      def test_cmeth_make
 104          value = Api.eval_expr @interp, "&Some.make @Apple"
 105          assert_instance_of VCU::Option::Some,   value
 106          assert_instance_of VCA::Symbol,         value.contents
 107          assert_equal       :Apple,              value.contents.val
 108      end
 109 
 110 
 111      def test_imeth_show
 112          value = Api.eval_expr @interp, "&Some.make @Apple.show"
 113          assert_instance_of VCA::String,     value
 114          assert_equal       '&Some @Apple',  value.val
 115      end
 116 
 117 
 118      def test_imeth_to_s
 119          value = Api.eval_expr @interp, "&Some.make @Apple.to-s"
 120          assert_instance_of VCA::String,     value
 121          assert_equal       '&Some Apple',   value.val
 122      end
 123 
 124 
 125      def test_imeth_is_none
 126          value = Api.eval_expr @interp, "&Some.make @Apple.None?"
 127          assert_instance_of VCA::Bool,   value
 128          assert_equal       false,       value.val
 129      end
 130 
 131 
 132      def test_imeth_is_some
 133          value = Api.eval_expr @interp, "&Some.make @Apple.Some?"
 134          assert_instance_of VCA::Bool,   value
 135          assert_equal       true,        value.val
 136      end
 137 
 138 
 139      def test_imess_equal
 140          interp_1 = Api.eval_decls @interp, <<-EOS
 141              val s1 = &Some.make @Apple
 142              val s2 = &Some.make @Apple
 143              EOS
 144 
 145          value = Api.eval_expr interp_1, "s1.== s2"
 146          assert_instance_of VCA::Bool,   value
 147          assert_equal       true,        value.val
 148 
 149          value = Api.eval_expr interp_1, "s1.== 4"
 150          assert_instance_of VCA::Bool,   value
 151          assert_equal       false,       value.val
 152 
 153          value = Api.eval_expr interp_1, <<-EOS
 154              s1.== (&Some.make @Banana)
 155              EOS
 156          assert_instance_of VCA::Bool,   value
 157          assert_equal       false,       value.val
 158      end
 159 
 160 
 161      def test_imess_less_than
 162          interp_1 = Api.eval_decls @interp, <<-EOS
 163              val s = &Some.make @Apple
 164              EOS
 165 
 166          value = Api.eval_expr interp_1, "s.< s"
 167          assert_instance_of VCA::Bool,   value
 168          assert_equal       false,       value.val
 169 
 170          value = Api.eval_expr interp_1, "s.< (&Some.make @Banana)"
 171          assert_instance_of VCA::Bool,   value
 172          assert_equal       true,         value.val
 173 
 174          value = Api.eval_expr interp_1, "s.< (&Some.make @A)"
 175          assert_instance_of VCA::Bool,   value
 176          assert_equal       false,        value.val
 177      end
 178  end
 179 
 180  end # Umu::Test::Library::Class::Union::Option
 181 
 182  end # Umu::Test::Library::Class::Union
 183 
 184  end # Umu::Test::Library::Class
 185 
 186  end # Umu::Test::Library
 187 
 188  end # Umu::Test
 189 
 190  end # Umu