Sha256: 4e2a99188bf48a4303faf1ece3d654119a1331843a120f25fbe0080d953c990e

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))

class ToSexpTest < Test::Unit::TestCase

  def setup
    @parser = Sexpistol.new
  end

  test "should convert nested arrays back into an S-Expression" do
    ast = [:string, [:is, [:parsed]]]
    sexp = @parser.to_sexp(ast)
    assert_equal "(string (is (parsed)))", sexp
  end
  
  test "should structure containing integers and strings back into an S-Expression" do
    ast = ["String!", [1, [2, "Other string."]]]
    sexp = @parser.to_sexp(ast)
    assert_equal "(String! (1 (2 Other string.)))", sexp
  end
  
  test "should output true and false using scheme notation" do
    ast = [true, [false, [true, false]]]
    sexp = @parser.to_sexp(ast)
    assert_equal "(#t (#f (#t #f)))", sexp
  end
  
  test "when not passed array to_sexp should print value (integer)" do
    ast = 1
    sexp = @parser.to_sexp(ast)
    assert_equal "1", sexp
  end
  
  test "when not passed array to_sexp should print value (string)" do
    ast = "test"
    sexp = @parser.to_sexp(ast)
    assert_equal "test", sexp
  end
  
  test "when not passed array to_sexp should print value (symbol)" do
    ast = :test
    sexp = @parser.to_sexp(ast)
    assert_equal "test", sexp
  end
  
  test "lists passed to to_sexp should have not extraneous spaces" do
    ast = [1, 2, 3]
    sexp = @parser.to_sexp(ast)
    assert_equal "(1 2 3)", sexp
  end
    
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sexpistol-0.0.6 test/unit/to_sexp_test.rb