dom/bindings/parser/tests/test_extended_attributes.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/parser/tests/test_extended_attributes.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +import WebIDL
     1.5 +
     1.6 +def WebIDLTest(parser, harness):
     1.7 +    parser.parse("""
     1.8 +        [NoInterfaceObject]
     1.9 +        interface TestExtendedAttr {
    1.10 +          [Unforgeable] readonly attribute byte b;
    1.11 +        };
    1.12 +    """)
    1.13 +
    1.14 +    results = parser.finish()
    1.15 +
    1.16 +    parser = parser.reset()
    1.17 +    parser.parse("""
    1.18 +        [Pref="foo.bar",Pref=flop]
    1.19 +        interface TestExtendedAttr {
    1.20 +          [Pref="foo.bar"] attribute byte b;
    1.21 +        };
    1.22 +    """)
    1.23 +
    1.24 +    results = parser.finish()
    1.25 +
    1.26 +    parser = parser.reset()
    1.27 +    parser.parse("""
    1.28 +        interface TestLenientThis {
    1.29 +          [LenientThis] attribute byte b;
    1.30 +        };
    1.31 +    """)
    1.32 +
    1.33 +    results = parser.finish()
    1.34 +    harness.ok(results[0].members[0].hasLenientThis(),
    1.35 +               "Should have a lenient this")
    1.36 +
    1.37 +    parser = parser.reset()
    1.38 +    threw = False
    1.39 +    try:
    1.40 +        parser.parse("""
    1.41 +            interface TestLenientThis2 {
    1.42 +              [LenientThis=something] attribute byte b;
    1.43 +            };
    1.44 +        """)
    1.45 +        results = parser.finish()
    1.46 +    except:
    1.47 +        threw = True
    1.48 +
    1.49 +    harness.ok(threw, "[LenientThis] must take no arguments")
    1.50 +
    1.51 +    parser = parser.reset()
    1.52 +    parser.parse("""
    1.53 +        interface TestClamp {
    1.54 +          void testClamp([Clamp] long foo);
    1.55 +          void testNotClamp(long foo);
    1.56 +        };
    1.57 +    """)
    1.58 +
    1.59 +    results = parser.finish()
    1.60 +    # Pull out the first argument out of the arglist of the first (and
    1.61 +    # only) signature.
    1.62 +    harness.ok(results[0].members[0].signatures()[0][1][0].clamp,
    1.63 +               "Should be clamped")
    1.64 +    harness.ok(not results[0].members[1].signatures()[0][1][0].clamp,
    1.65 +               "Should not be clamped")
    1.66 +
    1.67 +    parser = parser.reset()
    1.68 +    threw = False
    1.69 +    try:
    1.70 +        parser.parse("""
    1.71 +            interface TestClamp2 {
    1.72 +              void testClamp([Clamp=something] long foo);
    1.73 +            };
    1.74 +        """)
    1.75 +        results = parser.finish()
    1.76 +    except:
    1.77 +        threw = True
    1.78 +
    1.79 +    harness.ok(threw, "[Clamp] must take no arguments")
    1.80 +
    1.81 +    parser = parser.reset()
    1.82 +    parser.parse("""
    1.83 +        interface TestEnforceRange {
    1.84 +          void testEnforceRange([EnforceRange] long foo);
    1.85 +          void testNotEnforceRange(long foo);
    1.86 +        };
    1.87 +    """)
    1.88 +
    1.89 +    results = parser.finish()
    1.90 +    # Pull out the first argument out of the arglist of the first (and
    1.91 +    # only) signature.
    1.92 +    harness.ok(results[0].members[0].signatures()[0][1][0].enforceRange,
    1.93 +               "Should be enforceRange")
    1.94 +    harness.ok(not results[0].members[1].signatures()[0][1][0].enforceRange,
    1.95 +               "Should not be enforceRange")
    1.96 +
    1.97 +    parser = parser.reset()
    1.98 +    threw = False
    1.99 +    try:
   1.100 +        parser.parse("""
   1.101 +            interface TestEnforceRange2 {
   1.102 +              void testEnforceRange([EnforceRange=something] long foo);
   1.103 +            };
   1.104 +        """)
   1.105 +        results = parser.finish()
   1.106 +    except:
   1.107 +        threw = True
   1.108 +
   1.109 +    harness.ok(threw, "[EnforceRange] must take no arguments")
   1.110 +    

mercurial