File: core_language/declaration/function_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: Declaration#14
  class: FunctionTest#16
inherits from
  Test ( Minitest )
has properties
method: setup #26
method: test_function #31
method: test_binary_pattern #40
method: test_with_empty_local_declaration #49
method: test_with_single_local_declaration #60
method: test_with_some_local_declarations #71

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 Declaration
  15 
  16  class FunctionTest < Minitest::Test
  17  =begin
  18  <function-declaration> ::=
  19      FUN <pattern> "=" <function-body> ;
  20 
  21  <function-body> ::=
  22      <pattern> { <pattern> } "->" 
  23      [ WHERE "{" { <declaration> } "}"
  24      ;
  25  =end
  26      def setup
  27          @interp = Api.setup_interpreter
  28      end
  29 
  30 
  31      def test_function
  32          interp = Api.eval_decls @interp, "fun add4 = x -> x + 4"
  33 
  34          value = Api.eval_expr interp, "add4 3"
  35          assert_instance_of VCAN::Int, value
  36          assert_equal       7,         value.val
  37      end
  38 
  39 
  40      def test_binary_pattern
  41          interp = Api.eval_decls @interp, "fun add = x y -> x + y"
  42 
  43          value = Api.eval_expr interp, "add 3 4"
  44          assert_instance_of VCAN::Int, value
  45          assert_equal       7,         value.val
  46      end
  47 
  48 
  49      def test_with_empty_local_declaration
  50          interp = Api.eval_decls @interp, <<-EOS
  51              fun add4 = x -> x + 4 where { }
  52              EOS
  53 
  54          value = Api.eval_expr interp, "add4 3"
  55          assert_instance_of VCAN::Int, value
  56          assert_equal       7,         value.val
  57      end
  58 
  59 
  60      def test_with_single_local_declaration
  61          interp = Api.eval_decls @interp, <<-EOS
  62              fun add4 = x -> x + y where { val y = 4 }
  63              EOS
  64 
  65          value = Api.eval_expr interp, "add4 3"
  66          assert_instance_of VCAN::Int, value
  67          assert_equal       7,         value.val
  68      end
  69 
  70 
  71      def test_with_some_local_declarations
  72          interp = Api.eval_decls @interp, <<-EOS
  73              fun add4 = x -> x + y + z where { val y = 4 val z = 5 }
  74              EOS
  75 
  76          value = Api.eval_expr interp, "add4 3"
  77          assert_instance_of VCAN::Int, value
  78          assert_equal       12,        value.val
  79      end
  80  end
  81 
  82  end # Umu::Test::Grammar::CoreLanguage::Declaration
  83 
  84  end # Umu::Test::Grammar::CoreLanguage
  85 
  86  end # Umu::Test::Grammar
  87 
  88  end # Umu::Test
  89 
  90  end # Umu