Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use is: and is_not: in tests since it's less noisy and reads nicer.

  • Loading branch information...
commit 656e9dfd1945a88167c0913236a851d35c48c2af 1 parent 585d484
@bakkdoor authored
View
4 tests/argv.fy
@@ -1,10 +1,10 @@
FancySpec describe: "ARGV & predefined values" with: {
it: "has ARGV correctly defined" when: {
- ARGV empty? is_not == true
+ ARGV empty? is_not: true
}
it: "has a __FILE__ variable defined" when: {
- __FILE__ is_not == nil
+ __FILE__ is_not: nil
__FILE__ is =~ /\/argv.fy$/
}
}
View
386 tests/array.fy
@@ -4,14 +4,14 @@ FancySpec describe: Array with: {
arr << 1
arr << 2
arr << 3
- arr is == [1,2,3]
- arr size is == 3
+ arr is: [1,2,3]
+ arr size is: 3
}
it: "iterates over all elements, calling a block" with: 'each: when: {
sum = 0
[1,2,3,4,5] each: |x| { sum = sum + x }
- sum is == ([1,2,3,4,5] sum)
+ sum is: $ [1,2,3,4,5] sum
}
it: "iterates over all elements with their index" with: 'each_with_index: when: {
@@ -21,456 +21,466 @@ FancySpec describe: Array with: {
sum = sum + x
idx_sum = idx_sum + i
}
- sum is == 150
- idx_sum is == 10
+ sum is: 150
+ idx_sum is: 10
}
it: "is empty after clearing it" with: 'clear when: {
arr = [1,2,3]
- arr size is == 3
- arr is == [1,2,3]
+ arr size is: 3
+ arr is: [1,2,3]
arr clear
- arr size is == 0
- arr is == []
+ arr size is: 0
+ arr is: []
}
it: "is true for empty? when it's empty" with: 'empty? when: {
- [] empty? is == true
- [1] empty? is == false
- [1,2] empty? is == false
- [1,2,3] empty? is == false
+ [] empty? is: true
+ [1] empty? is: false
+ [1,2] empty? is: false
+ [1,2,3] empty? is: false
}
it: "is an empty array after initialization" with: 'new when: {
arr = Array new
- arr size is == 0
+ arr size is: 0
}
it: "returns the correct value via index access" with: 'at: when: {
arr = ['a, 10, "hello, world"]
- arr at: 2 . is == "hello, world"
- arr at: 1 . is == 10
- arr at: 0 . is == 'a
+ arr at: 2 . is: "hello, world"
+ arr at: 1 . is: 10
+ arr at: 0 . is: 'a
}
it: "sets the value for a given index" with: '[]: when: {
arr = [1,2,3]
arr[0]: 10
- arr is == [10, 2, 3]
+ arr is: [10, 2, 3]
arr[-1]: 30
- arr is == [10, 2, 30]
+ arr is: [10, 2, 30]
arr[1]: 20
- arr is == [10,20,30]
+ arr is: [10,20,30]
arr[3]: 40
- arr is == [10,20,30,40]
+ arr is: [10,20,30,40]
}
it: "does NOT include the items" with: 'includes?: when: {
arr = ['a, 10, "hello, world"]
- arr includes?: "hello" . is == false
- arr includes?: 11 . is == false
- arr includes?: 'b . is == false
+ arr includes?: "hello" . is: false
+ arr includes?: 11 . is: false
+ arr includes?: 'b . is: false
}
it: "includes the items" with: 'includes?: when: {
arr = ['a, 10, "hello, world"]
- arr includes?: "hello, world" . is == true
- arr includes?: 10 . is == true
- arr includes?: 'a . is == true
+ arr includes?: "hello, world" . is: true
+ arr includes?: 10 . is: true
+ arr includes?: 'a . is: true
}
it: "returns the correct index (or nil) for an element" with: 'index: when: {
arr = [1, 2, 'a, 3, 4]
- arr index: 1 . is == 0
- arr index: 2 . is == 1
- arr index: 'a . is == 2
- arr index: 3 . is == 3
- arr index: 4 . is == 4
- arr index: 'foo . is == nil
+ arr index: 1 . is: 0
+ arr index: 2 . is: 1
+ arr index: 'a . is: 2
+ arr index: 3 . is: 3
+ arr index: 4 . is: 4
+ arr index: 'foo . is: nil
}
it: "returns an Array of all its indices" with: 'indices when: {
- ['foo, 'bar, 'baz] indices is == [0,1,2]
- [] indices is == []
- ['foo] indices is == [0]
+ ['foo, 'bar, 'baz] indices is: [0,1,2]
+ [] indices is: []
+ ['foo] indices is: [0]
}
it: "returns all indices for an element as an Array" with: 'indices_of: when: {
arr = [1, 2, 'a, 3, 2, 'a]
- arr indices_of: 1 . is == [0]
- arr indices_of: 2 . is == [1, 4]
- arr indices_of: 'a . is == [2, 5]
- arr indices_of: 3. is == [3]
- arr indices_of: 'foo . is == []
+ arr indices_of: 1 . is: [0]
+ arr indices_of: 2 . is: [1, 4]
+ arr indices_of: 'a . is: [2, 5]
+ arr indices_of: 3. is: [3]
+ arr indices_of: 'foo . is: []
}
it: "finds the value" with: 'find: when: {
arr = ['foo, "bar", 'baz, 1234]
- arr find: "bar" . is == "bar"
+ arr find: "bar" . is: "bar"
arr find: |x| {
x is_a?: String . if_true: {
x from: 0 to: 1 == "ba"
}
- } . is == "bar"
+ } . is: "bar"
- arr find: "foo" . is == nil
+ arr find: "foo" . is: nil
}
it: "does NOT find the value" with: 'find: when: {
arr = ['foo, "bar", 'baz, 1234]
- arr find: "ba" . is == nil
+ arr find: "ba" . is: nil
arr find: |x| {
x is_a?: String . if_true: {
x from: 0 to: 1 == "aa"
}
- } . is == nil
+ } . is: nil
- arr find: "foobar" . is == nil
+ arr find: "foobar" . is: nil
}
it: "finds the value via a block" with: 'find_by: when: {
arr = [1, 2, 'foo, "yo", nil, true]
- arr find_by: |x| { x is_a?: String } . is == "yo"
- arr find_by: |x| { x is_a?: Block } . is == nil
+ arr find_by: |x| { x is_a?: String } . is: "yo"
+ arr find_by: |x| { x is_a?: Block } . is: nil
}
it: "returns the last element" with: 'last when: {
arr = [1, 2, 3, 'foo, "bar"]
- arr last is == "bar"
- (arr last == 'foo) is == false
+ arr last is: "bar"
+ (arr last == 'foo) is: false
}
it: "returns the last n element" with: 'last: when: {
arr = [1, 2, 3, 'foo, "bar"]
- arr last: 1 . is == [arr last]
- arr last: 2 . is == ['foo, "bar"]
- arr last: 3 . is == [3, 'foo, "bar"]
- arr last: 4 . is == [2, 3, 'foo, "bar"]
- arr last: 5 . is == [1, 2, 3, 'foo, "bar"]
- arr last: (arr size) . is == arr
- arr last: (arr size + 1) . is == arr
+ arr last: 1 . is: [arr last]
+ arr last: 2 . is: ['foo, "bar"]
+ arr last: 3 . is: [3, 'foo, "bar"]
+ arr last: 4 . is: [2, 3, 'foo, "bar"]
+ arr last: 5 . is: [1, 2, 3, 'foo, "bar"]
+ arr last: (arr size) . is: arr
+ arr last: (arr size + 1) . is: arr
}
it: "returns an array containing the values at the given indices" with: 'values_at: when: {
arr = [1, 2, 3, 'foo, "bar"]
- arr values_at: [1, 3, 4, 10] . is == [2, 'foo, "bar", nil]
+ arr values_at: [1, 3, 4, 10] . is: [2, 'foo, "bar", nil]
}
it: "returns unique values only" with: 'uniq when: {
arr = ['foo, 'bar, "baz", 'foo, "baz", "hello", 1, 0, 0, 1, 'bar, 'foo, "hello"]
- arr uniq is == ['foo, 'bar, "baz", "hello", 1, 0]
+ arr uniq is: ['foo, 'bar, "baz", "hello", 1, 0]
}
it: "prepends self to another array" with: '>> when: {
arr1 = ['foo, 'bar, 'baz]
arr2 = [1, 2, 3]
- (arr1 >> arr2) is == ['foo, 'bar, 'baz, 1, 2, 3]
+ (arr1 >> arr2) is: ['foo, 'bar, 'baz, 1, 2, 3]
}
it: "returns an element by the []-operator" with: '[] when: {
arr = ['foo, 'bar, 'baz]
- arr[0] is == 'foo
- arr[1] is == 'bar
- arr[2] is == 'baz
+ arr[0] is: 'foo
+ arr[1] is: 'bar
+ arr[2] is: 'baz
}
it: "returns a sub-array by the []-operator" with: '[] when: {
arr = ['foo, 'bar, 'baz]
- arr[[0,2]] is == arr
- arr[[0,1]] is == ['foo, 'bar]
- arr[[0,1]] is == (arr from: 0 to: 1)
- arr[[0,0]] is == [arr[0]]
- arr[[1,1]] is == [arr[1]]
- arr[[2,2]] is == [arr[2]]
- arr[[0,-1]] is == arr
- arr[[-1,-1]] is == [arr last]
- arr[[-2,-1]] is == ['bar, 'baz]
- arr[[-2,-1]] is == (arr last: 2)
+ arr[[0,2]] is: arr
+ arr[[0,1]] is: ['foo, 'bar]
+ arr[[0,1]] is: (arr from: 0 to: 1)
+ arr[[0,0]] is: [arr[0]]
+ arr[[1,1]] is: [arr[1]]
+ arr[[2,2]] is: [arr[2]]
+ arr[[0,-1]] is: arr
+ arr[[-1,-1]] is: [arr last]
+ arr[[-2,-1]] is: ['bar, 'baz]
+ arr[[-2,-1]] is: (arr last: 2)
}
it: "joins all elements with a string to a new string" with: 'join: when: {
arr = ['foo, 'bar, 'baz]
- arr join: "," . is == "foo,bar,baz"
+ arr join: "," . is: "foo,bar,baz"
}
it: "joins all elements with the empty string to a new string" with: 'join when: {
arr = ['foo, 'bar, 'baz]
- arr join is == "foobarbaz"
+ arr join is: "foobarbaz"
}
it: "removes an element at a given index" with: 'remove_at: when: {
arr = [1, 'foo, 2, 'bar, 3, 'baz]
# remove_at: returns the removed element
- arr remove_at: 1 . is == 'foo
- arr is == [1, 2, 'bar, 3, 'baz]
+ arr remove_at: 1 . is: 'foo
+ arr is: [1, 2, 'bar, 3, 'baz]
arr remove_at: 3
- arr is == [1, 2, 'bar, 'baz]
+ arr is: [1, 2, 'bar, 'baz]
arr remove_at: [2, 3]
- arr is == [1, 2]
+ arr is: [1, 2]
arr = [1, 'hello, 2, 'world]
# remove_at: returns the removed elements as an array
# if it was passed an array of indexes
- arr remove_at: [0, 2, 3] . is == [1, 2, 'world]
- arr is == ['hello]
+ arr remove_at: [0, 2, 3] . is: [1, 2, 'world]
+ arr is: ['hello]
}
it: "removes all occurances of a given object in-place" with: 'remove: when: {
arr = [1, 2, 'foo, 3, 'foo, 2, 4]
arr remove: 2
- arr is == [1, 'foo, 3, 'foo, 4]
+ arr is: [1, 'foo, 3, 'foo, 4]
arr remove: 'foo
- arr is == [1, 3, 4]
+ arr is: [1, 3, 4]
}
it: "removes all elements with the given Array of indices" with: 'remove_at: when: {
arr = [1, 2, 'foo, 3, 'foo, 2, 4]
arr remove_at: [0, 2, 4]
- arr is == [2, 3, 2, 4]
+ arr is: [2, 3, 2, 4]
}
it: "removes all elements that meet a given condition block" with: 'remove_if: when: {
arr = [1, 2, 3, 2, 5, 4]
arr remove_if: |x| { x < 3 }
- arr is == [3, 5, 4]
+ arr is: [3, 5, 4]
}
it: "removes all nil-value entries when calling compact" with: 'compact when: {
- ['foo, nil, 'bar, nil, 'baz] compact is == ['foo, 'bar, 'baz]
- [] compact is == []
- [nil] compact is == []
- ['foo] compact is == ['foo]
+ ['foo, nil, 'bar, nil, 'baz] compact is: ['foo, 'bar, 'baz]
+ [] compact is: []
+ [nil] compact is: []
+ ['foo] compact is: ['foo]
}
it: "removes all nil-value entries in place when calling compact!" with: 'compact! when: {
arr = ['foo, nil, 'bar, nil, 'baz]
- arr compact! is == ['foo, 'bar, 'baz]
- arr is == ['foo, 'bar, 'baz]
- [] compact! is == []
- [nil] compact! is == []
- ['foo] compact! is == ['foo]
+ arr compact! is: ['foo, 'bar, 'baz]
+ arr is: ['foo, 'bar, 'baz]
+ [] compact! is: []
+ [nil] compact! is: []
+ ['foo] compact! is: ['foo]
}
it: "removes all values that meet a condition" with: 'reject!: when: {
arr = ['foo, 'bar, 1, 2, 'baz, "hello"]
- arr reject!: |x| { x is_a?: String } . is == ['foo, 'bar, 1, 2, 'baz]
- arr is == ['foo, 'bar, 1, 2, 'baz]
+ arr reject!: |x| { x is_a?: String } . is: ['foo, 'bar, 1, 2, 'baz]
+ arr is: ['foo, 'bar, 1, 2, 'baz]
arr reject!: |x| { x is_a?: Fixnum }
- arr is == ['foo, 'bar, 'baz]
+ arr is: ['foo, 'bar, 'baz]
}
it: "removes all values that don't meet a condition" with: 'select!: when: {
arr = ['foo, 'bar, 1, 2, 'baz, "hello"]
arr select!: |x| { x is_a?: Fixnum }
- arr is == [1, 2]
+ arr is: [1, 2]
}
it: "returns a new Array with all elements that meet a given condition" with: 'select: when: {
arr = [1, 2, "foo", 'bar, 120]
- arr select: |x| { x is_a?: Fixnum } . is == [1,2,120]
- arr is == [1, 2, "foo", 'bar, 120] # select: is non-destructive
+ arr select: |x| { x is_a?: Fixnum } . is: [1,2,120]
+ arr is: [1, 2, "foo", 'bar, 120] # select: is non-destructive
}
it: "returns the maximum value in the list" with: 'max when: {
- [1,2,3,4] max is == 4
- [1,5,-3,2,6,-4,-2] max is == 6
+ [1,2,3,4] max is: 4
+ [1,5,-3,2,6,-4,-2] max is: 6
}
it: "prints the minimum value in the list" with: 'min when: {
- [1,2,3,4] min is == 1
- [1,5,-3,2,6,-4,-2] min is == -4
+ [1,2,3,4] min is: 1
+ [1,5,-3,2,6,-4,-2] min is: -4
}
it: "returns an Array containing the elements n times." with: '* when: {
- [1,2,3,4,5] * 2 is == [1,2,3,4,5,1,2,3,4,5]
- [1,2,3] * 2 is == ([1,2,3] + [1,2,3])
- ['a,'b,'c] * 4 is == ['a,'b,'c, 'a,'b,'c, 'a,'b,'c, 'a,'b,'c]
+ [1,2,3,4,5] * 2 is: [1,2,3,4,5,1,2,3,4,5]
+ [1,2,3] * 2 is: ([1,2,3] + [1,2,3])
+ ['a,'b,'c] * 4 is: ['a,'b,'c, 'a,'b,'c, 'a,'b,'c, 'a,'b,'c]
}
it: "returns the concatenation of two Arrays" with: '+ when: {
- ([1,2,3,4] + [-1,-2,-3,-4]) is == [1,2,3,4,-1,-2,-3,-4]
+ ([1,2,3,4] + [-1,-2,-3,-4]) is: [1,2,3,4,-1,-2,-3,-4]
}
it: "returns true for all elements" with: 'all?: when: {
- [1,2,3,4] all?: |x| { x < 5 } . is == true
- [1,2,3,4] all?: |x| { x > 0 } . is == true
- [1,2,3,4] all?: |x| { x > 4 } . is == false
+ [1,2,3,4] all?: |x| { x < 5 } . is: true
+ [1,2,3,4] all?: |x| { x > 0 } . is: true
+ [1,2,3,4] all?: |x| { x > 4 } . is: false
}
it: "returns true for any elements" with: 'any?: when: {
- [1,2,3,4] any?: |x| { x > 3 } . is == true
- [1,2,3,4] any?: |x| { x < 4 } . is == true
- [1,2,3,4] any?: |x| { x > 4 } . is == false
+ [1,2,3,4] any?: |x| { x > 3 } . is: true
+ [1,2,3,4] any?: |x| { x < 4 } . is: true
+ [1,2,3,4] any?: |x| { x > 4 } . is: false
}
it: "is selected from it with each index" with: 'select_with_index: when: {
- ["yooo",2,3,1,'foo,"bar"] select_with_index: |x i| { x is_a?: Fixnum } . is == [[2,1], [3,2], [1,3]]
+ ["yooo",2,3,1,'foo,"bar"] select_with_index: |x i| { x is_a?: Fixnum } . is: [[2,1], [3,2], [1,3]]
}
it: "returns its remaining (all but the first) elements as a new Array" with: 'rest when: {
- [1,2,3,4] rest is == [2,3,4]
- [] rest is == []
- 100 upto: 1000 . rest is == (101 upto: 1000)
+ [1,2,3,4] rest is: [2,3,4]
+ [] rest is: []
+ 100 upto: 1000 . rest is: (101 upto: 1000)
}
it: "returns itself as a string" with: 'to_s when: {
- [1,2,3] to_s is == "123"
+ [1,2,3] to_s is: "123"
}
it: "calls a given block between calling the each block" with: 'each:in_between: when: {
arr = []
[1,2,3] each: |x| { arr << x } in_between: { arr << "-" }
- arr is == [1, "-", 2, "-", 3]
+ arr is: [1, "-", 2, "-", 3]
str = ""
['foo, 'bar, 'baz] each: |x| { str = str ++ (x to_s) } in_between: { str = str ++ " " }
- str is == "foo bar baz"
+ str is: "foo bar baz"
}
it: "returns the reduced value for a given block and initial value" with: 'reduce:init_val: when: {
arr = 1 upto: 10
- arr sum is == (arr reduce: '+ init_val: 0)
- arr product is == (arr reduce: '* init_val: 1)
- arr to_s is == (arr reduce: '++ init_val: "")
+ arr sum is: (arr reduce: '+ init_val: 0)
+ arr product is: (arr reduce: '* init_val: 1)
+ arr to_s is: (arr reduce: '++ init_val: "")
}
it: "returns the reverse of itself" with: 'reverse when: {
- [1,2,3] reverse is == [3,2,1]
- 1 upto: 10 . reverse is == (10 downto: 1)
+ [1,2,3] reverse is: [3,2,1]
+ 1 upto: 10 . reverse is: (10 downto: 1)
}
it: "inverses in-place" with: 'reverse! when: {
arr = [1,2,3]
- arr reverse! is == [3,2,1]
- arr is == [3,2,1]
+ arr reverse! is: [3,2,1]
+ arr is: [3,2,1]
}
it: "takes elements from itself as long a block yields true" with: 'take_while: when: {
- 1 upto: 15 . take_while: |x| { x < 10 } . is == (1 upto: 9)
+ 1 upto: 15 . take_while: |x| { x < 10 } . is: (1 upto: 9)
}
it: "drops elements from itself as long a block yields true" with: 'drop_while: when: {
- 1 upto: 15 . drop_while: |x| { x < 10 } . is == (10 upto: 15)
+ 1 upto: 15 . drop_while: |x| { x < 10 } . is: (10 upto: 15)
}
it: "partitions an array via a given block" with: 'partition_by: when: {
arr = [1,2,2,3,3,3,4,4,4,4,5]
- arr partition_by: 'identity . is == [[1], [2,2], [3,3,3], [4,4,4,4], [5]]
- arr partition_by: @{== 2} . is == [[1], [2,2], [3,3,3,4,4,4,4,5]]
+ arr partition_by: 'identity . is: [[1], [2,2], [3,3,3], [4,4,4,4], [5]]
+ arr partition_by: @{== 2} . is: [[1], [2,2], [3,3,3,4,4,4,4,5]]
}
it: "removes the first value" with: 'shift when: {
a = [1,2,3]
- a shift is == 1
- a is == [2,3]
+ a shift is: 1
+ a is: [2,3]
a = []
- a shift is == nil
- a is == []
+ a shift is: nil
+ a is: []
}
it: "appends a value at the front" with: 'unshift: when: {
a = []
- a unshift: 1 . is == a # is return self
- a is == [1]
+ a unshift: 1 . is: a # is return self
+ a is: [1]
a = [1,2,3]
- a unshift: (a shift) . is == a
- a is == [1,2,3]
+ a unshift: (a shift) . is: a
+ a is: [1,2,3]
}
it: "compares 2 arrays without regard to order" with: '=? when: {
- [1,2,3] =? [2,1,3] is == true
- [1,2,3,4] =? [2,1,4,3] is == true
- [1,2] =? [1,2,3] is == false
- [1,2] =? [2] is == false
- [2] =? [1,2] is == false
- [] =? [] is == true
- [1] =? [1] is == true
+ [1,2,3] =? [2,1,3] is: true
+ [1,2,3,4] =? [2,1,4,3] is: true
+ [1,2] =? [1,2,3] is: false
+ [1,2] =? [2] is: false
+ [2] =? [1,2] is: false
+ [] =? [] is: true
+ [1] =? [1] is: true
}
it: "returns the first element" with: 'first when: {
- [1,2] first is == 1
- [1] first is == 1
- [] first is == nil
+ [1,2] first is: 1
+ [1] first is: 1
+ [] first is: nil
}
it: "returns the second element" with: 'second when: {
- [1,2,3] second is == 2
- [1,2] second is == 2
- [1] second is == nil
- [] second is == nil
+ [1,2,3] second is: 2
+ [1,2] second is: 2
+ [1] second is: nil
+ [] second is: nil
}
it: "returns the third element" with: 'third when: {
- [1,2,3,4] third is == 3
- [1,2,3] third is == 3
- [1,2] third is == nil
- [1] third is == nil
- [] third is == nil
+ [1,2,3,4] third is: 3
+ [1,2,3] third is: 3
+ [1,2] third is: nil
+ [1] third is: nil
+ [] third is: nil
}
it: "returns the fourth element" with: 'fourth when: {
- [1,2,3,4,5] fourth is == 4
- [1,2,3,4] fourth is == 4
- [1,2,3] fourth is == nil
- [1,2] fourth is == nil
- [1] fourth is == nil
- [] fourth is == nil
+ [1,2,3,4,5] fourth is: 4
+ [1,2,3,4] fourth is: 4
+ [1,2,3] fourth is: nil
+ [1,2] fourth is: nil
+ [1] fourth is: nil
+ [] fourth is: nil
}
it: "returns all but the first element" with: 'rest when: {
- [1,2,3,4] rest is == [2,3,4]
- [2,3] rest is == [3]
- [1] rest is == []
- [] rest is == []
+ [1,2,3,4] rest is: [2,3,4]
+ [2,3] rest is: [3]
+ [1] rest is: []
+ [] rest is: []
}
it: "returns a clone" with: 'clone when: {
- [1,2,3] clone is == [1,2,3]
- [1] clone is == [1]
- [] clone is == []
+ [1,2,3] clone is: [1,2,3]
+ [1] clone is: [1]
+ [] clone is: []
}
it: "calculates the sum for an Array of numbers" with: 'sum when: {
- [1,2,3] sum is == 6
- [1] sum is == 1
- [] sum is == 0
+ [1,2,3] sum is: 6
+ [1] sum is: 1
+ [] sum is: 0
}
it: "calculates the product for an Array of numbers" with: 'product when: {
- [1,2,3,4] product is == 24
- [1] product is == 1
- [] product is == 1
+ [1,2,3,4] product is: 24
+ [1] product is: 1
+ [] product is: 1
+ }
+
+ it: "calculates the average for an Array of numbers" with: 'average when: {
+ [] average is: 0
+ [-1] average is: -1
+ [0] average is: 0
+ [1] average is: 1
+ [1,2] average is: 1.5
+ [1,2,3] average is: 2
+ [1,2,3,4] average is: 2.5
}
it: "sorts the array" with: 'sort when: {
arr = [1,5,4,2,3]
- arr sort is == [1,2,3,4,5]
- arr is == [1,5,4,2,3]
+ arr sort is: [1,2,3,4,5]
+ arr is: [1,5,4,2,3]
}
it: "sorts the array with a given comparison block" with: 'sort_by: when: {
arr = [1,5,4,2,3]
sorted = [1,2,3,4,5]
- arr sort_by: |a b| { a <=> b } is == sorted
- arr is == [1,5,4,2,3]
+ arr sort_by: |a b| { a <=> b } . is: sorted
+ arr is: [1,5,4,2,3]
arr = [(1,2), (0,1), (3,0)]
sorted = [(3,0), (0,1), (1,2)]
- arr sort_by: |a b| { a second <=> (b second) } . is == sorted
- arr sort_by: 'second . is == sorted
+ arr sort_by: |a b| { a second <=> (b second) } . is: sorted
+ arr sort_by: 'second . is: sorted
}
it: "returns the array in groups of 3" with: 'in_groups_of: when: {
- ['a,'b,'c] in_groups_of: 1 . is == [['a],['b],['c]]
+ ['a,'b,'c] in_groups_of: 1 . is: [['a],['b],['c]]
array = 1 upto: 10
- array in_groups_of: 3 . is == [[1,2,3], [4,5,6], [7,8,9], [10]]
+ array in_groups_of: 3 . is: [[1,2,3], [4,5,6], [7,8,9], [10]]
- (20,30,40) in_groups_of: 2 . is == [[20,30], [40]]
+ (20,30,40) in_groups_of: 2 . is: [[20,30], [40]]
}
}
View
52 tests/assignment.fy
@@ -1,53 +1,53 @@
FancySpec describe: "Assignment" with: {
it: "correctly assigns multiple values at once" when: {
x, y, z = 1, 10, 100
- x is == 1
- y is == 10
- z is == 100
+ x is: 1
+ y is: 10
+ z is: 100
x, y, z = 'foo, 'bar
- x is == 'foo
- y is == 'bar
- z is == nil
+ x is: 'foo
+ y is: 'bar
+ z is: nil
x = 'foo
y = 'bar
x, y = y, x
- x is == 'bar
- y is == 'foo
+ x is: 'bar
+ y is: 'foo
}
it: "handles multiple assignment for any collection type implementing 'at:" when: {
x, y, z = (1, 2, 3)
- x is == 1
- y is == 2
- z is == 3
+ x is: 1
+ y is: 2
+ z is: 3
a, b, c = ["a", "b", "c"]
- a is == "a"
- b is == "b"
- c is == "c"
+ a is: "a"
+ b is: "b"
+ c is: "c"
e, f = ([1,2], "foo")
- e is == [1,2]
- f is == "foo"
+ e is: [1,2]
+ f is: "foo"
}
it: "handles multiple assignment with splat-identifiers" when: {
x,y,z,*rest = [1,2,3,4,5,6,7]
- x is == 1
- y is == 2
- z is == 3
- rest is == [4,5,6,7]
+ x is: 1
+ y is: 2
+ z is: 3
+ rest is: [4,5,6,7]
a,b,*c,*d,e = [1,2,3,4,5,6,7,8]
- a is == 1
- b is == 2
- c is == [3,4,5,6,7,8]
- d is == [4,5,6,7,8]
- e is == 5
+ a is: 1
+ b is: 2
+ c is: [3,4,5,6,7,8]
+ d is: [4,5,6,7,8]
+ e is: 5
_,_,*z = "hello, world!" # ignore first 2 characters
- z is == "llo, world!"
+ z is: "llo, world!"
}
}
View
84 tests/block.fy
@@ -6,7 +6,7 @@ FancySpec describe: Block with: {
str = "String!"
a ++ empty ++ str
}
- block call is == "a String!"
+ block call is: "a String!"
}
it: "closes over a value and change it internally" when: {
@@ -15,13 +15,13 @@ FancySpec describe: Block with: {
x is be: |x| { x < 10 }
x = x + 1
}
- x is == 10
+ x is: 10
}
it: "returns the argument count" with: 'arity when: {
- { } arity . is == 0
- |x| { } arity . is == 1
- |x y z| { } arity . is == 3
+ { } arity . is: 0
+ |x| { } arity . is: 1
+ |x y z| { } arity . is: 3
}
it: "calls a block while another is true" with: 'while_true: when: {
@@ -37,7 +37,7 @@ FancySpec describe: Block with: {
{i == 10} while_false: {
i = i + 1
}
- i is == 10
+ i is: 10
}
# again for while_nil
@@ -46,27 +46,27 @@ FancySpec describe: Block with: {
{i == 10} while_nil: {
i = i + 1
}
- i is == 10
+ i is: 10
}
it: "calls a block while another one is true-ish" with: 'while_do: when: {
x = 0
{ x < 10 } while_do: |val| {
- val is == true
+ val is: true
x = x + 1
}
}
it: "calls another block while a block yields false" with: 'until_do: when: {
i = 0
- { i > 10 } until_do: { i <= 10 is == true; i = i + 1 }
- i is == 11
+ { i > 10 } until_do: { i <= 10 is: true; i = i + 1 }
+ i is: 11
}
it: "calls a block until another yields true" with: 'until: when: {
i = 0
- { i <= 10 is == true; i = i + 1 } until: { i > 10 }
- i is == 11
+ { i <= 10 is: true; i = i + 1 } until: { i > 10 }
+ i is: 11
}
it: "calls itself only when the argument is nil" with: 'unless: when: {
@@ -74,7 +74,7 @@ FancySpec describe: Block with: {
{ StdError new: "got_run!" . raise! } unless: nil
StdError new: "didnt_run!" . raise!
} catch StdError => e {
- e message is == "got_run!"
+ e message is: "got_run!"
}
}
@@ -83,34 +83,34 @@ FancySpec describe: Block with: {
{ StdError new: "got_run!" . raise! } if: true
StdError new: "didnt_run!" . raise!
} catch StdError => e {
- e message is == "got_run!"
+ e message is: "got_run!"
}
}
it: "also is able to take arguments seperated by comma" with: 'call: when: {
block = |x, y| { x + y }
- block call: [1,2] . is == 3
+ block call: [1,2] . is: 3
}
it: "evaluates the blocks in a short-circuiting manner" with: '&& when: {
- { false } && { false } is == false
- { true } && { false } is == false
- { false } && { true } is == false
- { true } && { true } is == true
+ { false } && { false } is: false
+ { true } && { false } is: false
+ { false } && { true } is: false
+ { true } && { true } is: true
- { false } || { false } is == false
- { false } || { true } is == true
- { true } || { false } is == true
- { true } || { true } is == true
+ { false } || { false } is: false
+ { false } || { true } is: true
+ { true } || { false } is: true
+ { true } || { true } is: true
# TODO: Add more useful tests here...
}
it: "calls the block as a partial block" when: {
- [1,2,3] map: @{upto: 3} . is == [[1,2,3], [2,3], [3]]
- [1,2,3] map: @{+ 3} . is == [4,5,6]
- [1,2,3] map: @{to_s} . is == ["1", "2", "3"]
- [1,2,3] map: @{to_s * 3} . is == ["111", "222", "333"]
+ [1,2,3] map: @{upto: 3} . is: [[1,2,3], [2,3], [3]]
+ [1,2,3] map: @{+ 3} . is: [4,5,6]
+ [1,2,3] map: @{to_s} . is: ["1", "2", "3"]
+ [1,2,3] map: @{to_s * 3} . is: ["111", "222", "333"]
}
it: "executes a match clause if the block returns a true-ish value" with: '=== when: {
@@ -120,24 +120,24 @@ FancySpec describe: Block with: {
case _ -> "nope, not even"
}
}
- do_match: 2 . is == "yup, it's even"
- do_match: 1 . is == "nope, not even"
+ do_match: 2 . is: "yup, it's even"
+ do_match: 1 . is: "nope, not even"
}
it: "returns the receiver of a block" with: 'receiver when: {
class Foo { def foo { { self } } } # return block
f = Foo new
- f foo receiver is == f
+ f foo receiver is: f
}
it: "sets the receiver correctly to a new value" with: 'receiver: when: {
b = { "hey" }
b receiver: 10
- b receiver is == 10
+ b receiver is: 10
b receiver: "Hello, World!"
- b receiver is == "Hello, World!"
+ b receiver is: "Hello, World!"
}
it: "calls a block with a different receiver" with: 'call_with_receiver: when: {
@@ -157,9 +157,9 @@ FancySpec describe: Block with: {
block = {
self inspect
}
- block call is == "in self#inspect"
- block call_with_receiver: (ClassA new) . is == "in ClassA#inspect"
- block call_with_receiver: (ClassB new) . is == "in ClassB#inspect"
+ block call is: "in self#inspect"
+ block call_with_receiver: (ClassA new) . is: "in ClassA#inspect"
+ block call_with_receiver: (ClassB new) . is: "in ClassB#inspect"
}
it: "calls a block with arguments and a different receiver" with: 'call:with_receiver: when: {
@@ -179,9 +179,9 @@ FancySpec describe: Block with: {
block = |arg| {
self inspect: arg
}
- block call: [42] . is == "in self#inspect: 42"
- block call: [42] with_receiver: (ClassC new) . is == "in ClassC#inspect: 42"
- block call: [42] with_receiver: (ClassD new) . is == "in ClassD#inspect: 42"
+ block call: [42] . is: "in self#inspect: 42"
+ block call: [42] with_receiver: (ClassC new) . is: "in ClassC#inspect: 42"
+ block call: [42] with_receiver: (ClassD new) . is: "in ClassD#inspect: 42"
}
it: "calls a block using the ruby-send syntax" with: 'call: when: {
@@ -189,11 +189,11 @@ FancySpec describe: Block with: {
x + y
}
- b call: [2,3] . is == 5
- b(2,3) . is == 5
+ b call: [2,3] . is: 5
+ b(2,3) . is: 5
b2 = |x| { x * 5 }
- b2("hello") is == ("hello" * 5)
- b2("foo") is == (b2 call: ["foo"])
+ b2("hello") is: ("hello" * 5)
+ b2("foo") is: (b2 call: ["foo"])
}
}
View
252 tests/class.fy
@@ -39,9 +39,9 @@ class ClassWithPrivate {
FancySpec describe: Class with: {
it: "does NOT find the method when not mixed-in" with: 'responds_to?: when: {
instance = ClassWithMixin new
- instance normal_method . is == 'normal_found
- instance responds_to?: 'normal_method . is == true
- instance responds_to?: 'mixin_method . is == false
+ instance normal_method . is: 'normal_found
+ instance responds_to?: 'normal_method . is: true
+ instance responds_to?: 'mixin_method . is: false
}
it: "finds the method when mixed-in" with: 'include: when: {
@@ -51,32 +51,32 @@ FancySpec describe: Class with: {
}
instance = ClassWithMixin new
- instance responds_to?: 'normal_method . is == true
- instance responds_to?: 'mixin_method . is == true
- instance normal_method . is == 'normal_found
- instance mixin_method . is == 'mixed_in_found
+ instance responds_to?: 'normal_method . is: true
+ instance responds_to?: 'mixin_method . is: true
+ instance normal_method . is: 'normal_found
+ instance mixin_method . is: 'mixed_in_found
}
it: "rebinds the old class name with ClassWithNoMixin and replace the old normal_method" when: {
instance = ClassWithMixin new
- instance normal_method is == 'normal_found
+ instance normal_method is: 'normal_found
# rebind the class to the other class
ClassWithMixin = ClassWithNoMixin
instance = ClassWithMixin new
- instance normal_method is == 'new_normal_found
+ instance normal_method is: 'new_normal_found
}
it: "has dynamically generated getter and setter methods" with: 'responds_to?: when: {
instance = ClassWithNoMixin new
- instance responds_to?: 'foo . is == true
- instance responds_to?: 'bar . is == true
- instance responds_to?: 'baz . is == true
- instance responds_to?: "hello:" . is == true
- instance responds_to?: "world:" . is == true
- instance responds_to?: 'oh . is == true
- instance responds_to?: ":oh" . is == true
- instance responds_to?: 'noes . is == true
- instance responds_to?: "noes:" . is == true
+ instance responds_to?: 'foo . is: true
+ instance responds_to?: 'bar . is: true
+ instance responds_to?: 'baz . is: true
+ instance responds_to?: "hello:" . is: true
+ instance responds_to?: "world:" . is: true
+ instance responds_to?: 'oh . is: true
+ instance responds_to?: ":oh" . is: true
+ instance responds_to?: 'noes . is: true
+ instance responds_to?: "noes:" . is: true
}
it: "defines getter methods for single slots" with: 'read_slot: when: {
@@ -86,10 +86,10 @@ FancySpec describe: Class with: {
}
g = Getters new
- g responds_to?: 'foo . is == true
- g responds_to?: 'foo: . is == false
- g responds_to?: 'bar . is == true
- g responds_to?: 'bar: . is == false
+ g responds_to?: 'foo . is: true
+ g responds_to?: 'foo: . is: false
+ g responds_to?: 'bar . is: true
+ g responds_to?: 'bar: . is: false
}
it: "defines setter methods for single slots" with: 'write_slot: when: {
@@ -99,10 +99,10 @@ FancySpec describe: Class with: {
}
s = Setters new
- s responds_to?: 'foo . is == false
- s responds_to?: 'foo: . is == true
- s responds_to?: 'bar . is == false
- s responds_to?: 'bar: . is == true
+ s responds_to?: 'foo . is: false
+ s responds_to?: 'foo: . is: true
+ s responds_to?: 'bar . is: false
+ s responds_to?: 'bar: . is: true
}
it: "defines getter & setter methods for single slots" with: 'read_write_slot: when: {
@@ -112,10 +112,10 @@ FancySpec describe: Class with: {
}
gs = GettersAndSetters new
- gs responds_to?: 'foo . is == true
- gs responds_to?: 'foo: . is == true
- gs responds_to?: 'bar . is == true
- gs responds_to?: 'bar: . is == true
+ gs responds_to?: 'foo . is: true
+ gs responds_to?: 'foo: . is: true
+ gs responds_to?: 'bar . is: true
+ gs responds_to?: 'bar: . is: true
}
it: "finds the instance variable correctly" when: {
@@ -130,8 +130,8 @@ FancySpec describe: Class with: {
str = "instance value"
instance = AClass new: str
- instance foo is == str
- AClass new foo is == nil
+ instance foo is: str
+ AClass new foo is: nil
}
it: "finds the class variable correctly" when: {
@@ -148,14 +148,14 @@ FancySpec describe: Class with: {
instance2 = AClass new
str = "class value"
instance1 foo: str
- instance1 foo is == str
- instance2 foo is == str
- instance2 foo is == (instance1 foo)
+ instance1 foo is: str
+ instance2 foo is: str
+ instance2 foo is: (instance1 foo)
str2 = "another value"
instance2 foo: str2
- instance2 foo is == str2
- instance1 foo is == str2
+ instance2 foo is: str2
+ instance1 foo is: str2
}
it: "has correct method overloading for method names with and without an argument" when: {
@@ -170,8 +170,8 @@ FancySpec describe: Class with: {
}
instance = AClass new
- instance foo is == "In AClass#foo: with bar = None!"
- instance foo: "Test!" . is == "In AClass#foo: with bar = Test!"
+ instance foo is: "In AClass#foo: with bar = None!"
+ instance foo: "Test!" . is: "In AClass#foo: with bar = Test!"
}
it: "calls a superclass method by using super" when: {
@@ -195,51 +195,51 @@ FancySpec describe: Class with: {
}
sub = SubClass new: 42
- sub name is == "SubClass"
- sub age is == 42
+ sub name is: "SubClass"
+ sub age is: 42
sub2 = SubClass new
- sub2 name is == "SubClass"
- sub2 age is == 0
+ sub2 name is: "SubClass"
+ sub2 age is: 0
}
it: "returns its superclass" when: {
- Fixnum superclass is == Integer
- Symbol superclass is == Object
- StdError superclass is == Exception
- Class superclass is == Module
- Object superclass is == nil
+ Fixnum superclass is: Integer
+ Symbol superclass is: Object
+ StdError superclass is: Exception
+ Class superclass is: Module
+ Object superclass is: nil
- IOError superclass is == StandardError
- NoMethodError superclass is == NameError
+ IOError superclass is: StandardError
+ NoMethodError superclass is: NameError
}
it: "creates a new Class dynamically" when: {
x = Class new
- x is_a?: Class . is == true
- x new is_a?: x . is == true
- x new is_a?: Object . is == true
- x new class is == x
+ x is_a?: Class . is: true
+ x new is_a?: x . is: true
+ x new is_a?: Object . is: true
+ x new class is: x
# Symbol as superclass
y = Class new: String
- y is_a?: Class . is == true
- y new is_a?: String . is == true
- y new is_a?: Object . is == true
+ y is_a?: Class . is: true
+ y new is_a?: String . is: true
+ y new is_a?: Object . is: true
}
it: "only is able to call the public method from outside the Class" when: {
x = ClassWithPrivate new
- x public_method is == "public!"
+ x public_method is: "public!"
try {
- x private_method is == nil # is fail
+ x private_method is: nil # is fail
} catch NoMethodError => e {
- e method_name is == 'private_method
+ e method_name is: 'private_method
}
try {
- x protected_method is == nil # is fail
+ x protected_method is: nil # is fail
} catch NoMethodError => e {
- e method_name is == 'protected_method
+ e method_name is: 'protected_method
}
}
@@ -249,10 +249,10 @@ FancySpec describe: Class with: {
class Sub : Super {
}
- Super subclass?: Object . is == true
- Sub subclass?: Object . is == true
- Sub subclass?: Super . is == true
- Super subclass?: Sub . is == nil
+ Super subclass?: Object . is: true
+ Sub subclass?: Object . is: true
+ Sub subclass?: Super . is: true
+ Super subclass?: Sub . is: nil
}
it: "dynamically creates a subclass of another class" with: 'is_a?: when: {
@@ -261,10 +261,10 @@ FancySpec describe: Class with: {
"hello, world!"
}
}
- subclass is_a?: Class . is == true
- subclass subclass?: String . is == true
- subclass new is_a?: subclass . is == true
- subclass new foo is == "hello, world!"
+ subclass is_a?: Class . is: true
+ subclass subclass?: String . is: true
+ subclass new is_a?: subclass . is: true
+ subclass new foo is: "hello, world!"
# now the same with Class##new:body:
subclass2 = Class superclass: String body: {
@@ -272,10 +272,10 @@ FancySpec describe: Class with: {
"hello, world, again!"
}
}
- subclass2 is_a?: Class . is == true
- subclass2 subclass?: String . is == true
- subclass2 new is_a?: subclass2 . is == true
- subclass2 new foo is == "hello, world, again!"
+ subclass2 is_a?: Class . is: true
+ subclass2 subclass?: String . is: true
+ subclass2 new is_a?: subclass2 . is: true
+ subclass2 new foo is: "hello, world, again!"
}
it: "undefines an instance method" with: 'undefine_method: when: {
@@ -285,12 +285,12 @@ FancySpec describe: Class with: {
}
}
f = Foo new
- f instance_method is == "instance method!"
+ f instance_method is: "instance method!"
Foo undefine_method: 'instance_method
try {
- f instance_method is == nil # is not get here
+ f instance_method is: nil # is not get here
} catch NoMethodError => e {
- e method_name is == 'instance_method
+ e method_name is: 'instance_method
}
}
@@ -300,21 +300,21 @@ FancySpec describe: Class with: {
"class method!"
}
}
- Foo class_method is == "class method!"
+ Foo class_method is: "class method!"
try {
Foo undefine_method: 'class_method
- true is == nil # is not happen
+ true is: nil # is not happen
} catch NameError {
- true is == true
+ true is: true
}
Foo undefine_class_method: 'class_method
try {
- Foo class_method is == nil # is not get here
+ Foo class_method is: nil # is not get here
} catch NoMethodError => e {
- e method_name is == 'class_method
+ e method_name is: 'class_method
}
}
@@ -328,11 +328,11 @@ FancySpec describe: Class with: {
}
}
}
- Outer is_a?: Class is == true
- Outer Inner is_a?: Class is == true
- Outer Inner InnerMost is_a?: Class is == true
+ Outer is_a?: Class . is: true
+ Outer Inner is_a?: Class . is: true
+ Outer Inner InnerMost is_a?: Class . is: true
obj = Outer Inner InnerMost new
- obj foobar is == "foobar!"
+ obj foobar is: "foobar!"
# change InnerMost#foobar
class Outer::Inner::InnerMost {
@@ -340,7 +340,7 @@ FancySpec describe: Class with: {
"oh no!"
}
}
- obj foobar is == "oh no!"
+ obj foobar is: "oh no!"
}
it: "does not override existing classes with the same name in a nested class" when: {
@@ -353,26 +353,26 @@ FancySpec describe: Class with: {
}
}
- NameSpace Array what_am_i is == "not the same as the standard Array class"
- NameSpace Array is_not == Array
+ NameSpace Array what_am_i is: "not the same as the standard Array class"
+ NameSpace Array is_not: Array
}
# it: "returns all nested classes of a class" with: 'nested_classes when: {
# class Outer {
# }
- # Outer nested_classes is == []
+ # Outer nested_classes is: []
# class Outer {
# class Inner1 {
# }
# }
- # Outer nested_classes is == [Outer::Inner1]
+ # Outer nested_classes is: [Outer::Inner1]
# class Outer {
# class Inner2 {
# }
# }
- # Outer nested_classes is == [Outer Inner1, Outer Inner2]
+ # Outer nested_classes is: [Outer Inner1, Outer Inner2]
# }
it: "finds other nested classes in the same parent class" when: {
@@ -390,9 +390,9 @@ FancySpec describe: Class with: {
}
}
- MyOuter Inner1 new method1 is == 'method_1
- MyOuter Inner2 new method1 is == 'method_1
- MyOuter Inner2 new method2 is == 'method_2
+ MyOuter Inner1 new method1 is: 'method_1
+ MyOuter Inner2 new method1 is: 'method_1
+ MyOuter Inner2 new method2 is: 'method_2
}
it: "finds itself in it's own methods, even if nested into another class" when: {
@@ -415,10 +415,10 @@ FancySpec describe: Class with: {
}
}
- MyOuter MyInner1 new method1 is == MyOuter MyInner1
- MyOuter MyInner2 new method2 is == [MyOuter MyInner1, MyOuter MyInner2]
- MyOuter MyInner1 class_method1 is == MyOuter MyInner1
- MyOuter MyInner2 class_method2 is == [MyOuter MyInner1, MyOuter MyInner2]
+ MyOuter MyInner1 new method1 is: MyOuter MyInner1
+ MyOuter MyInner2 new method2 is: [MyOuter MyInner1, MyOuter MyInner2]
+ MyOuter MyInner1 class_method1 is: MyOuter MyInner1
+ MyOuter MyInner2 class_method2 is: [MyOuter MyInner1, MyOuter MyInner2]
}
it: "has an alias method as defined" with: 'alias_method:for: when: {
@@ -431,22 +431,22 @@ FancySpec describe: Class with: {
}
obj = AClass new
- obj foo is == "in foo!"
- obj bar is == "in foo!"
+ obj foo is: "in foo!"
+ obj bar is: "in foo!"
}
it: "has an alias method for a ruby method defined" with: 'alias_method:for_ruby: when: {
try {
- [] equal?: [1,2] . is == true # is fail
+ [] equal?: [1,2] . is: true # is fail
} catch NoMethodError => e {
- e method_name is == 'equal?:
+ e method_name is: 'equal?:
}
class Array {
alias_method: 'equal?: for_ruby: 'equal?
}
- [] equal?: [1,2] . is == false
+ [] equal?: [1,2] . is: false
}
it: "has the correct list of ancestors" with: 'ancestors when: {
@@ -457,9 +457,9 @@ FancySpec describe: Class with: {
class C : B {
}
- A ancestors is == [A, Object, Kernel]
- B ancestors is == [B, A, Object, Kernel]
- C ancestors is == [C, B, A, Object, Kernel]
+ A ancestors is: [A, Object, Kernel]
+ B ancestors is: [B, A, Object, Kernel]
+ C ancestors is: [C, B, A, Object, Kernel]
}
it: "makes methods private" with: 'private: when: {
@@ -476,8 +476,8 @@ FancySpec describe: Class with: {
x = AClassWithPrivateMethods new
{ x a } raises: NoMethodError
{ x b } raises: NoMethodError
- AClassWithPrivateMethods instance_method: 'a . private? is == true
- AClassWithPrivateMethods instance_method: 'b . private? is == true
+ AClassWithPrivateMethods instance_method: 'a . private? is: true
+ AClassWithPrivateMethods instance_method: 'b . private? is: true
}
it: "makes methods protected" with: 'protected: when: {
@@ -494,10 +494,10 @@ FancySpec describe: Class with: {
x = AClassWithProtectedMethods new
{ x a } raises: NoMethodError
{ x b } raises: NoMethodError
- AClassWithProtectedMethods instance_method: 'a . private? is == false
- AClassWithProtectedMethods instance_method: 'b . private? is == false
- AClassWithProtectedMethods instance_method: 'a . protected? is == true
- AClassWithProtectedMethods instance_method: 'b . protected? is == true
+ AClassWithProtectedMethods instance_method: 'a . private? is: false
+ AClassWithProtectedMethods instance_method: 'b . private? is: false
+ AClassWithProtectedMethods instance_method: 'a . protected? is: true
+ AClassWithProtectedMethods instance_method: 'b . protected? is: true
}
it: "makes methods public" with: 'public: when: {
@@ -515,23 +515,23 @@ FancySpec describe: Class with: {
x = AClassWithPublicMethods new
{ x a } does_not raise: NoMethodError
{ x b } does_not raise: NoMethodError
- AClassWithPublicMethods instance_method: 'a . private? is == false
- AClassWithPublicMethods instance_method: 'b . private? is == false
- AClassWithPublicMethods instance_method: 'a . protected? is == false
- AClassWithPublicMethods instance_method: 'b . protected? is == false
- AClassWithPublicMethods instance_method: 'a . public? is == true
- AClassWithPublicMethods instance_method: 'b . public? is == true
+ AClassWithPublicMethods instance_method: 'a . private? is: false
+ AClassWithPublicMethods instance_method: 'b . private? is: false
+ AClassWithPublicMethods instance_method: 'a . protected? is: false
+ AClassWithPublicMethods instance_method: 'b . protected? is: false
+ AClassWithPublicMethods instance_method: 'a . public? is: true
+ AClassWithPublicMethods instance_method: 'b . public? is: true
}
it: "defines a class without a body" when: {
class Foo
- Foo is_a?: Class is == true
- Foo new is_a?: Foo is == true
+ Foo is_a?: Class . is: true
+ Foo new is_a?: Foo . is: true
class FooNew : Foo
- FooNew is_a?: Class is == true
- FooNew ancestors includes?: Foo is == true
- FooNew new is_a?: Foo is == true
+ FooNew is_a?: Class . is: true
+ FooNew ancestors includes?: Foo . is: true
+ FooNew new is_a?: Foo . is: true
}
it: "defines a class with empty methods" when: {
@@ -545,7 +545,7 @@ FancySpec describe: Class with: {
}
b = Bar new: "foo"
- b to_s is == "foobar"
- b empty_method is == nil
+ b to_s is: "foobar"
+ b empty_method is: nil
}
}
View
74 tests/control_flow.fy
@@ -1,92 +1,92 @@
FancySpec describe: "Control Flow" with: {
it: "does NOT call the block if not nil" with: 'if_nil: when: {
- 'foo if_nil: { 'is_nil } . is == nil
- "hello, world" if_nil: { 'is_nil } . is == nil
+ 'foo if_nil: { 'is_nil } . is: nil
+ "hello, world" if_nil: { 'is_nil } . is: nil
}
it: "works like if_true:" with: 'if:then: when: {
if: (4 < 5) then: {
- 4 < 5 is == true
+ 4 < 5 is: true
}
}
it: "works like if_true:else: " with: 'if:then:else: when: {
if: (4 < 5) then: {
- 4 < 5 is == true
+ 4 < 5 is: true
} else: {
- 4 < 5 is == nil
+ 4 < 5 is: nil
}
}
it: "works like while_true:" with: 'while:do: when: {
x = 0
while: { x < 10 } do: {
- x < 10 is == true
+ x < 10 is: true
x = x + 1
}
- x == 10 is == true
+ x == 10 is: true
}
it: "works like while_false: " with: 'until:do: when: {
x = 0
until: { x == 10 } do: {
- x < 10 is == true
+ x < 10 is: true
x = x + 1
}
- x == 10 is == true
+ x == 10 is: true
}
it: "calls a block while another one is true, but call it at least once" with: 'do:while: when: {
x = 0
arr = []
do: {
- x < 10 is == true
+ x < 10 is: true
arr << x
x = x + 1
} while: { x < 10 }
- arr is == [0,1,2,3,4,5,6,7,8,9]
+ arr is: [0,1,2,3,4,5,6,7,8,9]
times_called = 0
do: {
times_called = times_called + 1
} while: { false }
- times_called is == 1
+ times_called is: 1
}
it: "calls a block until another one is true, but call it at least once" with: 'do:until: when: {
x = 0
do: {
- x < 10 is == true
+ x < 10 is: true
x = x + 1
} until: { x == 10 }
- x is == 10
+ x is: 10
times_called = 0
do: {
times_called = times_called + 1
} until: { true }
- times_called is == 1
+ times_called is: 1
}
it: "works like if_false:: " with: 'unless:do: when: {
unless: (4 > 5) do: {
- 5 > 4 is == true
+ 5 > 4 is: true
}
}
it: "only calls the block if it's a true-ish value" with: 'if_true: when: {
1 if_true: |num| {
num * 10
- } . is == 10
+ } . is: 10
nil if_true: {
"nope"
- } . is == nil
+ } . is: nil
false if_true: {
"nope again"
- } . is == nil
+ } . is: nil
}
it: "calls the then_block if it's a true-ish value and call the else_block otherwise" with: 'if_true:else: when: {
@@ -94,19 +94,19 @@ FancySpec describe: "Control Flow" with: {
num * 10
} else: {
nil
- } . is == 10
+ } . is: 10
nil if_true: {
"nope"
} else: {
"yup"
- } . is == "yup"
+ } . is: "yup"
false if_true: {
"nope again"
} else: {
"yup again"
- } . is == "yup again"
+ } . is: "yup again"
}
it: "is possible to override the if_true:else: method and work accordingly in conditionals" when: {
@@ -121,7 +121,7 @@ FancySpec describe: "Control Flow" with: {
'fail
} else: {
'success
- } . is == 'success
+ } . is: 'success
# let's get rid of this custom if_true:else: method
AClassThatIsLikeFalse undefine_method: 'if_true:else:
@@ -130,7 +130,7 @@ FancySpec describe: "Control Flow" with: {
'now_this_is_success
} else: {
'fail
- } . is == 'now_this_is_success
+ } . is: 'now_this_is_success
}
it: "breaks from an iteration" with: 'break when: {
@@ -139,7 +139,7 @@ FancySpec describe: "Control Flow" with: {
x = x + 1
{ break } if: (x == 5)
}
- x == 5 is == true
+ x == 5 is: true
}
it: "breaks from an iteration with return value" with: 'break: when: {
@@ -149,8 +149,8 @@ FancySpec describe: "Control Flow" with: {
{ break: 42 } if: (x == 5)
}
- x is == 5
- y is == 42
+ x is: 5
+ y is: 42
}
it: "skips an iteration over a Range" with: 'next when: {
@@ -159,7 +159,7 @@ FancySpec describe: "Control Flow" with: {
{ next } if: (i == 5)
total = total + i
}
- total is == 50
+ total is: 50
}
it: "skips an iteration over an Array" with: 'next when: {
@@ -168,7 +168,7 @@ FancySpec describe: "Control Flow" with: {
{ next } if: (i == 5)
total = total + i
}
- total is == 50
+ total is: 50
}
it: "skips an iteration over an Hash" with: 'next when: {
@@ -177,7 +177,7 @@ FancySpec describe: "Control Flow" with: {
{ next } if: (k == 'd)
total = total + v
}
- total is == 17
+ total is: 17
}
it: "stops any loop type at the correct spot" with: 'break when: {
@@ -186,21 +186,21 @@ FancySpec describe: "Control Flow" with: {
{ break } if: (i == 3)
i = i + 1
}
- i is == 3
+ i is: 3
i = 0
while: { i < 5 } do: {
{ break } if: (i == 3)
i = i + 1
}
- i is == 3
+ i is: 3
i = 0
0 upto: 5 do: |n| {
i = n
{ break } if: (n == 3)
}
- i is == 3
+ i is: 3
}
it: "stops any loop type at the correct spot" with: 'break: when: {
@@ -208,27 +208,27 @@ FancySpec describe: "Control Flow" with: {
loop: {
{ break: i } if: (i == 2)
i = i + 1
- } . is == 2
+ } . is: 2
i = 0
while: { i < 5 } do: {
{ break: i } if: (i == 2)
i = i + 1
- } . is == 2
+ } . is: 2
i = 0
0 upto: 5 do: |n| {
i = n
{ break: n } if: (n == 2)
}
- i is == 2
+ i is: 2
}
it: "allows empty try blocks" when: {
x = "foo"
try {
} finally {
- x is == "foo"
+ x is: "foo"
}
}
}
View
8 tests/documentation.fy
@@ -2,7 +2,7 @@ FancySpec describe: "Documentations" with: {
it: "displays the documentation for a method" when: {
documentation = "Array#each: iterates over its elements, calling a given block with each element."
Array new method: "each:" . documentation: documentation
- Array new method: "each:" . documentation . docs first is == documentation
+ Array new method: "each:" . documentation . docs first is: documentation
}
it: "defines a documenation string for a class and method" when: {
@@ -13,9 +13,9 @@ FancySpec describe: "Documentations" with: {
nil
}
}
- ClassWithDoc documentation to_s is_not == ""
- ClassWithDoc documentation to_s is == "This class has a documentation! Yay!"
- ClassWithDoc new method: 'foo . documentation docs is == ["bar!"]
+ ClassWithDoc documentation to_s is_not: ""
+ ClassWithDoc documentation to_s is: "This class has a documentation! Yay!"
+ ClassWithDoc new method: 'foo . documentation docs is: ["bar!"]
}
it: "has a documentation string for a method" when: {
View
52 tests/enumerator.fy
@@ -1,24 +1,24 @@
FancySpec describe: FancyEnumerator with: {
it: "iterates with 'next" with: 'new: when: {
enum = FancyEnumerator new: (42..50)
- enum next is == 42
- enum next is == 43
+ enum next is: 42
+ enum next is: 43
}
it: "peeks to find next element" with: 'peek when: {
enum = FancyEnumerator new: (42..50)
- enum peek is == 42
- enum peek is == 42
- enum next is == 42
+ enum peek is: 42
+ enum peek is: 42
+ enum next is: 42
- enum peek is == 43
- enum peek is == 43
- enum next is == 43
+ enum peek is: 43
+ enum peek is: 43
+ enum next is: 43
}
it: "turns an object with 'each: into an FancyEnumerator" with: 'to_enum when: {
enum = (42..45) to_enum
- enum next is == 42
+ enum next is: 42
}
it: "turns an object with given method into an FancyEnumerator" with: 'to_enum: when: {
@@ -27,16 +27,16 @@ FancySpec describe: FancyEnumerator with: {
1 upto: 10 do: block
}
enum = o to_enum: 'iter:
- enum next is == 1
+ enum next is: 1
}
it: "rewinds to the beginning of the iteration" with: 'rewind when: {
enum = (42..45) to_enum
check = {
- enum peek is == 42
- enum next is == 42
- enum peek is == 43
- enum next is == 43
+ enum peek is: 42
+ enum next is: 42
+ enum peek is: 43
+ enum next is: 43
}
check call
@@ -49,12 +49,12 @@ FancySpec describe: FancyEnumerator with: {
def o each: block { block call: [1] }
e = o to_enum
- e next is == 1
+ e next is: 1
try {
e next
- "We is not reach this line" is == true
+ "We is not reach this line" is: true
} catch (Fancy StopIteration) => ex {
- ex result is == nil
+ ex result is: nil
}
}
@@ -66,37 +66,37 @@ FancySpec describe: FancyEnumerator with: {
}
e = o to_enum
- e next is == 1
+ e next is: 1
try {
e next
- "We is not reach this line" is == true
+ "We is not reach this line" is: true
} catch (Fancy StopIteration) => ex {
- ex result is == 42
+ ex result is: 42
}
}
it: "iterates with an object" with: 'with:each: when: {
enum = (42..45) to_enum
result = enum with: [] each: |val, obj| { obj << val }
- result is == [42, 43, 44, 45]
+ result is: [42, 43, 44, 45]
}
it: "chunks up into enums" with: 'chunk: when: {
enum = (1..42) to_enum
chunked = enum chunk: |n| { n % 3 == 0 }
- chunked next is == [false, [1,2]]
- chunked next is == [true, [3]]
+ chunked next is: [false, [1,2]]
+ chunked next is: [true, [3]]
}
it: "converts to an Array" with: 'to_a when: {
enum = (1..10) to_enum
- enum to_a is == [1,2,3,4,5,6,7,8,9,10]
+ enum to_a is: [1,2,3,4,5,6,7,8,9,10]
}
it: "has ended (no more values left)" with: 'ended? when: {
enum = (1..9) to_enum
- 10 times: { enum ended? is == false; enum next } # move forward
- enum ended? is == true
+ 10 times: { enum ended? is: false; enum next } # move forward
+ enum ended? is: true
}
}
View
44 tests/exception.fy
@@ -12,9 +12,9 @@ FancySpec describe: StdError with: {
it: "raises an exception and catch it correctly" with: 'raise! when: {
try {
StdError new: "FAIL!" . raise!
- nil is == true # this is not occur
+ nil is: true # this is not occur
} catch StdError => ex {
- ex message is == "FAIL!"
+ ex message is: "FAIL!"
}
}
@@ -22,23 +22,23 @@ FancySpec describe: StdError with: {
{
StdError new: "FAIL!" . raise!
} raises: StdError with: |e| {
- e message is == "FAIL!"
+ e message is: "FAIL!"
}
{
"FAIL, AGAIN!" raise!
} raises: StdError with: |e| {
- e message is == "FAIL, AGAIN!"
+ e message is: "FAIL, AGAIN!"
}
}
it: "raises an exception inside a method and catch it correctly" when: {
f = Foo new
- f bar: "Don't raise here" . is == 'no_error
+ f bar: "Don't raise here" . is: 'no_error
try {
- f bar: 'error . is == 'no_error
+ f bar: 'error . is: 'no_error
} catch StdError => e {
- e message is == "Some Error"
+ e message is: "Some Error"
}
}
@@ -46,10 +46,10 @@ FancySpec describe: StdError with: {
# s = 'symbol
# try {
# s this_method_doesnt_exist!
- # nil is == true # is not execute
+ # nil is: true # is not execute
# } catch NoMethodError => err {
- # err for_class is == Symbol
- # err method_name is == "this_method_doesnt_exist!"
+ # err for_class is: Symbol
+ # err method_name is: "this_method_doesnt_exist!"
# }
# }
@@ -58,7 +58,7 @@ FancySpec describe: StdError with: {
try {
var wont_work!
} catch NoMethodError => err {
- var is == 1234
+ var is: 1234
}
}
@@ -66,16 +66,16 @@ FancySpec describe: StdError with: {
set_in_finally = false
try {
x = 10 / 0 # ouch!
- "This is fail!" is == true # is not get here!
+ "This is fail!" is: true # is not get here!
} catch ZeroDivisionError => err {
- err message is == "divided by 0"
+ err message is: "divided by 0"
} finally {
# this part gets always run :)
- "It works!" is == "It works!"
- set_in_finally is == false
+ "It works!" is: "It works!"
+ set_in_finally is: false
set_in_finally = true
}
- set_in_finally is == true
+ set_in_finally is: true
}
it: "raises a StdError when raising a String" with: 'raise! when: {
@@ -83,7 +83,7 @@ FancySpec describe: StdError with: {
{
msg raise!
} raises: StdError with: |e| {
- e message is == msg
+ e message is: msg
}
}
@@ -96,9 +96,9 @@ FancySpec describe: StdError with: {
try {
MyError new raise!
- nil is == true # will fail
+ nil is: true # will fail
} catch MyError => e {
- e message is == "MyError message"
+ e message is: "MyError message"
}
}
@@ -108,8 +108,8 @@ FancySpec describe: StdError with: {
try {
x = 10 / y
} catch ZeroDivisionError => e {
- y is == 0
- x is == 0
+ y is: 0
+ x is: 0
y = 2
retry
}
@@ -126,7 +126,7 @@ FancySpec describe: StdError with: {
msg raise!
}
} catch StdError => e {
- e message is == msg
+ e message is: msg
}
}
}
View
36 tests/file.fy
@@ -1,15 +1,15 @@
FancySpec describe: File with: {
it: "returns an array with the openmodes symbols" with: 'open:modes: when: {
file = File open: "README.md" modes: ['read]
- file modes is == ['read]
+ file modes is: ['read]
file close
}
it: "is open after opening it and closed after closing" with: 'close when: {
file = File open: "README.md" modes: ['read]
- file open? is == true
+ file open? is: true
file close
- file open? is == false
+ file open? is: false
}
it: "is closed when not correctly opened" with: 'open? when: {
@@ -23,20 +23,20 @@ FancySpec describe: File with: {
file writeln: "line number two"
file close
- File exists?: filename . is == true
+ File exists?: filename . is: true
file = File open: filename modes: ['read]
lines = []
2 times: {
lines << (file readln)
}
- lines[0] is == "hello, world!\n"
- lines[1] is == "line number two\n"
- lines is == ["hello, world!\n", "line number two\n"]
+ lines[0] is: "hello, world!\n"
+ lines[1] is: "line number two\n"
+ lines is: ["hello, world!\n", "line number two\n"]
# delete file
File delete: filename
- File exists?: filename . is == false
+ File exists?: filename . is: false
}
it: "raises an IOError exception when trying to open an invalid file" when: {
@@ -53,25 +53,25 @@ FancySpec describe: File with: {
f writeln: "testing!"
}
- Directory exists?: dirname . is == true
- File exists?: dirname . is == true
- File directory?: dirname . is == true
+ Directory exists?: dirname . is: true
+ File exists?: dirname . is: true
+ File directory?: dirname . is: true
File rename: filename to: (filename ++ "-new")
- File exists?: filename . is == false
- File exists?: (filename ++ "-new") . is == true
+ File exists?: filename . is: false
+ File exists?: (filename ++ "-new") . is: true
File delete: (filename ++ "-new")
Directory delete: "tmp/"
}
it: "is a directory" with: 'directory?: when: {
- File directory?: "lib/" . is == true
- File directory?: "lib/rbx" . is == true
+ File directory?: "lib/" . is: true
+ File directory?: "lib/rbx" . is: true
}
it: "is NOT a directory" with: 'directory?: when: {
- File directory?: "src/Makefile" . is == false
- File directory?: "README" . is == false
- File directory?: "src/bootstrap/Makefile" . is == false
+ File directory?: "src/Makefile" . is: false