Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: third_party/WebKit/Source/bindings/scripts/idl_types_test.py

Issue 2746713003: bindings: Add support for nested union types (Closed)
Patch Set: Improve documentation Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/scripts/idl_types_test.py
diff --git a/third_party/WebKit/Source/bindings/scripts/idl_types_test.py b/third_party/WebKit/Source/bindings/scripts/idl_types_test.py
index 931c465461a159b0a8571fa7abab0b4ec603f990..c92fb42fd915363358571764fa516f780afddaee 100644
--- a/third_party/WebKit/Source/bindings/scripts/idl_types_test.py
+++ b/third_party/WebKit/Source/bindings/scripts/idl_types_test.py
@@ -8,9 +8,11 @@
import unittest
+from idl_types import IdlNullableType
from idl_types import IdlRecordType
from idl_types import IdlSequenceType
from idl_types import IdlType
+from idl_types import IdlUnionType
class IdlTypeTest(unittest.TestCase):
@@ -76,3 +78,61 @@ class IdlRecordTypeTest(unittest.TestCase):
IdlRecordType(IdlType('ByteString'),
IdlSequenceType(IdlType('unsigned short'))))
self.assertEqual(idl_type.name, 'StringByteStringUnsignedShortSequenceRecordRecord')
+
+
+class IdlUnionTypeTest(unittest.TestCase):
+
+ def test_flattened_member_types(self):
+ # We are only testing the algorithm here, so we do create some ambiguous union types.
+
+ def compare_flattened_members(actual, expected):
+ """Compare a set of IDL types by name, as the objects are different"""
+ actual_names = set([member.name for member in actual])
+ expected_names = set([member.name for member in expected])
+ self.assertEqual(actual_names, expected_names)
+
+ idl_type = IdlUnionType([IdlType('long'), IdlType('SomeInterface')])
+ compare_flattened_members(
+ idl_type.flattened_member_types,
+ set([IdlType('long'), IdlType('SomeInterface')]))
+
+ idl_type = IdlUnionType([IdlUnionType([IdlType('ByteString'), IdlType('float')]),
+ IdlType('boolean')])
+ compare_flattened_members(
+ idl_type.flattened_member_types,
+ set([IdlType('float'), IdlType('boolean'), IdlType('ByteString')]))
+
+ idl_type = IdlUnionType([IdlUnionType([IdlType('ByteString'), IdlType('DOMString')]),
+ IdlType('DOMString')])
+ compare_flattened_members(
+ idl_type.flattened_member_types,
+ set([IdlType('DOMString'), IdlType('ByteString')]))
+
+ idl_type = IdlUnionType(
+ [IdlNullableType(IdlType('ByteString')), IdlType('byte')])
+ compare_flattened_members(
+ idl_type.flattened_member_types,
+ set([IdlType('ByteString'), IdlType('byte')]))
+
+ idl_type = IdlUnionType(
+ [IdlNullableType(IdlType('ByteString')), IdlType('byte'),
+ IdlUnionType([IdlType('ByteString'), IdlType('float')])])
+ self.assertEqual(len(idl_type.flattened_member_types), 3)
+ compare_flattened_members(
+ idl_type.flattened_member_types,
+ set([IdlType('ByteString'), IdlType('byte'), IdlType('float')]))
+
+ # From the example in the spec: "the flattened member types of the union type (Node or (sequence<long> or Event) or
+ # (XMLHttpRequest or DOMString)? or sequence<(sequence<double> or NodeList)>) are the six types Node, sequence<long>,
+ # Event, XMLHttpRequest, DOMString and sequence<(sequence<double> or NodeList)>"
+ idl_type = IdlUnionType(
+ [IdlType('Node'),
+ IdlUnionType([IdlSequenceType(IdlType('long')), IdlType('Event')]),
+ IdlNullableType(IdlUnionType([IdlType('XMLHttpRequest'), IdlType('DOMString')])),
+ IdlSequenceType(IdlUnionType([IdlSequenceType(IdlType('double')), IdlType('NodeList')]))])
+ self.assertEqual(len(idl_type.flattened_member_types), 6)
+ compare_flattened_members(
+ idl_type.flattened_member_types,
+ set([IdlType('Node'), IdlSequenceType(IdlType('long')), IdlType('Event'),
+ IdlType('XMLHttpRequest'), IdlType('DOMString'),
+ IdlSequenceType(IdlUnionType([IdlSequenceType(IdlType('double')), IdlType('NodeList')]))]))
« no previous file with comments | « third_party/WebKit/Source/bindings/scripts/idl_types.py ('k') | third_party/WebKit/Source/bindings/scripts/v8_union.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698