summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/test/test-getopt.jsx
blob: 63731b924d4d180df93e469c7ab16c76539779c2 (plain)
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
import "test-case.jsx";
import "getopt.jsx";

class _Test extends TestCase
{
    function test_empty () : void
    {
        var parser = new BasicParser('', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }

    function test_silent () : void
    {
        var parser = new BasicParser(':', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }

    function test_args_without_param_01 () : void
    {
        var parser = new BasicParser(':l', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }

    function test_args_without_param_02 () : void
    {
        var parser = new BasicParser(':l:', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }
    
    function test_args_without_param_03 () : void
    {
        var parser = new BasicParser(':las', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }
    
    function test_args_without_param_04 () : void
    {
        var parser = new BasicParser(':l:a:s:', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }
    
    function test_long_args_without_param () : void
    {
        var parser = new BasicParser(':l:(long)', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }

    function test_args () : void
    {
        var parser = new BasicParser(':l:(long)', ['-l', 'arg1', '--long=q', 'b', '--long', 'foo']);
        var opt = parser.getopt();
        this.expect(opt.option).toBe('l');
        this.expect(opt.optarg).toBe('arg1');
        opt = parser.getopt();
        this.expect(opt.option).toBe('l');
        this.expect(opt.optarg).toBe('q');
        opt = parser.getopt();
        this.expect(opt.option).toBe('b');
        opt = parser.getopt();
        this.expect(opt.option).toBe('--long');
        opt = parser.getopt();
        this.expect(opt.option).toBe('foo');
    }

    function test_aliased_long_args_without_param_01 () : void
    {
        var parser = new BasicParser(':l:(long)(longer)', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }

    function test_aliased_long_args_without_param_02 () : void
    {
        var parser = new BasicParser(':la:r(recurse)(recur)f:(file)(filename)q', [] : string[]);
        this.expect(parser.getopt()).toBe(null);
    }

    function test_extra_options () : void
    {
        var parser = new BasicParser('la:r(recurse)(recur)f:(file)(filename)q', ['extra1', 'extra2']);
        this.expect(parser.getopt().option).toBe('extra1');
        this.expect(parser.getopt().option).toBe('extra2');
        this.expect(parser.getopt()).toBe(null);
    }
}