Esempio n. 1
0
        public void TrimTest()
        {
            const string a1 = "2014-09-11 16:36:07,184 INFO [30] myclassname - [d9b4b140-71a4-44ff-9fdd-dcdfd2757191] [<?xml version=\"1.0\" encoding=\"UTF-8\"?><Request RequestId=\"Transfer\" Version=\"1\" MsgId=\"6\"><Customer><Field Type=\"Id\">1</Field><Field Type=\"LocationId\">Home</Field><Field Type=\"LastName\">Duck</Field><Field Type=\"CustomerType\">Adult</Field></Customer><Record Id=\"2B075C23-0E85-E232-E14A-48D9EFC888B0\" PrtId=\"7EC25208-88A2-4B46-A813-71A61EBD04EC\" State=\"Valid\" CreationDateTime=\"20140911164711+1200\"><Parameter Type=\"Numeric\" Code=\"0002-4a04\" Label=\"Count\" IsManual=\"0\" CreationDateTime=\"20140911164630+1200\"></Parameter></Record></Request>]";
            const string e1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Request RequestId=\"Transfer\" Version=\"1\" MsgId=\"6\"><Customer><Field Type=\"Id\">1</Field><Field Type=\"LocationId\">Home</Field><Field Type=\"LastName\">Duck</Field><Field Type=\"CustomerType\">Adult</Field></Customer><Record Id=\"2B075C23-0E85-E232-E14A-48D9EFC888B0\" PrtId=\"7EC25208-88A2-4B46-A813-71A61EBD04EC\" State=\"Valid\" CreationDateTime=\"20140911164711+1200\"><Parameter Type=\"Numeric\" Code=\"0002-4a04\" Label=\"Count\" IsManual=\"0\" CreationDateTime=\"20140911164630+1200\"></Parameter></Record></Request>";

            Assert.AreEqual(e1, XParser.Trim(a1));

            Assert.AreEqual("<hallo/>", XParser.Trim("<hallo/>"));

            try
            {
                Assert.AreEqual("<", XParser.Trim("<"));
            }
            catch (Exception e)
            {
                Assert.AreEqual("No XML found", e.Message);
            }

            try
            {
                XParser.Trim("xxx");
            }
            catch (Exception e)
            {
                Assert.AreEqual("No XML found", e.Message);
            }
        }
Esempio n. 2
0
        public void GetParentElementAtCursorTest4()
        {
            const string x3 = @"<A><files><file></file><file></file></files></A>";
            string       s4 = XParser.GetParentElementAtCursor(x3, 23);

            Assert.AreEqual("files", s4);
        }
Esempio n. 3
0
 public void IsInsideAttributeValueTest()
 {
     Assert.AreEqual(false, XParser.IsInsideAttributeValue(@"<ActivationResponse><</ActivationResponse>", 5));
     Assert.AreEqual(false, XParser.IsInsideAttributeValue(@"<hallo abcd=""xxx""></hallo>", 3));
     Assert.AreEqual(false, XParser.IsInsideAttributeValue(@"<hallo abcd=""xxx""></hallo>", 9));
     Assert.AreEqual(true, XParser.IsInsideAttributeValue(@"<hallo abcd=""xxx""></hallo>", 15));
 }
Esempio n. 4
0
        public static Entity2D Parse(XElement xe)
        {
            switch (xe.Name.LocalName)
            {
            case "Line":
                return(XParser.Parse <LineSegment2D>(xe));

            case "CircleArc":
                return(XParser.Parse <CircleArc2D>(xe));

            case "Ellipse":
                return(XParser.Parse <Ellipse2D>(xe));

            case "Text":
                return(XParser.Parse <Text2D>(xe));

            case "PolyLine":
                return(XParser.Parse <PolyLine2D>(xe));

            case "Spline":
                return(XParser.Parse <Spline2D>(xe));

            default:
                return(null);
            }
        }
