Skip to content

Commit

Permalink
Merge pull request #182 from faultyserver/feature/type_equality
Browse files Browse the repository at this point in the history
Closes #173. Implement a base type, `Type` + various methods and fixes
  • Loading branch information
faultyserver authored Apr 5, 2018
2 parents 04d39c7 + 963449b commit d501552
Show file tree
Hide file tree
Showing 35 changed files with 386 additions and 141 deletions.
2 changes: 1 addition & 1 deletion spec/interpreter/closure_scope_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe "Interpreter - ClosureScope" do
it "removes all entries from the scope" do
scope = ClosureScope.new(Scope.new)
scope["a"] = TNil.new
scope["Thing"] = TType.new("Thing")
scope["Thing"] = TType.new("Thing", nil, nil)
scope["x"] = 100_i64

scope.values.size.should eq(3)
Expand Down
8 changes: 4 additions & 4 deletions spec/interpreter/matcher_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe "Interpreter - #match" do
# end
itr = Interpreter.new
mod_foo = TModule.new("Foo")
type_bar = TType.new("Bar")
type_bar = TType.new("Bar", nil)
type_bar.insert_ancestor(mod_foo)

itr.current_scope.assign("Foo", mod_foo)
Expand All @@ -151,7 +151,7 @@ describe "Interpreter - #match" do
itr = Interpreter.new
mod_foo = TModule.new("Foo")
mod_bar = TModule.new("Bar")
type_baz = TType.new("Baz")
type_baz = TType.new("Baz", nil)
mod_bar.insert_ancestor(mod_foo)
type_baz.insert_ancestor(mod_bar)

Expand All @@ -167,7 +167,7 @@ describe "Interpreter - #match" do
itr = Interpreter.new
mod_foo = TModule.new("Foo")
mod_bar = TModule.new("Bar")
type_baz = TType.new("Baz")
type_baz = TType.new("Baz", nil)
type_baz.insert_ancestor(mod_foo)
type_baz.insert_ancestor(mod_bar)

Expand All @@ -181,7 +181,7 @@ describe "Interpreter - #match" do
# end
itr = Interpreter.new
mod_foo = TModule.new("Foo")
type_bar = TType.new("Bar")
type_bar = TType.new("Bar", nil)
type_bar.extend_module(mod_foo)

itr.current_scope.assign("Foo", mod_foo)
Expand Down
2 changes: 1 addition & 1 deletion spec/interpreter/nodes/type_def_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe "Interpreter - TypeDef" do
end
) do |typ, itr|
typ.should be_a(Myst::TType)
typ.scope.values.size.should eq(1)
typ.scope.values.size.should eq(0)
typ.scope.parent.should eq(itr.current_scope)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/interpreter/scope_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe "Interpreter - Scope" do
it "removes all entries from the scope" do
scope = Scope.new
scope["a"] = TNil.new
scope["Thing"] = TType.new("Thing")
scope["Thing"] = TType.new("Thing", nil)
scope["x"] = 100_i64

scope.values.size.should eq(3)
Expand Down
62 changes: 31 additions & 31 deletions spec/myst/assert_spec.mt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end
def test_raises(&block)
block()
rescue ex
test_assert(ex.type.to_s == "AssertionFailure")
test_assert(ex.type == Assert.AssertionFailure)
end

describe("Assert") do
Expand All @@ -17,11 +17,11 @@ describe("Assert") do

describe("#is_truthy") do
it("returns the assertion object when the assertion succeeds") do
test_assert(true_subject.is_truthy.type.to_s == "Assertion")
test_assert(true_subject.is_truthy.type == Assert.Assertion)
end

