File: import_os.t

package info (click to toggle)
libjavascript-quickjs-perl 0.21-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,180 kB
  • sloc: ansic: 72,822; javascript: 7,743; perl: 1,065; makefile: 353; sh: 108
file content (44 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download
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
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;
use Test::FailWarnings;
use Test::Deep;
use Test::Fatal;

use JavaScript::QuickJS;

for my $mod (qw(os std)) {
    my $js = JavaScript::QuickJS->new()->$mod();

    # ensure that this doesn't crash
    is(
        exception { $js->eval_module( qq<import * as what from "$mod";> ) },
        undef,
        "JS with $mod(): module can import $mod",
    );

    my $keys = $js->eval( qq<Object.keys($mod)> );
    cmp_deeply(
        $keys,
        superbagof( ignore() ),
        "JS with $mod(): global “$mod” exists in script mode",
    ) or diag explain $keys;

    my $js2 = JavaScript::QuickJS->new();
    cmp_deeply(
        exception { $js2->eval_module( qq<import * as what from "$mod";> ) },
        re(qr/ReferenceError/),
        "JS without $mod(): module fails to import $mod",
    );

    cmp_deeply(
        exception { $js2->eval( qq<Object.keys($mod)> ) },
        re(qr/ReferenceError/),
        "JS without $mod(): script lacks global $mod",
    );
}

done_testing;