Sha256: 186dde9fbef159de48229af514e482835afbc250c87bdf979f0950c0427ed16c

Contents?: true

Size: 1.62 KB

Versions: 7

Compression:

Stored size: 1.62 KB

Contents

require "spec_helper"

describe Nydp::StringAtom do
  let(:bar) { Nydp::StringAtom.new "BAR" }
  let(:foo) { Nydp::StringAtom.new "FOO" }
  let(:vm)  { Nydp::VM.new(ns)           }

  it "is not equal to a symbol with the same represenation" do
    string = Nydp::StringAtom.new "harrypotter"
    symbol = Nydp::Symbol.mk "harrypotter", ns
    compare = Nydp::StringAtom.new symbol.to_s
    expect(string == compare).to eq true
    expect(string == symbol) .to eq false
  end

  it "is not equal to a list with the same represenation" do
    string = Nydp::StringAtom.new "(FOO BAR)"
    list   = Nydp::Pair.from_list [foo, bar]
    compare = Nydp::StringAtom.new list.to_s
    expect(string == compare).to eq true
    expect(string == list)   .to eq false
  end

  it "returns its string in #to_ruby" do
    s = Nydp::StringAtom.new "harrypotter"
    expect(s.to_ruby).to eq "harrypotter"
    expect(s.to_ruby.class).to eq String
  end

  it "works with builtin greater-than when true" do
    f = Nydp::Builtin::GreaterThan.instance

    f.invoke vm, pair_list([foo, bar])

    expect(vm.args.pop).to eq Nydp::T
  end

  it "works with builtin greater-than when false" do
    f = Nydp::Builtin::GreaterThan.instance

    f.invoke vm, pair_list([bar, foo])

    expect(vm.args.pop).to eq Nydp::NIL
  end

  it "works with builtin less-than when true" do
    f = Nydp::Builtin::LessThan.instance

    f.invoke vm, pair_list([bar, foo])

    expect(vm.args.pop).to eq Nydp::T
  end

  it "works with builtin less-than when false" do
    f = Nydp::Builtin::LessThan.instance

    f.invoke vm, pair_list([foo, bar])

    expect(vm.args.pop).to eq Nydp::NIL
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nydp-0.3.0 spec/string_atom_spec.rb
nydp-0.2.6 spec/string_atom_spec.rb
nydp-0.2.5 spec/string_atom_spec.rb
nydp-0.2.3 spec/string_atom_spec.rb
nydp-0.2.2 spec/string_atom_spec.rb
nydp-0.2.1 spec/string_atom_spec.rb
nydp-0.2.0 spec/string_atom_spec.rb