Sha256: 3db4a684306411dc92542acd0ec0d7bf56e0177da1a5e7f9d5307007e6720aa9

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

require 'test/unit'

require File.join(File.dirname(__FILE__), "minibasic")

class ATestMiniBasic < Test::Unit::TestCase
  def assert_parse(exp, str)
    res = MiniBasic::Parser.parse_string(str)
    assert_equal(exp, res)
  end

  def assert_stmt(expStmt, str)
    assert_parse([expStmt], str)
  end

  include MiniBasic::Grammar::ASTs

  def test_01
    assert_stmt(PrintLn["PRINTLN"], "PRINTLN")
  end

  def test_02
    assert_stmt(Read["READ", :A], "READ A")
  end

  def test_03
    assert_stmt(Print["PRINT", :BC], "PRINT  BC")
  end

  def test_04
    assert_stmt(Assign[:D, ":=", 1], "D := 1")
    assert_stmt(Assign[:D, ":=", 1], "D :=1")
    assert_stmt(Assign[:D, ":=", 1], "D:=1")
  end

  def test_05
    assert_stmt(For["FOR", :A, ":=", 1, "TO", 3, 
                 [Assign[:S, ":=", OpExpr[:S, "+", :A]],
                  Print["PRINT", :S],
                 ],
                 "NEXT"], "FOR A := 1 TO 3 S:= S + A PRINT S NEXT")
  end

  def atest_06    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rockit-0.7.1 tests/acceptance/packrat/minibasic/atest_minibasic.rb