tests/object.fy in fancy-0.5.0 vs tests/object.fy in fancy-0.6.0
- old
+ new
@@ -215,20 +215,67 @@
arr do: {
is: [2] # same
}
}
- it: "returns a set of its slot names" with: 'slots when: {
+ it: "calls a given block with the receiver before returning itself" with: 'tap: when: {
+ 10 + 2 tap: |x| {
+ x is: 12
+ x is_a?: Number . is: true
+ } . is: 12
+
+ "foo" + "bar" tap: @{ is: "foobar"; * 2 is: "foobarfoobar" } . is: "foobar"
+ }
+
+ it: "returns an array of its slot names" with: 'slots when: {
class GotSlots {
def initialize {
@x, @y = 1, 2
}
def set_another_slot {
@z = 123
}
}
gs = GotSlots new
- gs slots is: $ Set[['x, 'y]]
+ Set[gs slots] is: $ Set[['x, 'y]]
gs set_another_slot
- gs slots is: $ Set[['x,'y,'z]]
+ Set[gs slots] is: $ Set[['x,'y,'z]]
+ }
+
+ it: "copies a given list of slots from one object to another" with: 'copy_slots:from: when: {
+ o1 = { slot1: "foo" slot2: "bar" } to_object
+ o2 = {} to_object
+ o2 copy_slots: ['slot1] from: o1
+ o2 slots includes?: 'slot1 . is: true
+ o2 get_slot: 'slot1 == (o1 slot1) is: true
+ }
+
+ it: "copies all slots from one object to another" with: 'copy_slots_from: when: {
+ o1 = { slot1: "foo" slot2: "bar" } to_object
+ o2 = {} to_object
+ o2 slots is: []
+ o2 copy_slots_from: o1
+ o2 slots includes?: 'slot1 . is: true
+ o2 slots includes?: 'slot2 . is: true
+ o2 slots is: $ o1 slots
+ o2 get_slot: 'slot1 == (o1 slot1) is: true
+ o2 get_slot: 'slot2 == (o1 slot2) is: true
+ }
+
+ it: "returns itself when return is send as a message" with: 'return when: {
+ def foo: array {
+ array each: @{ return }
+ }
+ foo: [1,2,3] . is: 1
+
+ def bar: array values: vals {
+ array each: |x| {
+ vals << x
+ x return
+ }
+ }
+
+ v = []
+ bar: [1,2,3] values: v . is: 1
+ v is: [1]
}
}