it("passes when the value is anything truthy") do
test_assert(assert([]).is_truthy.type.to_s == "Assertion")
test_assert(assert([]).is_truthy.type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is not truthy") do
Expand All @@ -31,12 +31,12 @@ describe("Assert") do

describe("#is_falsey") do
it("returns the assertion object when the assertion succeeds") do
test_assert(false_subject.is_falsey.type.to_s == "Assertion")
test_assert(false_subject.is_falsey.type == Assert.Assertion)
end


it("passes when the value is anything nil") do
test_assert(assert(nil).is_falsey.type.to_s == "Assertion")
test_assert(assert(nil).is_falsey.type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is not truthy") do
Expand All @@ -46,7 +46,7 @@ describe("Assert") do

describe("#is_true") do
it("returns the assertion object when the assertion succeeds") do
test_assert(true_subject.is_true.type.to_s == "Assertion")
test_assert(true_subject.is_true.type == Assert.Assertion)
end

it("does not pass unless the value is exactly `true`") do
Expand All @@ -60,7 +60,7 @@ describe("Assert") do

describe("#is_false") do
it("returns the assertion object when the assertion succeeds") do
test_assert(false_subject.is_false.type.to_s == "Assertion")
test_assert(false_subject.is_false.type == Assert.Assertion)
end

it("does not pass unless the value is exactly `false`") do
Expand All @@ -74,7 +74,7 @@ describe("Assert") do

describe("#is_nil") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(nil).is_nil.type.to_s == "Assertion")
test_assert(assert(nil).is_nil.type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is not `nil`") do
Expand All @@ -84,11 +84,11 @@ describe("Assert") do

describe("#is_not_nil") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(true).is_not_nil.type.to_s == "Assertion")
test_assert(assert(true).is_not_nil.type == Assert.Assertion)
end

it("passes when the value is `false`") do
test_assert(assert(false).is_not_nil.type.to_s == "Assertion")
test_assert(assert(false).is_not_nil.type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is `nil`") do
Expand All @@ -99,7 +99,7 @@ describe("Assert") do

describe("#equals") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(true).equals(true).type.to_s == "Assertion")
test_assert(assert(true).equals(true).type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is not equal to its argument") do
Expand All @@ -109,7 +109,7 @@ describe("Assert") do

describe("#does_not_equal") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(true).does_not_equal(false).type.to_s == "Assertion")
test_assert(assert(true).does_not_equal(false).type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is equal to its argument") do
Expand All @@ -120,7 +120,7 @@ describe("Assert") do

describe("#less_than") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(1).less_than(2).type.to_s == "Assertion")
test_assert(assert(1).less_than(2).type == Assert.Assertion)
end

it("does not pass when the values are equal") do
Expand All @@ -134,11 +134,11 @@ describe("Assert") do

describe("#less_or_equal") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(1).less_or_equal(2).type.to_s == "Assertion")
test_assert(assert(1).less_or_equal(2).type == Assert.Assertion)
end

it("passes when the values are equal") do
test_assert(assert(1).less_or_equal(1).type.to_s == "Assertion")
test_assert(assert(1).less_or_equal(1).type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is not less or equal than its argument") do
Expand All @@ -148,11 +148,11 @@ describe("Assert") do

describe("#greater_or_equal") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(2).greater_or_equal(1).type.to_s == "Assertion")
test_assert(assert(2).greater_or_equal(1).type == Assert.Assertion)
end

it("passes when the values are equal") do
test_assert(assert(1).greater_or_equal(1).type.to_s == "Assertion")
test_assert(assert(1).greater_or_equal(1).type == Assert.Assertion)
end

it("raises an AssertionFailure if the value is not greater or equal than its argument") do
Expand All @@ -162,7 +162,7 @@ describe("Assert") do

describe("#greater_than") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(2).greater_than(1).type.to_s == "Assertion")
test_assert(assert(2).greater_than(1).type == Assert.Assertion)
end

it("does not pass when the values are equal") do
Expand All @@ -177,7 +177,7 @@ describe("Assert") do

describe("#between") do
it("returns the assertion object when the assertion succeeds") do
test_assert(assert(1).between(0, 2).type.to_s == "Assertion")
test_assert(assert(1).between(0, 2).type == Assert.Assertion)
end

it("passes when the value is equal to the lower argument") do
Expand All @@ -196,45 +196,45 @@ describe("Assert") do

describe("#<") do
it("acts like #less_than") do
test_assert(assert(1).less_than(2).type.to_s == "Assertion")
test_assert(assert(1).less_than(2).type == Assert.Assertion)
test_raises{ assert(1).less_than(1) }
test_raises{ assert(2).less_than(1) }
end
end

describe("#<=") do
it("acts like #less_or_equal") do
test_assert(assert(1).less_or_equal(2).type.to_s == "Assertion")
test_assert(assert(1).less_or_equal(1).type.to_s == "Assertion")
test_assert(assert(1).less_or_equal(2).type == Assert.Assertion)
test_assert(assert(1).less_or_equal(1).type == Assert.Assertion)
test_raises{ assert(2).less_or_equal(1) }
end
end

