File: core_language/expression/entry/case_expression/datum_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
  module: Entry#16
  module: CaseExpression#18
  class: DatumTest#20
inherits from
  Test ( Minitest )
has properties
method: setup #25
method: test_datum #30
method: test_with_contents #52
method: test_should_be_consistent_rule_category #74
method: test_should_not_be_duplicated_rule #90

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  module Entry
  17 
  18  module CaseExpression
  19 
  20  class DatumTest < Minitest::Test
  21  =begin
  22  <case-rule-head-datum> ::= ID [ <pattern> ] ;
  23  =end
  24 
  25      def setup
  26          @interp = Api.setup_interpreter
  27      end
  28 
  29 
  30      def test_datum
  31          script = <<-EOS
  32              case x of {
  33                | Apple  -> @A
  34                | Banana -> @B
  35              }
  36              EOS
  37 
  38          value = Api.eval_expr(
  39              @interp, script, x:VC.make_datum(:Apple, VC.make_unit)
  40          )
  41          assert_instance_of  VCA::Symbol, value
  42          assert_equal        :A,          value.val
  43 
  44          value = Api.eval_expr(
  45              @interp, script, x:VC.make_datum(:Banana, VC.make_unit)
  46          )
  47          assert_instance_of  VCA::Symbol, value
  48          assert_equal        :B,          value.val
  49      end
  50 
  51 
  52      def test_with_contents
  53          script = <<-EOS
  54              case x of {
  55                | Apple  price -> price
  56                | Banana price -> price
  57              }
  58              EOS
  59 
  60          value = Api.eval_expr(
  61              @interp, script, x:VC.make_datum(:Apple, VC.make_integer(300))
  62          )
  63          assert_instance_of  VCAN::Int, value
  64          assert_equal        300,       value.val
  65 
  66          value = Api.eval_expr(
  67              @interp, script, x:VC.make_datum(:Banana, VC.make_integer(500))
  68          )
  69          assert_instance_of  VCAN::Int, value
  70          assert_equal        500,       value.val
  71      end
  72 
  73 
  74      def test_should_be_consistent_rule_category
  75          script = <<-EOS
  76              case x of {
  77                | Apple   -> @A
  78                | @Banana -> @B
  79              }
  80              EOS
  81 
  82          assert_raises(X::SyntaxError) do
  83              Api.eval_expr(
  84                  @interp, script, x:VC.make_datum(:Apple, VC.make_unit)
  85              )
  86          end
  87      end
  88 
  89 
  90      def test_should_not_be_duplicated_rule
  91          script = <<-EOS
  92              case x of {
  93                | Apple   -> @A
  94                | Apple   -> @B
  95              }
  96              EOS
  97 
  98          assert_raises(X::SyntaxError) do
  99              Api.eval_expr(
 100                  @interp, script, x:VC.make_datum(:Apple, VC.make_unit)
 101              )
 102          end
 103      end
 104  end
 105 
 106  end # Umu::Test::Grammar::CoreLanguage::Expression::Entry::CaseExpression
 107 
 108  end # Umu::Test::Grammar::CoreLanguage::Expression::Entry
 109 
 110  end # Umu::Test::Grammar::CoreLanguage::Expression
 111 
 112  end # Umu::Test::Grammar::CoreLanguage
 113 
 114  end # Umu::Test::Grammar
 115 
 116  end # Umu::Test
 117 
 118  end # Umu