Esempio n. 5
0
        public void GetParentElementAtCursorTest3()
        {
            const string x3 = @"<ActivationResponse><</ActivationResponse>";
            string       s4 = XParser.GetParentElementAtCursor(x3, 21);

            Assert.AreEqual("ActivationResponse", s4);
        }
Esempio n. 6
0
        public PartFolder(DirectoryInfo dir, Func <string, FileInfo, ImagePart> makeOtherFile)
        {
            Name = dir.Name;
            foreach (var subdir in dir.GetDirectories())
            {
                Add(new PartFolder(subdir, makeOtherFile));
            }
            foreach (var file in dir.GetFiles())
            {
                var       ext = file.Extension.ToLower();
                ImagePart part;
                switch (ext)
                {
                case ".px":
                    var xe = XElement.Load(file.FullName);
                    part = XParser.Parse <ParameterizedPart>(xe);
                    break;

                default:
                    part = makeOtherFile(ext, file);
                    break;
                }
                if (part != null)
                {
                    Add(part);
                }
            }
        }
Esempio n. 7
0
        public void IsClosingElementTest2()
        {
            const string xml =
                "<file id=\"1\">\r\n        <name>uImage-2.6.33-omap-pm</name>\r\n        <checksum type=\"md5\">0E49369FCCD724CB7E44AC401902E2D8</checksum>\r\n      </file>";

            Assert.IsFalse(XParser.IsClosingElement(xml, 79));
        }
Esempio n. 8
0
        public void GetElementAtCursorFuzzyTest()
        {
            const string x = @"<element attr1=""hjdf"">";

            string s = XParser.GetElementAtCursorFuzzy(x, 9);

            Assert.AreEqual("element", s);
        }
Esempio n. 9
0
        public void GetParentElementAtCursorTest1()
        {
            const string x = @"<a><b></b><";

            string s = XParser.GetParentElementAtCursor(x, 11);

            Assert.AreEqual("a", s);
        }
Esempio n. 10
0
        public void IsInsideElementDeclarationTest()
        {
            Assert.IsFalse(XParser.IsInsideElementDeclaration("", 0));

            Assert.IsTrue(XParser.IsInsideElementDeclaration("<elem ", 5));

            Assert.IsFalse(XParser.IsInsideElementDeclaration("<a></a>", 3));
        }
Esempio n. 11
0
 public override void FromX(XElement xe)
 {
     _closed = bool.Parse(xe.Attribute("Closed").Value);
     Vertexs = new List <BulgeVertex2D>();
     foreach (var e in xe.Elements("Vertex"))
     {
         Vertexs.Add(XParser.Parse <BulgeVertex2D>(e));
     }
 }
Esempio n. 12
0
 public void FromX(XElement xe)
 {
     Closed = bool.Parse(xe.Attribute("Closed").Value);
     Degree = 3;
     ControlPoints.Clear();
     foreach (var pt in xe.Element("ControlPoints").Elements())
     {
         ControlPoints.Add(XParser.Parse <Point2D>(pt));
     }
     Knots.FromX(xe.Element("Knots"));
 }
Esempio n. 13
0
        public void IsInsideAttributeKeyTest()
        {
            Assert.AreEqual(false, XParser.IsInsideAttributeKey(@"<ActivationResponse><</ActivationResponse>", 5));
            Assert.AreEqual(false, XParser.IsInsideAttributeKey(@"<hallo abcd=""xxx""></hallo>", 3));
            Assert.AreEqual(true, XParser.IsInsideAttributeKey(@"<hallo abcd=""xxx""></hallo>", 9));
            Assert.AreEqual(false, XParser.IsInsideAttributeKey(@"<hallo abcd=""xxx""></hallo>", 15));

            const string xml =
                "<file id=\"1\">\r\n        <name>uImage-2.6.33-omap-pm</name>\r\n        <checksum type=\"md5\">0E49369FCCD724CB7E44AC401902E2D8</checksum>\r\n      </file>";

            Assert.IsFalse(XParser.IsInsideAttributeKey(xml, 9));
        }