describe("#==") do
it("acts like #equals") do
test_assert(assert(true).equals(true).type.to_s == "Assertion")
test_assert(assert(true).equals(true).type == Assert.Assertion)
test_raises{ assert(true).equals(false) }
end
end

describe("#!=") do
it("acts like #does_not_equal") do
test_assert(assert(true).does_not_equal(false).type.to_s == "Assertion")
test_assert(assert(true).does_not_equal(false).type == Assert.Assertion)
test_raises{ assert(true).equals(true) }
end
end

describe("#>=") do
it("acts like #greater_or_equal") do
test_assert(assert(2).greater_or_equal(1).type.to_s == "Assertion")
test_assert(assert(1).greater_or_equal(1).type.to_s == "Assertion")
test_assert(assert(2).greater_or_equal(1).type == Assert.Assertion)
test_assert(assert(1).greater_or_equal(1).type == Assert.Assertion)
test_raises{ assert(1).greater_or_equal(2) }
end
end

describe("#>") do
it("acts like #greater_than") do
test_assert(assert(2).greater_than(1).type.to_s == "Assertion")
test_assert(assert(2).greater_than(1).type == Assert.Assertion)
test_raises{ assert(1).greater_than(1) }
test_raises{ assert(1).greater_than(1) }
end
Expand All @@ -250,7 +250,7 @@ describe("Assert") do
describe("#raises") do
describe("with no arguments") do
it("returns the blockassertion object when the block raises any error") do
test_assert(raising_subject.raises.type.to_s == "BlockAssertion")
test_assert(raising_subject.raises.type == Assert.BlockAssertion)
end

it("raises an AssertionFailure when the block does not raise an error") do
Expand All @@ -260,7 +260,7 @@ describe("Assert") do

describe("with an error argument") do
it("returns the blockassertion object if the block raises the given error") do
test_assert(raising_subject.raises(:foo).type.to_s == "BlockAssertion")
test_assert(raising_subject.raises(:foo).type == Assert.BlockAssertion)
end

it("raises an AssertionFailure when the block does not raise an error") do
Expand All @@ -275,7 +275,7 @@ describe("Assert") do

describe("#succeeds") do
it("returns the blockassertion object when the block does not raise an error") do
test_assert(passing_subject.succeeds.type.to_s == "BlockAssertion")
test_assert(passing_subject.succeeds.type == Assert.BlockAssertion)
end

it("raises an AssertionFailure when the block does raise an error") do
Expand All @@ -285,7 +285,7 @@ describe("Assert") do

describe("#returns") do
it("returns the blockassertion object when the block returns the expected value") do
test_assert(passing_subject.returns(:passing).type.to_s == "BlockAssertion")
test_assert(passing_subject.returns(:passing).type == Assert.BlockAssertion)
end

it("raises an AssertionFailure when the block does not return the expected value") do
Expand Down
3 changes: 1 addition & 2 deletions spec/myst/file_spec.mt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ describe("File") do
describe(".open") do
it("returns a new File instance for the given file") do
file = File.open("spec/support/misc/fixed_size_file.txt", "r")

assert(file.type.to_s).equals("File")
assert(file).is_a(File)
end

it("defaults to 'read' mode if no mode is given") do
Expand Down
6 changes: 3 additions & 3 deletions spec/myst/random_spec.mt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("Random") do
describe("#rand") do
describe("without arguments") do
it("returns a Float value") do
assert(Random.rand.type.to_s).equals("Float")
assert(Random.rand).is_a(Float)
end

it("returns a value in the range [0, 1]") do
Expand All @@ -15,7 +15,7 @@ describe("Random") do

describe("with an Integer argument") do
it("returns an Integer value") do
assert(Random.rand(500).type.to_s).equals("Integer")
assert(Random.rand(500)).is_a(Integer)
end

it("returns a value between 0 and the given maximum") do
Expand All @@ -26,7 +26,7 @@ describe("Random") do

describe("with a Float argument") do
it("returns a Float value") do
assert(Random.rand(500.0).type.to_s).equals("Float")
assert(Random.rand(500.0)).is_a(Float)
end

it("returns a value between 0 and the given maximum") do
Expand Down
Loading

0 comments on commit d501552

Please sign in to comment.