Skip to content

Commit

Permalink
Sketch out a basic test for attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jan 2, 2013
1 parent 4557e1c commit c50db7c
Showing 1 changed file with 85 additions and 1 deletion.
86 changes: 85 additions & 1 deletion t/qast_6model.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use helper;

plan(4);
plan(5);

qast_test(
-> {
Expand Down Expand Up @@ -194,3 +194,87 @@ qast_test(
},
"Survived!\n",
"Can create instances of a type");

qast_test(
-> {
my $block := QAST::Block.new(
QAST::Stmts.new(
# Create a new type.
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name('type'), :scope('local'), :decl('var') ),
QAST::Op.new(
:op('callmethod'), :name('new_type'),
QAST::Op.new( :op('knowhow') )
)
),

# Get its HOW, add a method, and compose it.
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name('how'), :scope('local'), :decl('var') ),
QAST::Op.new(
:op('how'),
QAST::Var.new( :name('type'), :scope('local') )
)
),
QAST::Op.new(
:op('callmethod'), :name('add_attribute'),
QAST::Var.new( :name('how'), :scope('local') ),
QAST::Var.new( :name('type'), :scope('local') ),
QAST::Op.new(
:op('callmethod'), :name('new'),
QAST::Op.new( :op('knowhowattr') ),
QAST::SVal.new( :value('$!x'), :named('name') ),
QAST::Op.new( :op('knowhow'), :named('type') )
)
),
QAST::Op.new(
:op('callmethod'), :name('compose'),
QAST::Var.new( :name('how'), :scope('local') ),
QAST::Var.new( :name('type'), :scope('local') )
),

# Create a new instance.
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name('test'), :scope('local'), :decl('var') ),
QAST::Op.new(
:op('create'),
QAST::Var.new( :name('type'), :scope('local') )
)
),

# Store something in the attribute.
QAST::Op.new(
:op('bindattr'),
QAST::Var.new( :name('test'), :scope('local') ),
QAST::Var.new( :name('type'), :scope('local') ),
QAST::SVal.new( :value('$!x') ),
QAST::Op.new(
:op('list'),
QAST::Op.new( :op('knowhow') ),
QAST::Op.new( :op('knowhow') )
)),

# Get it back.
QAST::Op.new(
:op('say'),
QAST::Op.new(
:op('elems'),
QAST::Op.new(
:op('getattr'),
QAST::Var.new( :name('test'), :scope('local') ),
QAST::Var.new( :name('type'), :scope('local') ),
QAST::SVal.new( :value('$!x') )
)))
));
QAST::CompUnit.new(
$block,
:main(QAST::Op.new(
:op('call'),
QAST::BVal.new( :value($block) )
)))
},
"2\n",
"Reference type attribute works");

0 comments on commit c50db7c

Please sign in to comment.