Esempio n. 14
0
        public void IsInsideEmptyElementTest()
        {
            Assert.IsFalse(XParser.IsInsideEmptyElement("", 0));

            Assert.IsFalse(XParser.IsInsideEmptyElement("<elem></elem> ", 3));
            Assert.IsTrue(XParser.IsInsideEmptyElement("<elem/> ", 3));

            string s = @"<hallo datum=""2014-02-24 15:45:00"">
		                    <lastName>Duck</lastName>
		                    <proto>GUSTAV</proto>
	                    </hallo>"    ;

            for (int i = 1; i < s.Length; i++)
            {
                Assert.IsFalse(XParser.IsInsideEmptyElement(s, i));
            }
        }
Esempio n. 15
0
        public void GetElementAtCursorTest()
        {
            string s = XParser.GetElementAtCursor(@"<element attr1=""hjdf"">", 21);

            Assert.AreEqual("element", s);

            string s2 = XParser.GetElementAtCursor(@"</element>", 9);

            Assert.AreEqual("element", s2);

            string s3 = XParser.GetElementAtCursor(@"<element/>", 7);

            Assert.AreEqual("element", s3);

            string s4 = XParser.GetElementAtCursor("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<sd>", 45);

            Assert.AreEqual("sd", s4);
        }
Esempio n. 16
0
        public override void FromX(XElement xe)
        {
            XAttribute att = xe.Attribute("Root");

            Name = xe.Attribute("Name").Value;
            foreach (var e in xe.Elements())
            {
                if (e.Name.LocalName == "Folder")
                {
                    XParser.Parse <PartFolder>(e, f => Add(f));
                }
                else
                {
                    _partIndexs.Add(XParser.Parse <SymbolIndex>(e));
                }
            }
            LoadAttributeInfos(xe);
        }
Esempio n. 17
0
        public void GetParentElementAtCursorTest2()
        {
            const string x1 = @"<a><b></b><";

            string s1 = XParser.GetParentElementAtCursor(x1, 0);

            Assert.AreEqual("", s1);

            string s2 = XParser.GetParentElementAtCursor(x1, 1);

            Assert.AreEqual("", s2);

            const string x2 = @"<ActivationResponse>
	<"    ;
            string       s3 = XParser.GetParentElementAtCursor(x2, x2.Length - 1);

            Assert.AreEqual("ActivationResponse", s3);
        }
Esempio n. 18
0
        public void Completion_Grammar_X()
        {
            var cwd = System.IO.Directory.GetCurrentDirectory();
            // arrange
            var input       = @"A B G";
            var inputStream = new AntlrInputStream(input);
            var lexer       = new XLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new XParser(tokenStream);

            lexer.RemoveErrorListeners();
            parser.RemoveErrorListeners();

            var errorListener = new CountingErrorListener();

            parser.AddErrorListener(errorListener);

            // act
            // assert

            // Specify our entry point
            var tree = parser.a();

            Check.That(errorListener.ErrorCount).IsEqualTo(0);

            var core = new CodeCompletionCore(parser, null, null);

            // 1) At the input start index = 0 => ". A B G"
            var candidates = core.CollectCandidates(0, null);

            Check.That(candidates.Tokens).HasSize(1);
            Check.That(candidates.Tokens).ContainsKey(XLexer.A);
            Check.That(candidates.Rules.Count == 0);

            // 2) Go to token index = 3 => "A B ."
            //           candidates = core.CollectCandidates(3, null);
            candidates = core.CollectCandidates(2, null);
            Check.That(candidates.Tokens).HasSize(10);
            // Set should contain C, D, E, F, G, X, Y, Z, M, N
            // e.g., "A B C D G" is parsed fine.
            // Instead, what we see is C, X, Y, and of course, -2 = epsilon.
        }
