-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval-js.t
85 lines (75 loc) · 2.19 KB
/
eval-js.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!perl -T
use 5.010;
our $JavaScript_available;
our $JE_available;
BEGIN {
{
eval { require JavaScript };
unless ($@) {
$JavaScript_available++;
say "# Using JavaScript Perl module for testing JS emitter";
last;
}
eval { require JE };
unless ($@) {
$JE_available++;
say "# Using JE Perl module for testing JS emitter";
last;
}
require Test::More;
Test::More::plan(skip_all => "no JavaScript engine available");
}
}
sub eval_js {
my ($str) = @_;
if ($JavaScript_available) {
state $rt = JavaScript::Runtime->new;
state $cx = $rt->create_context;
return $cx->eval($str);
} elsif ($JE_available) {
state $je = JE->new;
return $je->eval($str);
} else {
die "BUG: no Javascript engine available";
}
}
use strict;
use warnings;
use Test::More tests => 1; #154*2 - (7+7+7);
use Test::Exception;
use Language::Expr::Compiler::JS;
use POSIX;
use lib "./t";
require "stdtests.pl";
my $js = new Language::Expr::Compiler::JS;
#$le->var(a => 1, b => 2, 'a b' => 3);
#$le->func(
# 'length' => sub { length(shift) },
# 'floor' => sub { POSIX::floor(shift) },
# 'ceil' => sub { POSIX::ceil(shift) },
#);
#package Language::Expr::Compiler::Perl;
#sub floor { POSIX::floor(shift) }
#sub ceil { POSIX::ceil(shift) }
#package main;
for my $t (@{[]}) {
my @use_itp;
my $tname = "category=$t->{category} $t->{text}";
if ($t->{parse_error}) {
$tname .= ", parse error: $t->{parse_error})";
throws_ok { eval_js($t->{text}) } $t->{parse_error}, $tname;
} else {
$tname .= ", js=q{".$js->js($t->{text})."}";
if ($t->{run_error}) {
$tname .= ", run error: $t->{run_error})";
throws_ok { eval_js($t->{text}) } $t->{run_error}, $tname;
} elsif ($t->{compiler_run_error}) {
$tname .= ", run error: $t->{compiler_run_error})";
throws_ok { eval_js($t->{text}) } $t->{compiler_run_error}, $tname;
} else {
$tname .= ")";
is_deeply( eval_js($t->{text}), $t->{result}, $tname );
}
}
}
ok(1);