Exemplo n.º 1
0
        public void XliffElement_CollapseChildren()
        {
            List <PlainText>             textList;
            List <ResourceStringContent> tagList;
            List <Source>       sourceList;
            List <Target>       targetList;
            List <XliffElement> elementList;
            PlainText           text;
            Segment             segment;
            StandaloneCode      code;
            Unit          unit;
            XliffDocument document;

            code           = new StandaloneCode();
            text           = new PlainText();
            segment        = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            elementList = document.CollapseChildren <XliffElement>();
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            sourceList = document.CollapseChildren <Source>();
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            tagList = document.CollapseChildren <ResourceStringContent>();
            Assert.AreEqual(2, tagList.Count, "Element count is incorrect.");
            Assert.IsTrue(tagList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(tagList.Contains(text), "PlainText not found in list");

            targetList = document.CollapseChildren <Target>();
            Assert.AreEqual(0, targetList.Count, "Element count is incorrect.");

            textList = document.CollapseChildren <PlainText>();
            Assert.AreEqual(1, textList.Count, "Element count is incorrect.");
            Assert.IsTrue(textList.Contains(text), "PlainText not found in list");
        }
Exemplo n.º 2
0
        public static void WhiteSpaces()
        {
            string data = "<xliff srcLang='en' version='2.0' xmlns='urn:oasis:names:tc:xliff:document:2.0'>"
                          + "<file id='f1'><unit id='u1'>"
                          + "<segment><source>Sentence 1.</source></segment>"
                          + "<ignorable><source> </source></ignorable>"
                          + "<segment><source>Sentence 2.</source></segment>"
                          + "</unit></file></xliff>";

            using (IO.MemoryStream ms = new IO.MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                XliffReader   reader = new XliffReader();
                XliffDocument doc    = reader.Deserialize(ms);
                foreach (XliffElement e in doc.CollapseChildren <XliffElement>())
                {
                    Console.WriteLine("Type: " + e.GetType().ToString());
                    if (e is PlainText)
                    {
                        PlainText pt = (PlainText)e;
                        Console.WriteLine("Content: '" + pt.Text + "'");
                    }
                }
            }
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public XliffDocument ExecuteExtraction(XliffDocument document)
        {
            var units = document.CollapseChildren <Unit>();

            foreach (var unit in units)
            {
                var originalData = new OriginalData();
                foreach (var resource in unit.Resources)
                {
                    var segment = resource as Segment;
                    if (segment != null)
                    {
                        var cdata = segment.Source.Text[0] as CDataTag;
                        if (cdata == null)
                        {
                            continue;
                        }
                        var html = cdata.Text;
                        var inlineCodeExtraction = html.ConvertHtmlTagsInInLineCodes();
                        foreach (var data in inlineCodeExtraction.OriginalData)
                        {
                            originalData.AddData(data.Value, data.Key);
                        }
                        segment.Source.Text.Clear();
                        segment.Source.Text.AddAll(inlineCodeExtraction.Text);
                    }
                }
                if (originalData.HasData)
                {
                    unit.OriginalData = originalData;
                }
            }
            return(document);
        }
Exemplo n.º 4
0
        public XliffDocument ExecuteExtraction(XliffDocument document)
        {
            var units = document.CollapseChildren <Unit>();

            foreach (var unit in units)
            {
                SplitUnitAndIterate(unit);
            }

            return(document);
        }
Exemplo n.º 5
0
        public XliffDocument ExecuteMerge(XliffDocument document)
        {
            var groups = document.CollapseChildren <Group>().Where(g => g.Id.StartsWith("u") && g.Id.Split('-').Length == 2);

            foreach (var group in groups)
            {
                var unitId  = group.Id.Replace("-g", "");
                var newUnit = new Unit(unitId);
                newUnit.Name = group.Name;

                if (group.Metadata != null)
                {
                    var newMetadataContainer = new MetadataContainer();
                    foreach (var metaGroup in group.Metadata.Groups)
                    {
                        var newMetaGroup = new MetaGroup();
                        newMetaGroup.Id = metaGroup.Id;

                        foreach (Meta item in metaGroup.Containers)
                        {
                            var newElement = new Meta(item.Type, item.NonTranslatableText);
                            newMetaGroup.Containers.Add(newElement);
                        }

                        newMetadataContainer.Groups.Add(newMetaGroup);
                    }
                    newUnit.Metadata = newMetadataContainer;
                }

                var newSegment = new Segment();

                newSegment.Source = SetSourceValue(group);
                newSegment.Target = SetTargetValue(group);
                newUnit.Resources.Add(newSegment);

                var parentFile = group.Parent as File;
                if (parentFile != null)
                {
                    parentFile.Containers.Add(newUnit);
                    parentFile.Containers.Remove(group);
                }
                else
                {
                    var parentGroup = group.Parent as Group;
                    if (parentGroup != null)
                    {
                        parentGroup.Containers.Add(newUnit);
                        parentGroup.Containers.Remove(group);
                    }
                }
            }
            return(document);
        }
Exemplo n.º 6
0
        public XliffDocument ExecuteMerge(XliffDocument document)
        {
            var units = document.CollapseChildren <Unit>();

            foreach (var unit in units)
            {
                foreach (var resource in unit.Resources)
                {
                    var segment = resource as Segment;
                    if (segment != null)
                    {
                        ConvertToHtmlAndStore(segment.Source);
                        ConvertToHtmlAndStore(segment.Target);
                    }
                }
            }
            return(document);
        }
Exemplo n.º 7
0
        public XliffDocument ExecuteExtraction(XliffDocument document)
        {
            var units = document.CollapseChildren <Unit>();

            foreach (var unit in units)
            {
                var originalData = new OriginalData();
                var subflows     = new Dictionary <string, string>();
                foreach (var resource in unit.Resources)
                {
                    var segment = resource as Segment;
                    if (segment != null)
                    {
                        var cdata = segment.Source.Text[0] as CDataTag;
                        if (cdata == null)
                        {
                            continue;
                        }
                        var html = cdata.Text;
                        var inlineCodeExtraction = html.ConvertHtmlTagsInInLineCodes(unit.Id + "-");
                        foreach (var data in inlineCodeExtraction.OriginalData)
                        {
                            originalData.AddData(data.Value, data.Key);
                        }
                        segment.Source.Text.Clear();
                        segment.Source.Text.AddAll(inlineCodeExtraction.Text);
                        if (inlineCodeExtraction.SubFlow.Count > 0)
                        {
                            subflows = inlineCodeExtraction.SubFlow;
                        }
                    }
                }
                if (originalData.HasData)
                {
                    unit.OriginalData = originalData;
                }
                if (subflows.Count > 0)
                {
                    var newGroup = new Group(unit.Id + "-g");
                    newGroup.Type = unit.Type;
                    newGroup.Name = unit.Name;
                    unit.Type     = null;

                    if (unit.Metadata != null)
                    {
                        var newMetadataContainer = new MetadataContainer();
                        foreach (var metaGroup in unit.Metadata.Groups)
                        {
                            var newMetaGroup = new MetaGroup();
                            newMetaGroup.Id = metaGroup.Id;

                            foreach (Meta item in metaGroup.Containers)
                            {
                                var newElement = new Meta(item.Type, item.NonTranslatableText);
                                newMetaGroup.Containers.Add(newElement);
                            }
                            newMetadataContainer.Groups.Add(newMetaGroup);
                        }
                        newGroup.Metadata = newMetadataContainer;
                        unit.Metadata     = null;
                    }


                    foreach (var subflowItem in subflows)
                    {
                        var subFlowUnit = new Unit(subflowItem.Key);
                        var newSegment  = new Segment();
                        var source      = new Source();
                        var content     = new PlainText(subflowItem.Value);
                        source.Text.Add(content);
                        newSegment.Source = source;
                        subFlowUnit.Resources.Add(newSegment);
                        newGroup.Containers.Add(subFlowUnit);
                    }

                    var parentFile = unit.Parent as File;
                    if (parentFile != null)
                    {
                        var index = parentFile.Containers.IndexOf(unit);
                        parentFile.Containers[index] = newGroup;
                    }
                    else
                    {
                        var parentGroup = unit.Parent as Group;
                        if (parentGroup != null)
                        {
                            var index = parentGroup.Containers.IndexOf(unit);
                            parentGroup.Containers[index] = newGroup;
                        }
                    }
                    newGroup.Containers.Add(unit);
                }
            }
            return(document);
        }
Exemplo n.º 8
0
        public XliffDocument ExecuteMerge(XliffDocument document)
        {
            var units = document.CollapseChildren <Unit>();

            foreach (var unit in units)
            {
                if (unit.Resources.Count > 1)
                {
                    throw new InvalidOperationException("At this stage I expect only one segment. This unit is invalid: " + unit.SelectorPath);
                }

                Segment segment = unit.Resources[0] as Segment;

                if (segment != null)
                {
                    var hasSubFlow = segment.Source.Text.HasSubFlow() || segment.Target.Text.HasSubFlow();

                    ConvertToHtmlAndStore(segment.Source, subflows => SearchSubflowsInDocument(subflows, units, s => s.Source));
                    ConvertToHtmlAndStore(segment.Target, subflows => SearchSubflowsInDocument(subflows, units, s => s.Target));


                    if (hasSubFlow)
                    {
                        var group   = unit.Parent as Group;
                        var newUnit = new Unit(unit.Id);
                        newUnit.Name = group.Name;
                        newUnit.Type = group.Type;

                        if (group.Metadata != null)
                        {
                            var newMetadataContainer = new MetadataContainer();
                            foreach (var metaGroup in group.Metadata.Groups)
                            {
                                var newMetaGroup = new MetaGroup();
                                newMetaGroup.Id = metaGroup.Id;

                                foreach (Meta item in metaGroup.Containers)
                                {
                                    var newElement = new Meta(item.Type, item.NonTranslatableText);
                                    newMetaGroup.Containers.Add(newElement);
                                }

                                newMetadataContainer.Groups.Add(newMetaGroup);
                            }
                            newUnit.Metadata = newMetadataContainer;
                        }

                        var newSegment = unit.Resources[0];
                        unit.Resources.Clear();
                        newUnit.Resources.Add(newSegment);

                        var parentFile = group.Parent as File;
                        if (parentFile != null)
                        {
                            var pos = parentFile.Containers.IndexOf(group);
                            parentFile.Containers.Insert(pos, newUnit);
                            parentFile.Containers.Remove(group);
                        }
                        else
                        {
                            var parentGroup = group.Parent as Group;
                            if (parentGroup != null)
                            {
                                var pos = parentGroup.Containers.IndexOf(group);
                                parentGroup.Containers.Insert(pos, newUnit);
                                parentGroup.Containers.Remove(group);
                            }
                        }
                    }
                }
            }
            return(document);
        }
        public void XliffElement_CollapseChildren()
        {
            List<PlainText> textList;
            List<ResourceStringContent> tagList;
            List<Source> sourceList;
            List<Target> targetList;
            List<XliffElement> elementList;
            PlainText text;
            Segment segment;
            StandaloneCode code;
            Unit unit;
            XliffDocument document;

            code = new StandaloneCode();
            text = new PlainText();
            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            elementList = document.CollapseChildren<XliffElement>();
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            sourceList = document.CollapseChildren<Source>();
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            tagList = document.CollapseChildren<ResourceStringContent>();
            Assert.AreEqual(2, tagList.Count, "Element count is incorrect.");
            Assert.IsTrue(tagList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(tagList.Contains(text), "PlainText not found in list");

            targetList = document.CollapseChildren<Target>();
            Assert.AreEqual(0, targetList.Count, "Element count is incorrect.");

            textList = document.CollapseChildren<PlainText>();
            Assert.AreEqual(1, textList.Count, "Element count is incorrect.");
            Assert.IsTrue(textList.Contains(text), "PlainText not found in list");
        }
        public void XliffElement_CollapseChildrenWithScope()
        {
            IExtensible extensible;
            CustomExtension extension1;
            CustomExtension extension2;
            CustomElement1 element1;
            CustomElement2 element2;
            List<XliffElement> elementList;
            List<Source> sourceList;
            PlainText text;
            Segment segment;
            Source source;
            StandaloneCode code;
            Unit unit;
            XliffDocument document;

            code = new StandaloneCode();
            text = new PlainText();
            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            extensible = document.Files[0];

            extension1 = new CustomExtension("namespace");
            element1 = new CustomElement1("pre1", "namespace");
            extension1.AddChild(new ElementInfo(new XmlNameInfo("localname"), element1));
            extensible.Extensions.Add(extension1);

            extension2 = new CustomExtension("namespace");
            element2 = new CustomElement2("pre1", "namespace");
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), element2));
            source = new Source();
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), source));
            extensible.Extensions.Add(extension2);

            Console.WriteLine("Test with none.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.None);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            Console.WriteLine("Test with current element.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.CurrentElement);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");

            Console.WriteLine("Test with default.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Default);
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            Console.WriteLine("Test with default with current element.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Default | CollapseScope.CurrentElement);
            Assert.AreEqual(7, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(9, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren<Source>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.All);
            Assert.AreEqual(10, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren<Source>(CollapseScope.All);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            Console.WriteLine("Test with extensions with core elements for Source.");
            sourceList = document.CollapseChildren<Source>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            Console.WriteLine("Test with extensions without core elements.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(3, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.TopLevelDescendants);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.TopLevelDescendants | CollapseScope.CoreElements);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
        }
Exemplo n.º 11
0
        public XliffDocument ExecuteExtraction(XliffDocument document)
        {
            var units = document.CollapseChildren <Unit>();

            foreach (var unit in units)
            {
                foreach (var resource in unit.Resources)
                {
                    var segment = resource as Segment;
                    if (segment != null)
                    {
                        var cdata = segment.Source.Text[0] as CDataTag;
                        if (cdata == null)
                        {
                            continue;
                        }
                        var html       = cdata.Text;
                        var paragraphs = html.SplitByParagraphs();
                        if (paragraphs.Count() > 1)
                        {
                            //TODO: Copy name and other attributes
                            var newGroup = new Group(unit.Id + "-g");
                            newGroup.Name = unit.Name;
                            if (unit.Metadata != null)
                            {
                                var newMetadataContainer = new MetadataContainer();
                                foreach (var metaGroup in unit.Metadata.Groups)
                                {
                                    var newMetaGroup = new MetaGroup();
                                    newMetaGroup.Id = metaGroup.Id;

                                    foreach (Meta item in metaGroup.Containers)
                                    {
                                        var newElement = new Meta(item.Type, item.NonTranslatableText);
                                        newMetaGroup.Containers.Add(newElement);
                                    }

                                    newMetadataContainer.Groups.Add(newMetaGroup);
                                }

                                newGroup.Metadata = newMetadataContainer;
                            }

                            var i = 0;
                            foreach (var para in paragraphs)
                            {
                                i++;
                                var paraUnit = new Unit(unit.Id + "-" + i);

                                var newSegment = new Segment();

                                var source = new Source();
                                source.Text.Add(new CDataTag(para));
                                newSegment.Source = source;

                                paraUnit.Resources.Add(newSegment);

                                newGroup.Containers.Add(paraUnit);
                            }

                            var parentFile = unit.Parent as File;
                            if (parentFile != null)
                            {
                                parentFile.Containers.Add(newGroup);
                                parentFile.Containers.Remove(unit);
                            }
                            else
                            {
                                var parentGroup = unit.Parent as Group;
                                if (parentGroup != null)
                                {
                                    parentGroup.Containers.Add(newGroup);
                                    parentGroup.Containers.Remove(unit);
                                }
                            }
                        }
                    }
                }
            }

            return(document);
        }
Exemplo n.º 12
0
        public void XliffElement_CollapseChildrenWithScope()
        {
            IExtensible         extensible;
            CustomExtension     extension1;
            CustomExtension     extension2;
            CustomElement1      element1;
            CustomElement2      element2;
            List <XliffElement> elementList;
            List <Source>       sourceList;
            PlainText           text;
            Segment             segment;
            Source         source;
            StandaloneCode code;
            Unit           unit;
            XliffDocument  document;

            code           = new StandaloneCode();
            text           = new PlainText();
            segment        = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            extensible = document.Files[0];

            extension1 = new CustomExtension("namespace");
            element1   = new CustomElement1("pre1", "namespace");
            extension1.AddChild(new ElementInfo(new XmlNameInfo("localname"), element1));
            extensible.Extensions.Add(extension1);

            extension2 = new CustomExtension("namespace");
            element2   = new CustomElement2("pre1", "namespace");
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), element2));
            source = new Source();
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), source));
            extensible.Extensions.Add(extension2);

            Console.WriteLine("Test with none.");
            elementList = document.CollapseChildren <XliffElement>(CollapseScope.None);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            Console.WriteLine("Test with current element.");
            elementList = document.CollapseChildren <XliffElement>(CollapseScope.CurrentElement);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");

            Console.WriteLine("Test with default.");
            elementList = document.CollapseChildren <XliffElement>(CollapseScope.Default);
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            Console.WriteLine("Test with default with current element.");
            elementList = document.CollapseChildren <XliffElement>(CollapseScope.Default | CollapseScope.CurrentElement);
            Assert.AreEqual(7, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            elementList = document.CollapseChildren <XliffElement>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(9, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren <Source>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren <XliffElement>(CollapseScope.All);
            Assert.AreEqual(10, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren <Source>(CollapseScope.All);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            Console.WriteLine("Test with extensions with core elements for Source.");
            sourceList = document.CollapseChildren <Source>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            Console.WriteLine("Test with extensions without core elements.");
            elementList = document.CollapseChildren <XliffElement>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(3, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren <XliffElement>(CollapseScope.TopLevelDescendants);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            elementList = document.CollapseChildren <XliffElement>(CollapseScope.TopLevelDescendants | CollapseScope.CoreElements);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
        }