Skip to content

Commit

Permalink
Added tests for RakUAST::Var::Compiler::(File|Line|Lookup)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 12, 2023
1 parent 9686757 commit e3b32da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
4 changes: 0 additions & 4 deletions t/12-rakuast/TODO
Expand Up @@ -104,10 +104,6 @@ RakuAST::Type::Parameterized
RakuAST::Type::Setting
RakuAST::UndeclaredSymbolDescription
RakuAST::UndeclaredSymbolDescription::Routine
RakuAST::Var::Compiler
RakuAST::Var::Compiler::File
RakuAST::Var::Compiler::Line
RakuAST::Var::Compiler::Lookup
RakuAST::Var::Lexical::Constant
RakuAST::Var::Lexical::Setting
RakuAST::Var::Package
Expand Down
34 changes: 33 additions & 1 deletion t/12-rakuast/var.rakutest
Expand Up @@ -2,7 +2,7 @@ use MONKEY-SEE-NO-EVAL;
use experimental :rakuast;
use Test;

plan 40;
plan 43;

my $ast;
my $deparsed;
Expand All @@ -13,6 +13,38 @@ sub ast(RakuAST::Node:D $node --> Nil) {
diag $deparsed.chomp;
}

# MUST be the first test to handle EVAL_n counter
subtest 'Special compiler variable $?FILE' => {
my $file := $*CWD.absolute ~ '/EVAL_1';
# $?FILE
ast RakuAST::Var::Compiler::File.new($file);

is-deeply $deparsed, '$?FILE', 'deparse';
is-deeply $_, $file, @type[$++]
for EVAL($ast), try EVAL($deparsed);
}

subtest 'Special compiler variable $?LINE' => {
# $?LINE
# always line 1 inside the EVAL
ast RakuAST::Var::Compiler::Line.new(1);

is-deeply $deparsed, '$?LINE', 'deparse';
is-deeply $_, 1, @type[$++]
for EVAL($ast), try EVAL($deparsed);
}

package Foo {
subtest 'Special compiler variable $?PACKAGE' => {
# $?PACKAGE
ast RakuAST::Var::Compiler::Lookup.new('$?PACKAGE');

is-deeply $deparsed, '$?PACKAGE', 'deparse';
is-deeply $_, Foo, @type[$++]
for EVAL($ast), try EVAL($deparsed);
}
}

subtest 'Lexical variable lookup ($ sigil)' => {
my $x = 42;

Expand Down

0 comments on commit e3b32da

Please sign in to comment.