Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Start a test file for QAST.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| use QRegex; | ||
|
|
||
| plan(3); | ||
|
|
||
| sub compile_qast($qast) { | ||
| my $post := QAST::Compiler.as_post($qast); | ||
| my $pir := QAST::Compiler.pir($post); | ||
| QAST::Compiler.evalpmc($pir); | ||
| } | ||
| sub is_qast($qast, $value, $desc) { | ||
| try { | ||
| my $code := compile_qast($qast); | ||
| ok($code() eq $value, $desc); | ||
| CATCH { ok(0, $desc) } | ||
| } | ||
| } | ||
|
|
||
| is_qast( | ||
| QAST::Block.new( | ||
| QAST::IVal.new( :value(42) ) | ||
| ), | ||
| 42, | ||
| 'IVal node'); | ||
|
|
||
| is_qast( | ||
| QAST::Block.new( | ||
| QAST::NVal.new( :value(6.9) ) | ||
| ), | ||
| 6.9, | ||
| 'NVal node'); | ||
|
|
||
| is_qast( | ||
| QAST::Block.new( | ||
| QAST::SVal.new( :value('Gorillas just love pizza') ) | ||
| ), | ||
| 'Gorillas just love pizza', | ||
| 'SVal node'); |