From 656e9dfd1945a88167c0913236a851d35c48c2af Mon Sep 17 00:00:00 2001 From: Christopher Bertels Date: Wed, 29 Jun 2011 17:34:14 +0200 Subject: [PATCH] Use is: and is_not: in tests since it's less noisy and reads nicer. --- tests/argv.fy | 4 +- tests/array.fy | 386 +++++++++++++++++++------------------- tests/assignment.fy | 52 ++--- tests/block.fy | 84 ++++----- tests/class.fy | 252 ++++++++++++------------- tests/control_flow.fy | 74 ++++---- tests/documentation.fy | 8 +- tests/enumerator.fy | 52 ++--- tests/exception.fy | 44 ++--- tests/file.fy | 36 ++-- tests/fixnum.fy | 112 +++++------ tests/future.fy | 6 +- tests/hash.fy | 56 +++--- tests/method.fy | 58 +++--- tests/nil_class.fy | 50 ++--- tests/object.fy | 110 +++++------ tests/pattern_matching.fy | 74 ++++---- tests/range.fy | 8 +- tests/set.fy | 60 +++--- tests/stack.fy | 8 +- tests/string.fy | 98 +++++----- tests/stringio.fy | 5 +- tests/struct.fy | 18 +- tests/symbol.fy | 8 +- tests/true_class.fy | 40 ++-- tests/tuple.fy | 24 +-- 26 files changed, 869 insertions(+), 858 deletions(-) diff --git a/tests/argv.fy b/tests/argv.fy index 47cc2acf..fc01776f 100644 --- a/tests/argv.fy +++ b/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$/ } } diff --git a/tests/array.fy b/tests/array.fy index 4db0b55a..9f9c1a6f 100644 --- a/tests/array.fy +++ b/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]] } } diff --git a/tests/assignment.fy b/tests/assignment.fy index 295c6522..faa7bd49 100644 --- a/tests/assignment.fy +++ b/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!" } } \ No newline at end of file diff --git a/tests/block.fy b/tests/block.fy index e30fb897..d0fc2ab8 100644 --- a/tests/block.fy +++ b/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"]) } } diff --git a/tests/class.fy b/tests/class.fy index 54fdf28d..148c6034 100644 --- a/tests/class.fy +++ b/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 } } diff --git a/tests/control_flow.fy b/tests/control_flow.fy index 9648464d..4622f070 100644 --- a/tests/control_flow.fy +++ b/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" } } } \ No newline at end of file diff --git a/tests/documentation.fy b/tests/documentation.fy index 2ed09a25..f8ce83dc 100644 --- a/tests/documentation.fy +++ b/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: { diff --git a/tests/enumerator.fy b/tests/enumerator.fy index 39894077..cf928287 100644 --- a/tests/enumerator.fy +++ b/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 } } diff --git a/tests/exception.fy b/tests/exception.fy index 7eb84d90..3f6732b5 100644 --- a/tests/exception.fy +++ b/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 } } } diff --git a/tests/file.fy b/tests/file.fy index 75ca6d79..da6852aa 100644 --- a/tests/file.fy +++ b/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 + File directory?: "README" . is: false + File directory?: "src/bootstrap/Makefile" . is: false } } diff --git a/tests/fixnum.fy b/tests/fixnum.fy index fcc54d19..56777581 100644 --- a/tests/fixnum.fy +++ b/tests/fixnum.fy @@ -2,25 +2,25 @@ FancySpec describe: Fixnum with: { it: "adds two numbers correctly" with: '+ when: { n1 = 20 n2 = 22 - n1 + n2 is == 42 + n1 + n2 is: 42 } it: "subtracts two numbers correctly" with: '- when: { n1 = 20 n2 = 22 - n1 - n2 is == -2 + n1 - n2 is: -2 } it: "multiplies two numbers correctly" with: '* when: { n1 = 20 n2 = 22 - n1 * n2 is == 440 + n1 * n2 is: 440 } it: "divides two numbers correctly" with: '/ when: { n1 = 20 n2 = 10 - n1 / n2 is == 2 + n1 / n2 is: 2 } it: "raises an exception when dividing by zero" when: { @@ -28,119 +28,119 @@ FancySpec describe: Fixnum with: { } it: "calculates the correct modulo value" with: 'modulo: when: { - 9 % 4 is == 1 - 10 modulo: 2 . is == 0 + 9 % 4 is: 1 + 10 modulo: 2 . is: 0 } it: "does proper integer division" with: 'div: when: { - 50 div: 10 . is == 5 - 55 div: 10 . is == 5 - 5 div: 10 . is == 0 - ((55 div: 10) * 10) + (55 modulo: 10) is == 55 + 50 div: 10 . is: 5 + 55 div: 10 . is: 5 + 5 div: 10 . is: 0 + ((55 div: 10) * 10) + (55 modulo: 10) is: 55 } it: "is the negation" with: 'negate when: { - 42 negate is == -42 + 42 negate is: -42 } it: "is odd" with: 'odd? when: { - 1 odd? is == true - 1 even? is == false + 1 odd? is: true + 1 even? is: false } it: "is even" with: 'even? when: { - 2 odd? is == false - 2 even? is == true + 2 odd? is: false + 2 even? is: true } it: "returns an array from 0 upto 10" with: 'upto: when: { - 0 upto: 10 . is == [0,1,2,3,4,5,6,7,8,9,10] + 0 upto: 10 . is: [0,1,2,3,4,5,6,7,8,9,10] } it: "iterates from 1 upto 10" with: 'upto:do: when: { sum = 0 1 upto: 10 do: |n| { sum = sum + n } - sum is == 55 + sum is: 55 } it: "returns an array from 10 downto 0" with: 'downto: when: { - 10 downto: 0 . is == [10,9,8,7,6,5,4,3,2,1,0] + 10 downto: 0 . is: [10,9,8,7,6,5,4,3,2,1,0] } it: "iterates from 10 downto 1" with: 'downto:do: when: { sum = 0 10 downto: 1 do: |n| { sum = sum + n } - sum is == 55 + sum is: 55 } it: "calculates the given power of itself" with: '** when: { - 2 ** 3 is == 8 - 2 ** 0 is == 1 - 2 ** 1 is == 2 + 2 ** 3 is: 8 + 2 ** 0 is: 1 + 2 ** 1 is: 2 0 upto: 10 do: |i| { - i ** 0 is == 1 - i ** 1 is == i - i ** 2 is == (i squared) + i ** 0 is: 1 + i ** 1 is: i + i ** 2 is: (i squared) } } it: "is the square of self" with: 'squared when: { - 5 squared is == 25 - 10 squared is == 100 + 5 squared is: 25 + 10 squared is: 100 20 upto: 50 do: |i| { - i squared is == (i * i) + i squared is: (i * i) } } it: "is the double value of self" with: 'doubled when: { - 5 doubled is == 10 - 10 doubled is == 20 + 5 doubled is: 10 + 10 doubled is: 20 20 upto: 50 do: |i| { - i doubled is == (i + i) + i doubled is: (i + i) } } it: "is the same when using underscores within the literal" when: { - 50000 is == 50_000 - 100_000 is == 100000 - 100_000 is == 100_000 - 100_000 is == 100000.0 - 100_000.0 is == 100000 - 100_999.999 is == 100999.999 + 50000 is: 50_000 + 100_000 is: 100000 + 100_000 is: 100_000 + 100_000 is: 100000.0 + 100_000.0 is: 100000 + 100_999.999 is: 100999.999 } it: "evaluates octal literals correctly" when: { - 0o00 is == 0 - 0o01 is == 1 - 0o07 is == 7 - 0o10 is == 8 - 0o70 is == 56 + 0o00 is: 0 + 0o01 is: 1 + 0o07 is: 7 + 0o10 is: 8 + 0o70 is: 56 } it: "evaluates binary literals correctly" when: { - 0b00 is == 0 - 0b01 is == 1 - 0b10 is == 2 - 0b11 is == 3 - 0b100 is == 4 + 0b00 is: 0 + 0b01 is: 1 + 0b10 is: 2 + 0b11 is: 3 + 0b100 is: 4 } it: "evaluates hexadecimal literals correctly" when: { - 0x00 is == 0 - 0x01 is == 1 - 0x0A is == 10 - 0xA0 is == 160 - 0xFF is == 255 + 0x00 is: 0 + 0x01 is: 1 + 0x0A is: 10 + 0xA0 is: 160 + 0xFF is: 255 } it: "calls a block a given amount of times" with: 'times: when: { times_called = 0 10 times: { times_called = times_called + 1 } - times_called is == 10 + times_called is: 10 sum = 0 10 times: |i| { sum = sum + i } - sum is == ((0..9) sum) + sum is: ((0..9) sum) } it: "calls a block a given amount of times with an offset" with: 'times:offset: when: { @@ -150,7 +150,7 @@ FancySpec describe: Fixnum with: { times_called = times_called + 1 sum = sum + i } offset: 10 - times_called is == 10 - sum is == ((10..19) sum) + times_called is: 10 + sum is: ((10..19) sum) } } diff --git a/tests/future.fy b/tests/future.fy index 71533805..648c4a68 100644 --- a/tests/future.fy +++ b/tests/future.fy @@ -5,8 +5,8 @@ FancySpec describe: FutureSend with: { } f = self @ some_computation: 2 && @{select: 'even?} && @{size} - f is_a?: FutureSend . is == true - f value is_a?: Fixnum . is == true + f is_a?: FutureSend . is: true + f value is_a?: Fixnum . is: true } } @@ -18,7 +18,7 @@ FancySpec describe: FutureCollection with: { fc = FutureCollection new: futures fc each: |val| { - val is_a?: Integer . is == true + val is_a?: Integer . is: true } fc await_all diff --git a/tests/hash.fy b/tests/hash.fy index cea96369..4b4f6e9b 100644 --- a/tests/hash.fy +++ b/tests/hash.fy @@ -1,20 +1,20 @@ FancySpec describe: Hash with: { it: "is empty on initialization" with: 'empty? when: { hash = <[]> - hash size is == 0 - hash empty? is == true + hash size is: 0 + hash empty? is: true } it: "is empty on initialization via Hash#new" with: 'size when: { hash = Hash new - hash size is == 0 - hash empty? is == true + hash size is: 0 + hash empty? is: true } it: "contains one entry" when: { hash = <['foo => "bar"]> - hash size is == 1 - hash empty? is == false + hash size is: 1 + hash empty? is: false } it: "contains 10 square values after 10 insertions" with: 'at: when: { @@ -24,15 +24,15 @@ FancySpec describe: Hash with: { } 10 times: |i| { - hash at: i . is == (i * i) + hash at: i . is: (i * i) } } it: "overrides the value for a given key" with: 'at: when: { hash = <['foo => "bar"]> - hash at: 'foo . is == "bar" + hash at: 'foo . is: "bar" hash at: 'foo put: 'foobarbaz - hash at: 'foo . is == 'foobarbaz + hash at: 'foo . is: 'foobarbaz } it: "returns all keys" with: 'keys when: { @@ -47,21 +47,21 @@ FancySpec describe: Hash with: { it: "returns value by the []-operator" with: '[] when: { hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]> - hash['foo] is == "bar" - hash['bar] is == "baz" - hash['foobar] is == 112.21 + hash['foo] is: "bar" + hash['bar] is: "baz" + hash['foobar] is: 112.21 } it: "returns nil if the key isn't defined" with: '[] when: { - <['foo => "bar"]> ['bar] . is == nil - <[]> ['foobar] . is == nil - <['foo => "bar"]> [nil] . is == nil + <['foo => "bar"]> ['bar] . is: nil + <[]> ['foobar] . is: nil + <['foo => "bar"]> [nil] . is: nil } it: "calls the Block for each key and value" with: 'each: when: { hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]> hash each: |key val| { - val is == (hash[key]) + val is: (hash[key]) } } @@ -69,7 +69,7 @@ FancySpec describe: Hash with: { hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]> count = 0 hash each_key: |key| { - key is == (hash keys[count]) + key is: (hash keys[count]) count = count + 1 } } @@ -78,7 +78,7 @@ FancySpec describe: Hash with: { hash = <['foo => "bar", 'bar => "baz", 'foobar => 112.21]> count = 0 hash each_value: |val| { - val is == (hash values[count]) + val is: (hash values[count]) count = count + 1 } } @@ -89,10 +89,10 @@ FancySpec describe: Hash with: { hash map: |pair| { pair[0] } . is =? ['hello, 'fancy] # order does not matter hash select: |pair| { pair[1] to_s includes?: "c" } . - is == [['fancy, "is cool"]] + is: [['fancy, "is cool"]] hash reject: |pair| { pair[0] to_s includes?: "l" } . - map: 'second . is == ["is cool"] + map: 'second . is: ["is cool"] } it: "returns an Array of the key-value pairs" with: 'to_a when: { @@ -102,17 +102,17 @@ FancySpec describe: Hash with: { it: "returns multiple values if given an array of keys" with: '[] when: { hash = <['foo => 1, 'bar => "foobar", 'baz => 42, "hello world" => "hello!"]> a, b, c = hash values_at: ('foo, 'bar, "hello world") - a is == 1 - b is == "foobar" - c is == "hello!" + a is: 1 + b is: "foobar" + c is: "hello!" } it: "includes a key" with: 'includes?: when: { h = <['foo => "bar", 'bar => "baz"]> - h includes?: 'foo is == true - h includes?: 'bar is == true - h includes?: "foo" is == false - h includes?: "bar" is == false - h includes?: nil is == false + h includes?: 'foo . is: true + h includes?: 'bar . is: true + h includes?: "foo" . is: false + h includes?: "bar" . is: false + h includes?: nil . is: false } } diff --git a/tests/method.fy b/tests/method.fy index 2b9794cc..6e80f57e 100644 --- a/tests/method.fy +++ b/tests/method.fy @@ -1,6 +1,6 @@ FancySpec describe: Method with: { it: "returns a Method object" when: { - [1,2,3] method: "each:" . class is == Method + [1,2,3] method: "each:" . class is: Method } # it: "returns the (correct) sender object of the MessageSend" when: { @@ -11,7 +11,7 @@ FancySpec describe: Method with: { # } # x = SenderTest new - # x give_me_the_sender! is == self + # x give_me_the_sender! is: self # } it: "returns the amount of arguments a Method takes" with: 'arity when: { @@ -26,10 +26,10 @@ FancySpec describe: Method with: { } } - Foo instance_method: 'no_args . arity is == 0 - Foo instance_method: "one_arg:" . arity is == 1 - Foo instance_method: "two:args:" . arity is == 2 - Foo instance_method: "three:args:ok:" . arity is == 3 + Foo instance_method: 'no_args . arity is: 0 + Foo instance_method: "one_arg:" . arity is: 1 + Foo instance_method: "two:args:" . arity is: 2 + Foo instance_method: "three:args:ok:" . arity is: 3 } it: "returns the return value" when: { @@ -38,7 +38,7 @@ FancySpec describe: Method with: { bar # will never get executed } - foo: "yay" . is == "returning!" + foo: "yay" . is: "returning!" # another example @@ -49,8 +49,8 @@ FancySpec describe: Method with: { 0 } - f: 10 . is == 0 - f: 9 . is == 100 + f: 10 . is: 0 + f: 9 . is: 100 # and another one @@ -63,7 +63,7 @@ FancySpec describe: Method with: { return 0 } - foo is == 8 + foo is: 8 } it: "returns only from block-scope not from method-scope" when: { @@ -75,14 +75,14 @@ FancySpec describe: Method with: { } 0 } - foo is == 8 + foo is: 8 } it: "returns locally (from block-scope not from method-scope" when: { def self foo { [1,2,3] select: |x| { return_local x != 3 } } - foo is == [1,2] + foo is: [1,2] } class Foo { @@ -97,21 +97,21 @@ FancySpec describe: Method with: { } it: "is public" with: 'public? when: { - Foo instance_method: 'bar . public? is == true - Foo instance_method: 'private_bar . public? is == false - Foo instance_method: 'protected_bar . public? is == false + Foo instance_method: 'bar . public? is: true + Foo instance_method: 'private_bar . public? is: false + Foo instance_method: 'protected_bar . public? is: false } it: "is private" with: 'private? when: { - Foo instance_method: 'bar . private? is == false - Foo instance_method: 'private_bar . private? is == true - Foo instance_method: 'protected_bar . private? is == false + Foo instance_method: 'bar . private? is: false + Foo instance_method: 'private_bar . private? is: true + Foo instance_method: 'protected_bar . private? is: false } it: "is protected" with: 'protected? when: { - Foo instance_method: 'bar . protected? is == false - Foo instance_method: 'private_bar . protected? is == false - Foo instance_method: 'protected_bar . protected? is == true + Foo instance_method: 'bar . protected? is: false + Foo instance_method: 'private_bar . protected? is: false + Foo instance_method: 'protected_bar . protected? is: true } it: "sets the default values for optional argument, when not passed in" when: { @@ -119,9 +119,9 @@ FancySpec describe: Method with: { arg1 ++ arg2 ++ arg3 } - foo: "hello" bar: "world" baz: "!" . is == "helloworld!" - foo: "hello" bar: "world" . is == "helloworld" - foo: "hello" . is == "hellofoo" + foo: "hello" bar: "world" baz: "!" . is: "helloworld!" + foo: "hello" bar: "world" . is: "helloworld" + foo: "hello" . is: "hellofoo" } it: "has default values for all arguments, if none given" when: { @@ -129,16 +129,16 @@ FancySpec describe: Method with: { [arg1, arg2, arg3] } - a: "hello" b: "world" c: "!" . is == ["hello", "world", "!"] - a: "hello" b: "world" . is == ["hello", "world", "baz"] - a: "hello" . is == ["hello", "bar", "baz"] - a is == ["foo", "bar", "baz"] + a: "hello" b: "world" c: "!" . is: ["hello", "world", "!"] + a: "hello" b: "world" . is: ["hello", "world", "baz"] + a: "hello" . is: ["hello", "bar", "baz"] + a is: ["foo", "bar", "baz"] } it: "returns multiple values (as a Tuple)" when: { def multiple_return_values: x { (x, x + x, x + x + x) } - val = multiple_return_values: 3 . is == (3, 6, 9) + val = multiple_return_values: 3 . is: (3, 6, 9) } } diff --git a/tests/nil_class.fy b/tests/nil_class.fy index 7bf7f0d9..bab8611e 100644 --- a/tests/nil_class.fy +++ b/tests/nil_class.fy @@ -1,62 +1,62 @@ FancySpec describe: NilClass with: { it: "is false for calling and: with any value" with: 'and: when: { - nil and: true . is == nil - nil and: 'foo . is == nil - nil and: nil . is == nil - false and: true . is == false - false and: 'foo . is == false - false and: nil . is == false + nil and: true . is: nil + nil and: 'foo . is: nil + nil and: nil . is: nil + false and: true . is: false + false and: 'foo . is: false + false and: nil . is: false } it: "is nil/false for calling && with any value" with: '&& when: { - (nil && true) is == nil - (nil && 'foo) is == nil - (nil && nil) is == nil - (false && true) is == false - (false && 'foo) is == false - (false && nil) is == false + (nil && true) is: nil + (nil && 'foo) is: nil + (nil && nil) is: nil + (false && true) is: false + (false && 'foo) is: false + (false && nil) is: false } it: "is true for calling or: with any non-nil value" with: 'or: when: { - nil or: true . is == true - nil or: 'foo . is == 'foo + nil or: true . is: true + nil or: 'foo . is: 'foo } it: "is nil/false for calling or: with a nil/false value" with: 'or: when: { - nil or: nil . is == nil - nil or: false . is == false + nil or: nil . is: nil + nil or: false . is: false } it: "is true for calling || with any non-nil value" with: '|| when: { - (nil || true) is == true - (nil || 'foo) is == 'foo + (nil || true) is: true + (nil || 'foo) is: 'foo } it: "is nil for calling || with a nil value" with: '|| when: { - (nil || nil) is == nil + (nil || nil) is: nil } it: "does not call the block" with: 'if_true: when: { - nil if_true: { 'then } . is == nil + nil if_true: { 'then } . is: nil } it: "does not call the block" with: 'if_false: when: { - nil if_false: { 'false } . is == nil + nil if_false: { 'false } . is: nil } it: "is nil" with: 'nil? when: { - nil nil? is == true + nil nil? is: true } it: "is false" with: 'false? when: { - nil false? is == false + nil false? is: false } it: "is not true" with: 'true? when: { - nil true? is == false + nil true? is: false } it: "calls the block if nil" with: 'if_nil: when: { - nil if_nil: { 'is_nil } . is == 'is_nil + nil if_nil: { 'is_nil } . is: 'is_nil } } diff --git a/tests/object.fy b/tests/object.fy index 31d6407b..fbbfb6b7 100644 --- a/tests/object.fy +++ b/tests/object.fy @@ -1,36 +1,36 @@ FancySpec describe: Object with: { it: "dynamically evaluates a message-send with no arguments" when: { obj = 42 - obj receive_message: 'to_s . is == "42" + obj receive_message: 'to_s . is: "42" } it: "dynamically evaluates a message-send with a list of arguments" when: { obj = "hello, world" - obj receive_message: 'from:to: with_params: [0,4] . is == "hello" + obj receive_message: 'from:to: with_params: [0,4] . is: "hello" } it: "dynamically defines slotvalues" when: { obj = Object new - obj get_slot: 'foo . is == nil + obj get_slot: 'foo . is: nil obj set_slot: 'foo value: "hello, world" - obj get_slot: 'foo . is == "hello, world" + obj get_slot: 'foo . is: "hello, world" } it: "undefines a singleton method" when: { def self a_singleton_method { "a singleton method!" } - self a_singleton_method is == "a singleton method!" + self a_singleton_method is: "a singleton method!" self undefine_singleton_method: 'a_singleton_method { self a_singleton_method } raises: NoMethodError } it: "returns its class" when: { - nil class is == NilClass - true class is == TrueClass - "foo" class is == String - 'bar class is == Symbol - { 'a_block } class is == Block + nil class is: NilClass + true class is: TrueClass + "foo" class is: String + 'bar class is: Symbol + { 'a_block } class is: Block } it: "calls unkown_message:with_params: when calling an undefined method" when: { @@ -41,82 +41,82 @@ FancySpec describe: Object with: { } obj = UnknownMessage new - obj this_is_not_defined: "It's true!" . is == "Got: this_is_not_defined: It's true!" + obj this_is_not_defined: "It's true!" . is: "Got: this_is_not_defined: It's true!" } it: "returns a correct string representation" when: { - 3 to_s is == "3" - 'foo to_s is == "foo" - nil to_s is == "" + 3 to_s is: "3" + 'foo to_s is: "foo" + nil to_s is: "" } it: "returns a correct array representation" when: { - nil to_a is == [] - 'foo to_a is == ['foo] + nil to_a is: [] + 'foo to_a is: ['foo] <['foo => "bar", 'bar => "baz"]> to_a is =? [['bar, "baz"], ['foo, "bar"]] } it: "returns a correct fixnum representation" when: { - nil to_i is == 0 - 3 to_i is == 3 - 3.28437 to_i is == 3 + nil to_i is: 0 + 3 to_i is: 3 + 3.28437 to_i is: 3 } it: "is an Object of the correct Class (or Superclass)" when: { - Object new is_a?: Object . is == true - "foo" is_a?: String . is == true - "foo" is_a?: Object . is == true - 1123 is_a?: Fixnum . is == true - 1123 is_a?: Object . is == true - 132.123 is_a?: Float . is == true - 132.123 is_a?: Object . is == true + Object new is_a?: Object . is: true + "foo" is_a?: String . is: true + "foo" is_a?: Object . is: true + 1123 is_a?: Fixnum . is: true + 1123 is_a?: Object . is: true + 132.123 is_a?: Float . is: true + 132.123 is_a?: Object . is: true } # boolean messages it: "is true for calling and: with non-nil values" with: 'and: when: { - 'foo and: 'bar . is == 'bar + 'foo and: 'bar . is: 'bar } it: "is false for calling and: with a nil value" with: 'and: when: { - 'foo and: nil . is == nil + 'foo and: nil . is: nil } it: "is true for calling && with non-nil values" with: '&& when: { - ('foo && 'bar) is == 'bar + ('foo && 'bar) is: 'bar } it: "is false for calling && with a nil value" with: '&& when: { - ('foo && nil) is == nil + ('foo && nil) is: nil } it: "is true for calling or: with any value" with: 'or: when: { - 'foo or: 'bar . is == 'foo - 'foo or: nil . is == 'foo + 'foo or: 'bar . is: 'foo + 'foo or: nil . is: 'foo } it: "is true for calling || with any value" with: '|| when: { - ('foo || 'bar) is == 'foo - ('foo || nil) is == 'foo + ('foo || 'bar) is: 'foo + ('foo || nil) is: 'foo } # end boolean messages it: "is not nil for non-nil values" with: 'nil? when: { - 'foo nil? is == false - 1 nil? is == false - "hello" nil? is == false + 'foo nil? is: false + 1 nil? is: false + "hello" nil? is: false } it: "is not false for non-nil values" with: 'false? when: { - 'foo false? is == false - "hello, world" false? is == false + 'foo false? is: false + "hello, world" false? is: false } it: "is not true" with: 'true? when: { - 'foo true? is == false - "hello, world" true? is == false + 'foo true? is: false + "hello, world" true? is: false } it: "returns the correct value" with: 'returning:do: when: { @@ -124,7 +124,7 @@ FancySpec describe: Object with: { arr << 1 arr << 2 arr << 3 - } . is == [1,2,3] + } . is: [1,2,3] } it: "only calls a method if the receiver responds to it using a RespondsToProxy" with: 'if_responds? when: { @@ -135,19 +135,19 @@ FancySpec describe: Object with: { } s = SomeClass new - s if_responds? some_method is == 'it_works! - s if_responds? some_undefined_method is == nil + s if_responds? some_method is: 'it_works! + s if_responds? some_undefined_method is: nil } it: "calls the backtick: method when using the '`' syntax" with: 'backtick: when: { - `cat #{__FILE__}` is == (File read: __FILE__) + `cat #{__FILE__}` is: (File read: __FILE__) # override backticks def backtick: str { str + " - NOT!" } - `ls -al` is == "ls -al - NOT!" + `ls -al` is: "ls -al - NOT!" } it: "overrides true and does some wacky stuff" with: 'true when: { @@ -160,10 +160,10 @@ FancySpec describe: Object with: { 4 == 5 } } - MyClass new do_wacky_things is == false + MyClass new do_wacky_things is: false { - true is == false + true is: false } call_with_receiver: (MyClass new) } @@ -174,7 +174,7 @@ FancySpec describe: Object with: { } } - { nil is == true } call_with_receiver: (MyClass new) + { nil is: true } call_with_receiver: (MyClass new) } it: "overrides false" with: 'false when: { @@ -184,14 +184,14 @@ FancySpec describe: Object with: { } } - { false is == true } call_with_receiver: (MyClass2 new) + { false is: true } call_with_receiver: (MyClass2 new) } it: "implicitly sends a message to self if no receiver is specified" when: { def test { 42 } - test is == 42 - self test is == 42 - test is == (self test) + test is: 42 + self test is: 42 + test is: (self test) } it: "calls a given block in the context of the receiver (like a message cascade)" with: 'do: when: { @@ -202,9 +202,9 @@ FancySpec describe: Object with: { << 3 select!: 'even? } - arr is == [2] + arr is: [2] arr do: { - is == [2] # same + is: [2] # same } } } diff --git a/tests/pattern_matching.fy b/tests/pattern_matching.fy index e9e482d2..d2ec992e 100644 --- a/tests/pattern_matching.fy +++ b/tests/pattern_matching.fy @@ -8,28 +8,28 @@ FancySpec describe: "Pattern Matching" with: { } } - do_match: "foo" . is == 'string - do_match: 42 . is == 'fixnum - do_match: 'symbol . is == 'anything - do_match: Object . is == 'anything - do_match: 32.32 . is == 'anything + do_match: "foo" . is: 'string + do_match: 42 . is: 'fixnum + do_match: 'symbol . is: 'anything + do_match: Object . is: 'anything + do_match: 32.32 . is: 'anything } it: "binds a given match arg, if present, to the result of the match operation" when: { match "foobarbaz" { case /foo([a-z]+)baz/ -> |matcher| local1, local2, local3 = 'ignore, 'this_too, 'this_also - matcher[1] is == "bar" + matcher[1] is: "bar" } } it: "only binds a given match arg to the scope of the match case" when: { match "foobarbaz" { case /foo([a-z]+)baz/ -> |local_of_case| - local_of_case == nil . is == false + local_of_case == nil . is: false } - local_of_case is == nil + local_of_case is: nil } it: "only binds locals of the match clause to the scope of the match case" when: { @@ -38,16 +38,16 @@ FancySpec describe: "Pattern Matching" with: { local1 = "Hi, I am some local, that is be gone after this block." } - local1 is == nil + local1 is: nil } it: "binds any additional match args to the matched values" when: { str = "foo bar baz" match str { case /^foo (.*) (.*)$/ -> |all, match1, match2| - all class is == MatchData - match1 is == "bar" - match2 is == "baz" + all class is: MatchData + match1 is: "bar" + match2 is: "baz" } } @@ -59,10 +59,10 @@ FancySpec describe: "Pattern Matching" with: { match create_tuple: 10 { case Tuple -> |md, x, y, z| # convention: md[0] always holds the entire object that was matched. - md[0] is == (create_tuple: 10) - x is == 10 - y is == 100 - z is == nil # tuple only has 2 entries + md[0] is: (create_tuple: 10) + x is: 10 + y is: 100 + z is: nil # tuple only has 2 entries } } @@ -73,10 +73,10 @@ FancySpec describe: "Pattern Matching" with: { match create_array: 2 { case Array -> |_, a,b,c,d| - a is == 2 - b is == (2 ** 2) - c is == (2 ** 3) - d is == (2 ** 4) + a is: 2 + b is: (2 ** 2) + c is: (2 ** 3) + d is: (2 ** 4) } } @@ -84,9 +84,9 @@ FancySpec describe: "Pattern Matching" with: { ["hello world!", "hello you!", "no hello here!"] each: |str| { match str { case /^hello (.*)$/ -> |_, name| - name is_not == nil + name is_not: nil - case _ -> name is == nil + case _ -> name is: nil } } } @@ -110,20 +110,20 @@ FancySpec describe: "Pattern Matching" with: { } } - match_it: "hello, world!" is == 'string - match_it: [] is == 'empty - match_it: <[]> is == 'empty - match_it: (Set new) is == 'empty - match_it: (Stack new) is == 'empty - match_it: [1,2,3] is == 'not_empty - match_it: (1,"foo") is == 'not_empty - match_it: <['foo => 'bar]> is == 'not_empty - match_it: 'yo is == 'symbol - match_it: 32 is == 64 - match_it: 4 is == 8 - match_it: 3 is == '<= - match_it: 2 is == '<= - match_it: 0 is == '<= - match_it: -1 is == '<= + match_it: "hello, world!" . is: 'string + match_it: [] . is: 'empty + match_it: <[]> . is: 'empty + match_it: (Set new) . is: 'empty + match_it: (Stack new) . is: 'empty + match_it: [1,2,3] . is: 'not_empty + match_it: (1,"foo") . is: 'not_empty + match_it: <['foo => 'bar]> . is: 'not_empty + match_it: 'yo . is: 'symbol + match_it: 32 . is: 64 + match_it: 4 . is: 8 + match_it: 3 . is: '<= + match_it: 2 . is: '<= + match_it: 0 . is: '<= + match_it: -1 . is: '<= } } diff --git a/tests/range.fy b/tests/range.fy index 71551170..cc888d20 100644 --- a/tests/range.fy +++ b/tests/range.fy @@ -1,11 +1,11 @@ FancySpec describe: Range with: { it: "has the correct amount of elements" with: 'size when: { - Range new: 1 to: 10 . to_a size is == 10 - (1..10) to_a size is == 10 - ("a".."z") to_a size is == 26 + Range new: 1 to: 10 . to_a size is: 10 + (1..10) to_a size is: 10 + ("a".."z") to_a size is: 26 } it: "has a working literal syntax" when: { - (1..10) is == (Range new: 1 to: 10) + (1..10) is: (Range new: 1 to: 10) } } diff --git a/tests/set.fy b/tests/set.fy index b3ce53c0..ece11a15 100644 --- a/tests/set.fy +++ b/tests/set.fy @@ -3,62 +3,62 @@ FancySpec describe: Set with: { s = Set new s << 'foo s << 'foo - s size is == 1 - s is == (Set[['foo]]) - s is_not == ['foo] # Sets and Arrays differ + s size is: 1 + s is: (Set[['foo]]) + s is_not: ['foo] # Sets and Arrays differ } it: "is empty" with: 'empty? when: { s = Set new - s empty? is == true + s empty? is: true s = Set[[]] - s empty? is == true + s empty? is: true } it: "is not empty" with: 'empty? when: { s = Set new s << 1 - s empty? is == false + s empty? is: false s = Set[[1,2,3]] - s empty? is == false + s empty? is: false } it: "has the correct size" with: 'size when: { s = Set new - s size is == 0 + s size is: 0 s << 'foo - s size is == 1 + s size is: 1 10 times: { s << 'bar # only inserted once } - s size is == 2 + s size is: 2 } it: "is equal to another set" with: '== when: { s1 = Set new s2 = Set new - s1 == s2 is == true + s1 == s2 is: true s1 = Set[[1,2,3]] s2 = Set[[3,2,1]] - s1 == s2 is == true + s1 == s2 is: true s1 << 1 # should have no effect s2 << 3 - s2 == s1 is == true + s2 == s1 is: true } it: "includes a value" with: 'includes?: when: { s = Set[[1,2,3,"foo", 'bar, 10.0, 10.1]] - s includes?: 1 is == true - s includes?: 2 is == true - s includes?: 3 is == true - s includes?: "foo" is == true - s includes?: 'bar is == true - s includes?: 10.0 is == true - s includes?: 10.1 is == true - s includes?: 'hello is == false - s includes?: nil is == false + s includes?: 1 . is: true + s includes?: 2 . is: true + s includes?: 3 . is: true + s includes?: "foo" . is: true + s includes?: 'bar . is: true + s includes?: 10.0 . is: true + s includes?: 10.1 . is: true + s includes?: 'hello . is: false + s includes?: nil . is: false } it: "calls a Block with each value" with: 'each: when: { @@ -66,36 +66,36 @@ FancySpec describe: Set with: { sum = 0 s each: |val| { sum = sum + val - s includes?: val is == true + s includes?: val . is: true } - sum is == (s sum) + sum is: (s sum) } it: "removes a value in the Set" with: 'remove: when: { s = Set[(1,2,3)] s remove: 2 - s is == (Set[(1,3)]) + s is: (Set[(1,3)]) s remove: 1 - s is == (Set[[3]]) + s is: (Set[[3]]) s remove: 3 - s empty? is == true + s empty? . is: true } it: "returns the union of two sets" with: '+ when: { s1 = Set[(1,2,3)] s2 = Set[(3,4,5)] - s1 + s2 is == (Set[(1,2,3,4,5)]) + s1 + s2 is: (Set[(1,2,3,4,5)]) } it: "returns the difference of two sets" with: '- when: { s1 = Set[(1,2,3)] s2 = Set[(3,4,5)] - s1 - s2 is == (Set[(1,2)]) + s1 - s2 is: (Set[(1,2)]) } it: "returns the intersection of two sets" with: '& when: { s1 = Set[(1,2,3)] s2 = Set[(2,3,4,5)] - s1 & s2 is == (Set[(2,3)]) + s1 & s2 is: (Set[(2,3)]) } } diff --git a/tests/stack.fy b/tests/stack.fy index 7a02ca39..0a7d03b1 100644 --- a/tests/stack.fy +++ b/tests/stack.fy @@ -1,13 +1,13 @@ FancySpec describe: Stack with: { it: "is empty when created" with: '<< when: { s = Stack new - s empty? is == true + s empty? is: true } it: "returns the last inserted element" with: 'pop when: { s = Stack new s push: 1 - s pop is == 1 + s pop is: 1 objs = [1,2,3] objs each: |x| { @@ -15,7 +15,7 @@ FancySpec describe: Stack with: { } objs reverse each: |x| { - s pop is == x + s pop is: x } } @@ -24,7 +24,7 @@ FancySpec describe: Stack with: { 10 times: |i| { s << i } val = 9 s each: |x| { - x is == val + x is: val val = val - 1 } } diff --git a/tests/string.fy b/tests/string.fy index c9cdd731..8ed6704e 100644 --- a/tests/string.fy +++ b/tests/string.fy @@ -1,140 +1,140 @@ FancySpec describe: String with: { it: "is the empty string on initialization" when: { str = String new - str is == "" + str is: "" } it: "is the concatination of the strings" with: '+ when: { str1 = "hello " str2 = "world" str3 = "!" - str1 + str2 + str3 is == "hello world!" + str1 + str2 + str3 is: "hello world!" } it: "concatenates the argument's string value with a string" with: '++ when: { - "I'm " ++ 21 ++ " years old!" is == "I'm 21 years old!" + "I'm " ++ 21 ++ " years old!" is: "I'm 21 years old!" } it: "returns the correct substring" with: 'from:to: when: { - "hello, world" from: 2 to: 5 . is == "llo," - "hello, world"[[2,5]] . is == "llo," + "hello, world" from: 2 to: 5 . is: "llo," + "hello, world"[[2,5]] . is: "llo," } it: "returns the upcased string" with: 'upcase when: { - "hello, world" upcase is == "HELLO, WORLD" + "hello, world" upcase is: "HELLO, WORLD" } it: "returns the downcased string" with: 'downcase when: { - "HELLO, WORLD" downcase is == "hello, world" + "HELLO, WORLD" downcase is: "hello, world" } it: "returns the same string by down- and upcasing in a row" when: { - "HELLO, WORLD" downcase upcase is == "HELLO, WORLD" + "HELLO, WORLD" downcase upcase is: "HELLO, WORLD" } it: "iterates over each character in a string" with: 'each: when: { str = "Hello, World!" i = 0 str each: |char| { - char is == (str at: i) + char is: (str at: i) i = i + 1 } } it: "behaves like a collection/sequence via each:" with: 'uniq when: { str = "Hello, World!" - str uniq join: "" . is == "Helo, Wrd!" + str uniq join: "" . is: "Helo, Wrd!" } it: "has all its characters as instances of String class" with: 'all?: when: { str = "foo bar baz" - str all?: |c| { c is_a?: String } . is == true + str all?: |c| { c is_a?: String } . is: true } it: "drops all characters upto a whitespace" with: 'drop_while: when: { - "hello world" drop_while: |c| { c != " " } . join: "" . is == " world" + "hello world" drop_while: |c| { c != " " } . join: "" . is: " world" } it: "is empty" with: 'empty? when: { - "" empty? is == true - " " empty? is == false - String new empty? is == true + "" empty? is: true + " " empty? is: false + String new empty? is: true } it: "is blank" with: 'blank? when: { - "" blank? is == true - " " blank? is == true - "-" blank? is == false - " " blank? is == true - "hello world" blank? is == false - "hello world" at: 5 . blank? is == true + "" blank? is: true + " " blank? is: true + "-" blank? is: false + " " blank? is: true + "hello world" blank? is: false + "hello world" at: 5 . blank? is: true } it: "is evaluated as fancy code and returns the correct value" when: { x = "'foo" eval - x is == 'foo - "3 + 4" eval is == 7 - "'foo to_s upcase" eval is == "FOO" - "33.33" eval is == 33.33 + x is: 'foo + "3 + 4" eval is: 7 + "'foo to_s upcase" eval is: "FOO" + "33.33" eval is: 33.33 } it: "returns itself times n" with: '* when: { - "foo" * 2 is == "foofoo" - "f" ++ ("o" * 2) ++ "bar" is == "foobar" + "foo" * 2 is: "foofoo" + "f" ++ ("o" * 2) ++ "bar" is: "foobar" } it: "splits a string at a given seperator string" with: 'split: when: { str = "hello, world, how are you?" - str split: ", " . is == ["hello", "world", "how are you?"] - "1,2,3,,4,5" split: "," . is == ["1", "2", "3", "", "4", "5"] - ",1,2,3,4," split: "," . is == ["", "1", "2", "3", "4"] - "foo bar\n baz yo" split is == ["foo", "bar", "baz", "yo"] - "foo bar\n baz yo" words is == ["foo", "bar", "baz", "yo"] + str split: ", " . is: ["hello", "world", "how are you?"] + "1,2,3,,4,5" split: "," . is: ["1", "2", "3", "", "4", "5"] + ",1,2,3,4," split: "," . is: ["", "1", "2", "3", "4"] + "foo bar\n baz yo" split is: ["foo", "bar", "baz", "yo"] + "foo bar\n baz yo" words is: ["foo", "bar", "baz", "yo"] } it: "supports basic string interpolation" when: { - "hello, #{10 * 10} world!" is == "hello, 100 world!" + "hello, #{10 * 10} world!" is: "hello, 100 world!" x = "world" - "hello, #{x}!!" is == "hello, world!!" + "hello, #{x}!!" is: "hello, world!!" - "hello, #{x}, Fancy #{'rocks to_s upcase}!!" is == "hello, world, Fancy ROCKS!!" + "hello, #{x}, Fancy #{'rocks to_s upcase}!!" is: "hello, world, Fancy ROCKS!!" } it: "returns the String as a Symbol" with: 'to_sym when: { - "foo" to_sym is == 'foo - "foo:bar:" to_sym is == 'foo:bar: - "FooBar?!" to_sym is == 'FooBar?! + "foo" to_sym is: 'foo + "foo:bar:" to_sym is: 'foo:bar: + "FooBar?!" to_sym is: 'FooBar?! "+-&/^\?a!" to_sym is '+-&/^\?a! } it: "allows replacing characters in the string" with: '[]: when: { s = "hello" s[0]: "H" - s is == "Hello" + s is: "Hello" s[0]: "Good day. H" - s is == "Good day. Hello" + s is: "Good day. Hello" s[-1]: "o." - s is == "Good day. Hello." + s is: "Good day. Hello." } it: "contains a substring" with: 'includes?: when: { - "foo bar baz" includes?: "foo" is == true - "foo bar baz" includes?: "bar" is == true - "foo bar baz" includes?: "baz" is == true - "foo bar baz" includes?: " " is == true - "foo bar baz" includes?: "" is == true - "foo bar baz" includes?: "foobarbaz" is == false + "foo bar baz" includes?: "foo" . is: true + "foo bar baz" includes?: "bar" . is: true + "foo bar baz" includes?: "baz" . is: true + "foo bar baz" includes?: " " . is: true + "foo bar baz" includes?: "" . is: true + "foo bar baz" includes?: "foobarbaz" . is: false } it: "should remove any leading indentation" with: 'skip_leading_indentation when: { """ hello, world! how are you? - """ skip_leading_indentation is == "hello, world!\nhow are you?" + """ skip_leading_indentation is: "hello, world!\nhow are you?" str = """ foo, bar """ - str skip_leading_indentation is_not == str + str skip_leading_indentation is_not: str } } diff --git a/tests/stringio.fy b/tests/stringio.fy index ae9f691f..64310750 100644 --- a/tests/stringio.fy +++ b/tests/stringio.fy @@ -4,14 +4,15 @@ FancySpec describe: StringIO with: { before_each: { @s = StringIO new } + it: "returns the empty string on initialization" with: 'string when: { - @s string == "" + @s string is: "" } it: "appends strings to its string value" with: '<< when: { @s << "foo" @s << "\n" @s << "bar" - @s string is == "foo\nbar" + @s string is: "foo\nbar" } } \ No newline at end of file diff --git a/tests/struct.fy b/tests/struct.fy index 1efc3e1c..6f28d62f 100644 --- a/tests/struct.fy +++ b/tests/struct.fy @@ -2,26 +2,26 @@ FancySpec describe: Struct with: { Point = Struct new: ('x, 'y) it: "creates a struct class" when: { - Point is_a?: Class is == true + Point is_a?: Class . is: true } it: "creates setter methods for a struct's fields" when: { - Point instance_methods includes?: "x:" is == true - Point instance_methods includes?: "y:" is == true + Point instance_methods includes?: "x:" . is: true + Point instance_methods includes?: "y:" . is: true } it: "creates getter methods for a struct's fields" when: { - Point instance_methods includes?: ":x" is == true - Point instance_methods includes?: ":y" is == true + Point instance_methods includes?: ":x" . is: true + Point instance_methods includes?: ":y" . is: true } it: "works with getter and setter methods as expected" when: { p = Point new: (2, 3) - p x is == 2 - p y is == 3 + p x is: 2 + p y is: 3 p x: 10 p y: 20 - p x is == 10 - p y is == 20 + p x is: 10 + p y is: 20 } } diff --git a/tests/symbol.fy b/tests/symbol.fy index 01f8e081..eb0ef2f6 100644 --- a/tests/symbol.fy +++ b/tests/symbol.fy @@ -1,17 +1,17 @@ FancySpec describe: Symbol with: { it: "is usable like a block for Enumerable methods" when: { [1,2,3,4,5] map: 'squared . - is == [1,4,9,16,25] + is: [1,4,9,16,25] ["hello", "world"] map: 'upcase . - is == ["HELLO", "WORLD"] + is: ["HELLO", "WORLD"] [1,2,3,4,5] select: 'even? . - is == [2,4] + is: [2,4] } it: "evaluates itself within the current scope" when: { x = 10 - 'x eval is == x + 'x eval is: x } } diff --git a/tests/true_class.fy b/tests/true_class.fy index 3c855a6c..9bf10044 100644 --- a/tests/true_class.fy +++ b/tests/true_class.fy @@ -1,63 +1,63 @@ FancySpec describe: TrueClass with: { it: "is true for calling and: with non-nil value" with: 'and: when: { - true and: true . is == true - true and: 'bar . is == 'bar + true and: true . is: true + true and: 'bar . is: 'bar } it: "is false for calling and: with a nil value" with: 'and: when: { - true and: nil . is == nil + true and: nil . is: nil } it: "is true for calling && with non-nil value" with: '&& when: { - (true && true) is == true - (true && 'bar) is == 'bar + (true && true) is: true + (true && 'bar) is: 'bar } it: "is false for calling && with a nil value" with: '&& when: { - (true && nil) is == nil + (true && nil) is: nil } it: "is true for calling or: with both non-nil values" with: 'or: when: { - true or: true . is == true + true or: true . is: true } it: "is true for calling or: with any values" with: 'or: when: { - true or: nil . is == true - true or: true . is == true - true or: 'foo . is == true + true or: nil . is: true + true or: true . is: true + true or: 'foo . is: true } it: "is true for calling || with both non-nil values" with: '|| when: { - (true || true) is == true + (true || true) is: true } it: "is true for calling || with any values" with: '|| when: { - (true || nil) is == true - (true || true) is == true - (true || 'foo) is == true + (true || nil) is: true + (true || true) is: true + (true || 'foo) is: true } it: "calls the then-block" with: 'if_true:else: when: { - true if_true: { 'then } else: { 'else } . is == 'then + true if_true: { 'then } else: { 'else } . is: 'then } it: "does not call the block" with: 'if_false: when: { - true if_false: { 'false } . is == nil + true if_false: { 'false } . is: nil } it: "is not nil" with: 'nil? when: { - true nil? is == false + true nil? is: false } it: "is not false" with: 'false? when: { - true false? is == false + true false? is: false } it: "is true" with: 'true? when: { - true true? is == true + true true? is: true } it: "does NOT call the block if true" with: 'if_nil: when: { - true if_nil: { 'is_nil } . is == nil + true if_nil: { 'is_nil } . is: nil } } diff --git a/tests/tuple.fy b/tests/tuple.fy index 38163206..008882e6 100644 --- a/tests/tuple.fy +++ b/tests/tuple.fy @@ -1,29 +1,29 @@ FancySpec describe: Tuple with: { it: "has the correct amount of elements" with: 'size when: { - (1,2) size is == 2 - (1,2,3) size is == 3 - ('foo, "bar", 'baz, 123) size is == 4 + (1,2) size is: 2 + (1,2,3) size is: 3 + ('foo, "bar", 'baz, 123) size is: 4 } it: "has the correct items at a given index" with: 'at: when: { tuple = ("foo", 'bar, "baz") - tuple at: 0 . is == "foo" - tuple at: 1 . is == 'bar - tuple at: 2 . is == "baz" + tuple at: 0 . is: "foo" + tuple at: 1 . is: 'bar + tuple at: 2 . is: "baz" } it: "has the correct items at a given index" with: '[] when: { tuple = ("foo", 'bar, "baz") - tuple[0] . is == "foo" - tuple[1] . is == 'bar - tuple[2] . is == "baz" + tuple[0] . is: "foo" + tuple[1] . is: 'bar + tuple[2] . is: "baz" } it: "creates a new tuple with values set to nil" with: 'new: when: { t = Tuple new: 2 - t size is == 2 - t[0] is == nil - t[1] is == nil + t size is: 2 + t[0] is: nil + t[1] is: nil } it: "does not allow to create an empty Tuple" with: 'new when: {