Esempio n. 19
0
        public static void ExpandEmptyTag(string text, int cursor, out int newCursor, out int startReplace, out int lengthReplace, out string replaceWith)
        {
            Debug.Assert(XParser.IsInsideEmptyElement(text, cursor));


//            int idxStart = text.LastIndexOf('<', cursor);
            int idxEnd = text.IndexOf('>', cursor);

            Debug.Assert(idxEnd != -1, "Can only happen of XParser.IsInsideEmptyElement is incorrect");


            string tag = XParser.GetElementAtCursor(text, cursor - 1);

            startReplace = idxEnd - 1;

            string element = string.Format("></{0}>", tag);

//            startReplace = idxStart;
            lengthReplace = 2;  //we assume that endtag is always "/>" and not something with spaces, like "/    >"
            replaceWith   = element;
            newCursor     = idxEnd + 1;
        }
Esempio n. 20
0
        public override void FromX(XElement xe)
        {
            Periodic  = bool.Parse(xe.Attribute("Periodic").Value);
            NurbsData = new NurbsData();
            NurbsData.FromX(xe.Element("NurbsData"));

            HasFitPoints = bool.Parse(xe.Attribute("HasFitPoints").Value);
            if (HasFitPoints)
            {
                var fpts = xe.Element("FitPoints");
                FitPoints = new List <Point2D>();
                foreach (var pt in fpts.Elements())
                {
                    FitPoints.Add(XParser.Parse <Point2D>(pt));
                }
                TangentsExist = bool.Parse(fpts.Attribute("TangentsExist").Value);
                if (TangentsExist)
                {
                    StartTangent = Vector2D.Parse(fpts.Attribute("Start").Value);
                    EndTangent   = Vector2D.Parse(fpts.Attribute("End").Value);
                }
            }
        }
Esempio n. 21
0
        public void IsClosingElementTest()
        {
            const string x1 = @"<element attr1=""hjdf"">";

            Assert.IsFalse(XParser.IsClosingElement(x1, 21, "element"));

            const string x2 = @"</element>";

            Assert.IsTrue(XParser.IsClosingElement(x2, 9, "element"));

            const string x3 = @"<element/>";

            Assert.IsTrue(XParser.IsClosingElement(x3, 9, "element"));

            const string x4 = @"<element>";

            Assert.IsFalse(XParser.IsClosingElement(x4, 6, "element"));

            Assert.IsFalse(XParser.IsClosingElement(@"<element attr1=""hjdf"">", 21));
            Assert.IsTrue(XParser.IsClosingElement(@"</element>", 9));
            Assert.IsTrue(XParser.IsClosingElement(@"<element/>", 9));
            Assert.IsFalse(XParser.IsClosingElement(@"<element>", 6));
        }
Esempio n. 22
0
        protected override void Execute(EditorFrame ef)
        {
            try
            {
                string xmlToProcess;

                try
                {
                    ef.XmlEditor.Text.ToXmlDocument();  //we are interested if this throws an exception, nothing else
                    xmlToProcess = ef.XmlEditor.Text;
                    //MessageBox.Show(Application.Current.MainWindow, "Document is well-formed. No need to trim.",
                    //                "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch
                {
                    xmlToProcess = XParser.Trim(ef.XmlEditor.Text);
                }

                try
                {
                    ef.XmlEditor.Text = PrettyPrint.Execute(
                        xmlToProcess,
                        ef.Data.PrettyPrintData.Indent,
                        ef.Data.PrettyPrintData.NewLineOnAttributes
                        );
                }
                catch
                {
                    ef.XmlEditor.Text = xmlToProcess;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(Application.Current.MainWindow, "Error: " + e.Message, "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
Esempio n. 23
0
 public void IsInsideCommentTest()
 {
     Assert.IsFalse(XParser.IsInsideComment("xxx", 2));
     Assert.IsTrue(XParser.IsInsideComment("<!-- xxx --> ", 6));
 }