File: core_language/pattern/tuple_test.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Test#8
  module: Grammar#10
  module: CoreLanguage#12
  module: Pattern#14
  class: TupleTest#16
inherits from
  Test ( Minitest )
has properties
method: setup #25
method: test_value #30
method: test_value_less_than_rhs #45
method: test_value_more_than_rhs #60
method: test_value_triple #69
method: test_value_type #88
method: test_should_be_kind_of_specified_type_in_declaration #103
method: test_lambda #112
method: test_lambda_triple #121
method: test_lambda_type #130
method: test_should_be_kind_of_specified_type_in_lambda #139

Code

   1  # frozen_string_literal: true
   2 
   3  require "test_helper"
   4 
   5 
   6  module Umu
   7 
   8  module Test
   9 
  10  module Grammar
  11 
  12  module CoreLanguage
  13 
  14  module Pattern
  15 
  16  class TupleTest < Minitest::Test
  17  =begin
  18  <tuple-pattern> ::=
  19      "("
  20          <variable-pattern> "," <variable-pattern>
  21          { "," <variable-pattern> }
  22      ")"
  23      ;
  24  =end
  25      def setup
  26          @interp = Api.setup_interpreter
  27      end
  28 
  29 
  30      def test_value
  31          interp = Api.eval_decls @interp, <<-EOS
  32              val (name, price) = (@Apple, 300)
  33              EOS
  34 
  35          value = Api.eval_expr interp, "name"
  36          assert_instance_of VCA::Symbol, value
  37          assert_equal       :Apple,      value.val
  38 
  39          value = Api.eval_expr interp, "price"
  40          assert_instance_of VCAN::Int, value
  41          assert_equal       300,       value.val
  42      end
  43 
  44 
  45      def test_value_less_than_rhs
  46          interp = Api.eval_decls @interp, <<-EOS
  47              val (name, price) = (@Apple, 300, "Aomori")
  48              EOS
  49 
  50          value = Api.eval_expr interp, "name"
  51          assert_instance_of VCA::Symbol, value
  52          assert_equal       :Apple,      value.val
  53 
  54          value = Api.eval_expr interp, "price"
  55          assert_instance_of VCAN::Int, value
  56          assert_equal       300,       value.val
  57      end
  58 
  59 
  60      def test_value_more_than_rhs
  61          assert_raises(X::SelectionError) do
  62              Api.eval_decls @interp, <<-EOS
  63                  val (name, price, area) = (@Apple, 300)
  64                  EOS
  65          end
  66      end
  67 
  68 
  69      def test_value_triple
  70          interp = Api.eval_decls @interp, <<-EOS
  71              val (name, price, area) = (@Apple, 300, "Aomori")
  72              EOS
  73 
  74          value = Api.eval_expr interp, "name"
  75          assert_instance_of VCA::Symbol, value
  76          assert_equal       :Apple,      value.val
  77 
  78          value = Api.eval_expr interp, "price"
  79          assert_instance_of VCAN::Int, value
  80          assert_equal       300,       value.val
  81 
  82          value = Api.eval_expr interp, "area"
  83          assert_instance_of VCA::String, value
  84          assert_equal       "Aomori",    value.val
  85      end
  86 
  87 
  88      def test_value_type
  89          interp = Api.eval_decls @interp, <<-EOS
  90              val (name : Symbol, price : Int) = (@Apple, 300)
  91              EOS
  92 
  93          value = Api.eval_expr interp, "name"
  94          assert_instance_of VCA::Symbol, value
  95          assert_equal       :Apple,      value.val
  96 
  97          value = Api.eval_expr interp, "price"
  98          assert_instance_of VCAN::Int, value
  99          assert_equal       300,       value.val
 100      end
 101 
 102 
 103      def test_should_be_kind_of_specified_type_in_declaration
 104          assert_raises(X::TypeError) do
 105              Api.eval_decls @interp, <<-EOS
 106                  val (name :Int, price) = (@Apple, 300)
 107              EOS
 108          end
 109      end
 110 
 111 
 112      def test_lambda
 113          value = Api.eval_expr @interp, <<-EOS
 114              { (x, y) -> x + y } (3, 4)
 115              EOS
 116          assert_instance_of VCAN::Int, value
 117          assert_equal       7,         value.val
 118      end
 119 
 120 
 121      def test_lambda_triple
 122          value = Api.eval_expr @interp, <<-EOS
 123              { (x, y, z) -> x + y + z } (3, 4, 5)
 124              EOS
 125          assert_instance_of VCAN::Int, value
 126          assert_equal       12,        value.val
 127      end
 128 
 129 
 130      def test_lambda_type
 131          value = Api.eval_expr @interp, <<-EOS
 132              { (x : Int, y : Int) -> x + y } (3, 4)
 133              EOS
 134          assert_instance_of VCAN::Int, value
 135          assert_equal       7,         value.val
 136      end
 137 
 138 
 139      def test_should_be_kind_of_specified_type_in_lambda
 140          assert_raises(X::TypeError) do
 141              Api.eval_expr @interp, <<-EOS
 142                  { (x : String, y : Int) -> x + y } (3, 4)
 143                  EOS
 144          end
 145      end
 146  end
 147 
 148  end # Umu::Test::Grammar::CoreLanguage::Pattern
 149 
 150  end # Umu::Test::Grammar::CoreLanguage
 151 
 152  end # Umu::Test::Grammar
 153 
 154  end # Umu::Test
 155 
 156  end # Umu