<commit_before>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using CoreXml.Test.XLinq;
using Microsoft.Test.ModuleCore;

namespace XLinqTests
{
    public class AddNodeAfter : AddNodeBeforeAfterBase
    {
        // Type is CoreXml.Test.XLinq.FunctionalTests+TreeManipulationTests+AddNodeAfter
        // Test Case

        #region Public Methods and Operators

        public override void AddChildren()
        {
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding multiple (4) objects into XElement - connected") { Params = new object[] { true, 4 }, Priority = 1 } });
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding single object into XElement - not connected") { Params = new object[] { false, 1 }, Priority = 1 } });
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding multiple (4) objects into XElement - not connected") { Params = new object[] { false, 4 }, Priority = 1 } });
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding single object into XElement - connected") { Params = new object[] { true, 1 }, Priority = 1 } });
            AddChild(new TestVariation(InvalidNodeTypes) { Attribute = new VariationAttribute("Invalid node types - single object") { Priority = 2 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - not connected (multiple)") { Params = new object[] { false, 3 }, Priority = 1 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - connected (single)") { Params = new object[] { true, 1 }, Priority = 0 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - not connected (single)") { Params = new object[] { false, 1 }, Priority = 0 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - connected (multiple)") { Params = new object[] { true, 3 }, Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument1) { Attribute = new VariationAttribute("XDocument invalid add - double DTD") { Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument2) { Attribute = new VariationAttribute("XDocument invalid add - DTD after element") { Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument4) { Attribute = new VariationAttribute("XDocument invalid add - multiple root elements") { Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument5) { Attribute = new VariationAttribute("XDocument invalid add - CData, attribute, text (no whitespace)") { Priority = 1 } });
            AddChild(new TestVariation(WorkOnTextNodes1) { Attribute = new VariationAttribute("Working on the text nodes 1.") { Priority = 1 } });
            AddChild(new TestVariation(WorkOnTextNodes2) { Attribute = new VariationAttribute("Working on the text nodes 2.") { Priority = 1 } });
        }

        // - order
        // - parent, document property
        // - query
        // - value
        // - assigning/cloning nodes (connected, not connected)
        // ----

        // add valid:
        //  - first, in the middle, last
        //  - elem, text/XText (concatenation), PI, Comment - for XE
        //  - elem (just root), PI, Comment, XDecl/XDocType (order!)
        //  - on other node types
        //[Variation(Priority = 1, Desc = "Adding multiple (4) objects into XElement - not connected", Params = new object[] { false, 4 })]
        //[Variation(Priority = 1, Desc = "Adding multiple (4) objects into XElement - connected", Params = new object[] { true, 4 })]
        //[Variation(Priority = 1, Desc = "Adding single object into XElement - not connected", Params = new object[] { false, 1 })]
        //[Variation(Priority = 1, Desc = "Adding single object into XElement - connected", Params = new object[] { true, 1 })]

        public void AddingMultipleNodesIntoElement()
        {
            AddingMultipleNodesIntoElement(delegate(XNode n, object[] content) { n.AddAfterSelf(content); }, CalculateExpectedValuesAddAfter);
        }

        public IEnumerable<ExpectedValue> CalculateExpectedValuesAddAfter(XContainer orig, int startPos, IEnumerable<object> newNodes)
        {
            int counter = 0;
            for (XNode node = orig.FirstNode; node != null; node = node.NextNode, counter++)
            {
                yield return new ExpectedValue(!(node is XText), node); // Don't build on the text node identity
                if (counter == startPos)
                {
                    foreach (object o in newNodes)
                    {
                        yield return new ExpectedValue(o is XNode && (o as XNode).Parent == null && (o as XNode).Document == null, o);
                    }
                }
            }
        }

        //[Variation(Priority = 2, Desc = "Invalid node types - single object")]

        // XDocument constraints:
        // - only one DTD, DTD is first (before elem)
        // - only one root element
        // - no CDATA,
        // - no Attribute
        // - no no text (except whitespace)

        //[Variation(Priority = 1, Desc = "XDocument invalid add - double DTD")]
        public void InvalidAddIntoXDocument1()<commit_msg>typo: Double word "no" (#36299)<commit_after>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using CoreXml.Test.XLinq;
using Microsoft.Test.ModuleCore;

namespace XLinqTests
{
    public class AddNodeAfter : AddNodeBeforeAfterBase
    {
        // Type is CoreXml.Test.XLinq.FunctionalTests+TreeManipulationTests+AddNodeAfter
        // Test Case

        #region Public Methods and Operators

        public override void AddChildren()
        {
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding multiple (4) objects into XElement - connected") { Params = new object[] { true, 4 }, Priority = 1 } });
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding single object into XElement - not connected") { Params = new object[] { false, 1 }, Priority = 1 } });
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding multiple (4) objects into XElement - not connected") { Params = new object[] { false, 4 }, Priority = 1 } });
            AddChild(new TestVariation(AddingMultipleNodesIntoElement) { Attribute = new VariationAttribute("Adding single object into XElement - connected") { Params = new object[] { true, 1 }, Priority = 1 } });
            AddChild(new TestVariation(InvalidNodeTypes) { Attribute = new VariationAttribute("Invalid node types - single object") { Priority = 2 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - not connected (multiple)") { Params = new object[] { false, 3 }, Priority = 1 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - connected (single)") { Params = new object[] { true, 1 }, Priority = 0 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - not connected (single)") { Params = new object[] { false, 1 }, Priority = 0 } });
            AddChild(new TestVariation(ValidAddIntoXDocument) { Attribute = new VariationAttribute("XDocument valid add - connected (multiple)") { Params = new object[] { true, 3 }, Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument1) { Attribute = new VariationAttribute("XDocument invalid add - double DTD") { Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument2) { Attribute = new VariationAttribute("XDocument invalid add - DTD after element") { Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument4) { Attribute = new VariationAttribute("XDocument invalid add - multiple root elements") { Priority = 1 } });
            AddChild(new TestVariation(InvalidAddIntoXDocument5) { Attribute = new VariationAttribute("XDocument invalid add - CData, attribute, text (no whitespace)") { Priority = 1 } });
            AddChild(new TestVariation(WorkOnTextNodes1) { Attribute = new VariationAttribute("Working on the text nodes 1.") { Priority = 1 } });
            AddChild(new TestVariation(WorkOnTextNodes2) { Attribute = new VariationAttribute("Working on the text nodes 2.") { Priority = 1 } });
        }

        // - order
        // - parent, document property
        // - query
        // - value
        // - assigning/cloning nodes (connected, not connected)
        // ----

        // add valid:
        //  - first, in the middle, last
        //  - elem, text/XText (concatenation), PI, Comment - for XE
        //  - elem (just root), PI, Comment, XDecl/XDocType (order!)
        //  - on other node types
        //[Variation(Priority = 1, Desc = "Adding multiple (4) objects into XElement - not connected", Params = new object[] { false, 4 })]
        //[Variation(Priority = 1, Desc = "Adding multiple (4) objects into XElement - connected", Params = new object[] { true, 4 })]
        //[Variation(Priority = 1, Desc = "Adding single object into XElement - not connected", Params = new object[] { false, 1 })]
        //[Variation(Priority = 1, Desc = "Adding single object into XElement - connected", Params = new object[] { true, 1 })]

        public void AddingMultipleNodesIntoElement()
        {
            AddingMultipleNodesIntoElement(delegate(XNode n, object[] content) { n.AddAfterSelf(content); }, CalculateExpectedValuesAddAfter);
        }

        public IEnumerable<ExpectedValue> CalculateExpectedValuesAddAfter(XContainer orig, int startPos, IEnumerable<object> newNodes)
        {
            int counter = 0;
            for (XNode node = orig.FirstNode; node != null; node = node.NextNode, counter++)
            {
                yield return new ExpectedValue(!(node is XText), node); // Don't build on the text node identity
                if (counter == startPos)
                {
                    foreach (object o in newNodes)
                    {
                        yield return new ExpectedValue(o is XNode && (o as XNode).Parent == null && (o as XNode).Document == null, o);
                    }
                }
            }
        }

        //[Variation(Priority = 2, Desc = "Invalid node types - single object")]

        // XDocument constraints:
        // - only one DTD, DTD is first (before elem)
        // - only one root element
        // - no CDATA,
        // - no Attribute
        // - no text (except whitespace)

        //[Variation(Priority = 1, Desc = "XDocument invalid add - double DTD")]
        public void InvalidAddIntoXDocument1()
{'fraction_non_alphanumeric': 0.10857093929274766, 'fraction_numerical': 0.008476753146673517, 'mean_word_length': 2.8020833333333335, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5451831', 'n_tokens_mistral': 3119, 'n_tokens_neox': 2955, 'n_words': 986}