nomsu/tests/object.nom
Bruce Hill b53516c47c Simplified and correctified lib/object (though the codegen still need
streamlining), added a .stub member to Action trees, and switched
Source's repr to be @filename[start:stop] instead of
"filename[start:stop]"
2018-05-30 17:21:19 -07:00

41 lines
889 B
Plaintext

use "core"
use "lib/object.nom"
object "Dog"
action [bark]
%barks <- ("Bark!" for % in 1 to ((me).barks))
return: %barks joined with " "
action [get pissed off]
((me).barks) +<- 1
%d <-: new "Dog" {barks:2}
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!"
assume: "\(%d.class)" = "Dog"
assume: (%d's "barks") = 3
as: new "Dog" {barks:1}
assume: (bark) = "Bark!"
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'"
say "Object test passed."