2018-02-02 15:48:28 -08:00
|
|
|
use "core"
|
2018-05-24 14:57:24 -07:00
|
|
|
use "lib/object.nom"
|
2018-01-31 15:31:25 -08:00
|
|
|
|
2018-05-30 17:20:22 -07:00
|
|
|
object "Dog"
|
|
|
|
action [bark]
|
|
|
|
%barks <- ("Bark!" for % in 1 to ((me).barks))
|
|
|
|
return: %barks joined with " "
|
2018-01-31 15:31:25 -08:00
|
|
|
|
2018-05-30 17:20:22 -07:00
|
|
|
action [get pissed off]
|
|
|
|
((me).barks) +<- 1
|
2018-01-31 15:31:25 -08:00
|
|
|
|
2018-05-30 17:20:22 -07:00
|
|
|
%d <-: new "Dog" {barks:2}
|
2018-05-24 14:57:24 -07:00
|
|
|
as %d
|
|
|
|
assume: (me) = %d
|
|
|
|
assume: ((me).barks) = 2
|
|
|
|
assume: (bark) = "Bark! Bark!"
|
|
|
|
get pissed off
|
|
|
|
assume: ((me).barks) = 3
|
|
|
|
assume: (bark) = "Bark! Bark! Bark!"
|
2018-05-30 17:20:22 -07:00
|
|
|
assume: "\(%d.class)" = "Dog"
|
2018-05-24 14:57:24 -07:00
|
|
|
assume: (%d's "barks") = 3
|
|
|
|
|
2018-05-30 17:20:22 -07:00
|
|
|
as: new "Dog" {barks:1}
|
2018-05-24 14:57:24 -07:00
|
|
|
assume: (bark) = "Bark!"
|
|
|
|
|
2018-05-30 17:20:22 -07:00
|
|
|
action [foo]
|
|
|
|
as: new "Dog" {barks:23}
|
|
|
|
return: (me).barks
|
|
|
|
barf "Reached unreachable code"
|
|
|
|
|
|
|
|
assume: (foo) = 23
|
|
|
|
|
|
|
|
as: new "Dog" {barks:101}
|
|
|
|
try: as (new "Dog" {barks:8}) (barf)
|
|
|
|
..and if it succeeds: barf
|
|
|
|
|
|
|
|
assume: (me).barks = 101
|
|
|
|
..or barf "Error in nested 'as % %' failed to properly reset 'self'"
|
|
|
|
|
2018-05-24 14:57:24 -07:00
|
|
|
say "Object test passed."
|