From e3b32da180b72a267e5b7c1173ef17e0d34ee028 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Thu, 12 Jan 2023 21:01:27 +0100 Subject: [PATCH] Added tests for RakUAST::Var::Compiler::(File|Line|Lookup) --- t/12-rakuast/TODO | 4 ---- t/12-rakuast/var.rakutest | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/t/12-rakuast/TODO b/t/12-rakuast/TODO index 924b0328d30..8c9adfd49f8 100644 --- a/t/12-rakuast/TODO +++ b/t/12-rakuast/TODO @@ -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 diff --git a/t/12-rakuast/var.rakutest b/t/12-rakuast/var.rakutest index 30b6f705cac..3407d1fdeac 100644 --- a/t/12-rakuast/var.rakutest +++ b/t/12-rakuast/var.rakutest @@ -2,7 +2,7 @@ use MONKEY-SEE-NO-EVAL; use experimental :rakuast; use Test; -plan 40; +plan 43; my $ast; my $deparsed; @@ -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;