File: core_language/expression/apply_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: Expression#14
  class: ApplyTest#16
inherits from
  Test ( Minitest )
has properties
method: setup #21
method: test_apply_expression #26
method: test_with_product_expression #44

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 Expression
  15 
  16  class ApplyTest < Minitest::Test
  17  =begin
  18  <apply-expression> ::=
  19      <product-expression> { <product-expression> } ;
  20  =end
  21      def setup
  22          @interp = Api.setup_interpreter
  23      end
  24 
  25 
  26      def test_apply_expression
  27          value = Api.eval_expr @interp, "(+) 3 4"
  28          assert_instance_of VCAN::Int, value
  29          assert_equal       7,         value.val
  30 
  31          interp_1 = Api.eval_decls @interp,  "val op = (+)"
  32 
  33          interp_2 = Api.eval_decls interp_1, "val it = op 3"
  34          value_fun = Api.eval_expr interp_2, "it"
  35          assert_instance_of VC::Fun, value_fun
  36 
  37          interp_3 = Api.eval_decls interp_2, "val it = it 4"
  38          value_int = Api.eval_expr interp_3, "it"
  39          assert_instance_of VCAN::Int, value_int
  40          assert_equal       7,         value_int.val
  41      end
  42 
  43 
  44      def test_with_product_expression
  45          interp = Api.eval_decls @interp, <<-EOS
  46              val t1 = (name:@Apple  price:300)
  47              val t2 = (name:@Banana price:500)
  48              EOS
  49 
  50          value = Api.eval_expr interp, "(+) t1$2 t2$2"
  51          assert_instance_of VCAN::Int, value
  52          assert_equal       800,       value.val
  53      end
  54  end
  55 
  56  end # Umu::Test::Grammar::CoreLanguage::Expression
  57 
  58  end # Umu::Test::Grammar::CoreLanguage
  59 
  60  end # Umu::Test::Grammar
  61 
  62  end # Umu::Test
  63 
  64  end # Umu