public void GetTokens_MultipleConventions_ReturnsTokens()
        {
            var input = new CustomNamedObject
            {
                UpperPropertyName = "Foo.",
                OtherPropertyName = "Bar."
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("CustomNamedObject"),
                ModelGrammar.TokenProperty("upperPropertyName"),
                ModelGrammar.TokenPrimitive("Foo."),
                ModelGrammar.TokenProperty("arbitraryOther"),
                ModelGrammar.TokenPrimitive("Bar."),
                ModelGrammar.TokenObjectEnd
            };

            var resolver = new CombinedResolverStrategy(
                new JsonResolverStrategy(),
                new DataContractResolverStrategy(),
                new XmlResolverStrategy(),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.PascalCase),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, "-"),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Uppercase, "_"));

            var actual = new ModelWalker(new DataWriterSettings(resolver)).GetTokens(input).ToArray();

            Assert.Equal(expected, actual, false);
        }
        public void GetTokens_MultipleConventions_ReturnsSingleDataName()
        {
            var input = new NamingTest
            {
                Little_BITOfEverything123456789MixedIn = "Foo."
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("Naming Test"),
                ModelGrammar.TokenProperty("Little BIT Of Everything 123456789 Mixed In"),
                ModelGrammar.TokenPrimitive("Foo."),
                ModelGrammar.TokenObjectEnd
            };

            var resolver = new CombinedResolverStrategy(
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.NoChange, " "),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.PascalCase),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, "-"),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Uppercase, "_"));

            var actual = new ModelWalker(new DataWriterSettings(resolver)).GetTokens(input).ToArray();

            Assert.Equal(expected, actual, false);
        }
Beispiel #3
0
        public void GetTokens_ExpandoObjectNested_ReturnsObjectTokens()
        {
            dynamic input = new ExpandoObject();

            input.foo   = true;
            input.array = new object[]
            {
                false, 1, 2, Math.PI, null, "hello world."
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("foo"),
                ModelGrammar.TokenPrimitive(true),
                ModelGrammar.TokenProperty("array"),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenPrimitive(false),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenPrimitive(Math.PI),
                ModelGrammar.TokenPrimitive(null),
                ModelGrammar.TokenPrimitive("hello world."),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #4
0
        public void GetTokens_GraphCycleTypeReferences_ThrowsGraphCycleException()
        {
            var input = new Person
            {
                Name   = "John, Jr.",
                Father = new Person
                {
                    Name = "John, Sr."
                },
                Mother = new Person
                {
                    Name = "Sally"
                }
            };

            // create multiple cycles
            input.Father.Children = input.Mother.Children = new Person[]
            {
                input
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.Reference
            });

            GraphCycleException ex = Assert.Throws <GraphCycleException>(
                delegate
            {
                walker.GetTokens(input).ToArray();
            });

            Assert.Equal(GraphCycleType.Reference, ex.CycleType);
        }
Beispiel #5
0
        public void GetTokens_ExpandoObject_ReturnsObjectTokens()
        {
            dynamic input = new ExpandoObject();

            input.One   = 1;
            input.Two   = 2;
            input.Three = 3;

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("One"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenProperty("Two"),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenProperty("Three"),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens((object)input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void GetTokens_ArrayMultiItem_ReturnsArrayTokens()
        {
            var input = new object[]
            {
                false,
                true,
                null,
                'a',
                'b',
                'c',
                1,
                2,
                3
            };

            var expected = new[]
            {
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenFalse,
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenNull,
                ModelGrammar.TokenPrimitive('a'),
                ModelGrammar.TokenPrimitive('b'),
                ModelGrammar.TokenPrimitive('c'),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenArrayEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #7
0
        public void GetTokens_ObjectDictionary_ReturnsObjectTokens()
        {
            var input = new Dictionary <string, object>
            {
                { "One", 1 },
                { "Two", 2 },
                { "Three", 3 }
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("One"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenProperty("Two"),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenProperty("Three"),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #8
0
        public void GetTokens_DynamicExample_ReturnsDynamicObject()
        {
            dynamic input = new DynamicExample();

            input.foo     = "hello world";
            input.number  = 42;
            input.boolean = false;
            input.@null   = null;

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("DynamicExample"),
                ModelGrammar.TokenProperty("foo"),
                ModelGrammar.TokenPrimitive("hello world"),
                ModelGrammar.TokenProperty("number"),
                ModelGrammar.TokenPrimitive(42),
                ModelGrammar.TokenProperty("boolean"),
                ModelGrammar.TokenPrimitive(false),
                ModelGrammar.TokenProperty("null"),
                ModelGrammar.TokenPrimitive(null),
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual, false);
        }
Beispiel #9
0
        public void GetTokens_GraphCycleTypeMaxDepthNoMaxDepth_ThrowsArgumentException()
        {
            var input = new Person
            {
                Name   = "John, Jr.",
                Father = new Person
                {
                    Name = "John, Sr."
                },
                Mother = new Person
                {
                    Name = "Sally"
                }
            };

            // create multiple cycles
            input.Father.Children = input.Mother.Children = new Person[]
            {
                input
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.MaxDepth,
                MaxDepth    = 0
            });

            ArgumentException ex = Assert.Throws <ArgumentException>(
                delegate
            {
                walker.GetTokens(input).ToArray();
            });

            Assert.Equal("maxDepth", ex.ParamName);
        }
Beispiel #10
0
        public void Ctor_NullSettings_ThrowsArgumentNullException()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var walker = new ModelWalker(null);
            });

            // verify exception is coming from expected param
            Assert.Equal("settings", ex.ParamName);
        }
Beispiel #11
0
        public void GetTokens_SingleNegInfinity_ReturnsNegInfinityToken()
        {
            var input = Single.NegativeInfinity;

            var expected = new[]
            {
                ModelGrammar.TokenPrimitive(Double.NegativeInfinity)
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #12
0
        public void GetTokens_True_ReturnsTrueToken()
        {
            var input = true;

            var expected = new[]
            {
                ModelGrammar.TokenTrue
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            try
            {
                XSharpModel.ModelWalker.Suspend();
                if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                //
                var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
                if (!tp.HasValue)
                {
                    return;
                }
                //
                var    triggerPoint = tp.Value;
                IToken stopToken;
                //
                // Check if we can get the member where we are
                XMemberDefinition member           = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file);
                XTypeDefinition   currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(triggerPoint.Position, _file);

                var           lineNumber = triggerPoint.GetContainingLine().LineNumber;
                var           snapshot   = _textBuffer.CurrentSnapshot;
                List <String> tokenList  = XSharpTokenTools.GetTokenList(triggerPoint.Position, lineNumber, snapshot, out stopToken, true, _file, false, member);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                CompletionElement gotoElement;
                String            currentNS = "";
                if (currentNamespace != null)
                {
                    currentNS = currentNamespace.Name;
                }
                CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect);
                //
                if ((gotoElement != null) && (gotoElement.IsSourceElement))
                {
                    peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.SourceElement, _peekResultFactory));
                }
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("XSharpPeekItemSource.AugmentPeekSession failed : ");
                XSettings.DisplayException(ex);
            }
            finally
            {
                ModelWalker.Resume();
            }
        }
Beispiel #14
0
        public void GetTokens_Null_ReturnsNullToken()
        {
            var input = (object)null;

            var expected = new[]
            {
                ModelGrammar.TokenNull
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #15
0
        public void GetTokens_DoubleNaN_ReturnsNaNToken()
        {
            var input = Double.NaN;

            var expected = new[]
            {
                ModelGrammar.TokenPrimitive(Double.NaN)
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #16
0
        public void GetTokens_ListEmpty_ReturnsEmptyArrayTokens()
        {
            var input = new List <object>(0);

            var expected = new[]
            {
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenArrayEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #17
0
        public void GetTokens_EmptyDictionary_ReturnsEmptyObjectTokens()
        {
            var input = new Dictionary <string, object>(0);

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #18
0
        public int FDoIdle(uint grfidlef)
        {
            bool bPeriodic = (grfidlef & (uint)_OLEIDLEF.oleidlefPeriodic) != 0;

            if (_libraryManager != null)
            {
                _libraryManager.OnIdle();
            }

            if (!ModelWalker.IsRunning && ModelWalker.HasWork)
            {
                ModelWalker.Walk();
            }
            return(0);
        }
Beispiel #19
0
        public void GetTokens_ArraySingleItem_ReturnsSingleItemArrayTokens()
        {
            var input = new object[]
            {
                null
            };

            var expected = new[]
            {
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenArrayEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #20
0
        public void GetTokens_ObjectAnonymous_ReturnsObjectTokens()
        {
            var input = new
            {
                One   = 1,
                Two   = 2,
                Three = 3,
                Four  = new
                {
                    A = 'a',
                    B = 'b',
                    C = 'c'
                }
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("One"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenProperty("Two"),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenProperty("Three"),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenProperty("Four"),
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("A"),
                ModelGrammar.TokenPrimitive('a'),
                ModelGrammar.TokenProperty("B"),
                ModelGrammar.TokenPrimitive('b'),
                ModelGrammar.TokenProperty("C"),
                ModelGrammar.TokenPrimitive('c'),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
		public void GetTokens_DoubleNaN_ReturnsNaNToken()
		{
			var input = Double.NaN;

			var expected = new[]
				{
					ModelGrammar.TokenPrimitive(Double.NaN)
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_ArrayNested_ReturnsNestedArrayTokens()
		{
			var input = new object[]
				{
					false,
					true,
					null,
					new []
					{
						'a',
						'b',
						'c'
					},
					new []
					{
						1,
						2,
						3
					}
				};

			var expected = new[]
				{
					ModelGrammar.TokenArrayBegin("array"),
					ModelGrammar.TokenFalse,
					ModelGrammar.TokenTrue,
					ModelGrammar.TokenNull,
					ModelGrammar.TokenArrayBegin("array"),
					ModelGrammar.TokenPrimitive('a'),
					ModelGrammar.TokenPrimitive('b'),
					ModelGrammar.TokenPrimitive('c'),
					ModelGrammar.TokenArrayEnd,
					ModelGrammar.TokenArrayBegin("array"),
					ModelGrammar.TokenPrimitive(1),
					ModelGrammar.TokenPrimitive(2),
					ModelGrammar.TokenPrimitive(3),
					ModelGrammar.TokenArrayEnd,
					ModelGrammar.TokenArrayEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_ExpandoObjectNested_ReturnsObjectTokens()
		{
			dynamic input = new ExpandoObject();

			input.foo = true;
			input.array = new object[]
			{
				false, 1, 2, Math.PI, null, "hello world."
			};

			var expected = new[]
				{
					ModelGrammar.TokenObjectBegin("object"),
					ModelGrammar.TokenProperty("foo"),
					ModelGrammar.TokenPrimitive(true),
					ModelGrammar.TokenProperty("array"),
					ModelGrammar.TokenArrayBegin("array"),
					ModelGrammar.TokenPrimitive(false),
					ModelGrammar.TokenPrimitive(1),
					ModelGrammar.TokenPrimitive(2),
					ModelGrammar.TokenPrimitive(Math.PI),
					ModelGrammar.TokenPrimitive(null),
					ModelGrammar.TokenPrimitive("hello world."),
					ModelGrammar.TokenArrayEnd,
					ModelGrammar.TokenObjectEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_GraphComplex_ReturnsObjectTokens()
		{
			var input = new object[] {
				"JSON Test Pattern pass1",
				new Dictionary<string, object>
				{
					{ "object with 1 member", new[] { "array with 1 element" } },
				},
				new Dictionary<string, object>(),
				new object[0],
				-42,
				true,
				false,
				null,
				new Dictionary<string, object> {
					{ "integer", 1234567890 },
					{ "real", -9876.543210 },
					{ "e", 0.123456789e-12 },
					{ "E", 1.234567890E+34 },
					{ "", 23456789012E66 },
					{ "zero", 0 },
					{ "one", 1 },
					{ "space", " " },
					{ "quote", "\"" },
					{ "backslash", "\\" },
					{ "controls", "\b\f\n\r\t" },
					{ "slash", "/ & /" },
					{ "alpha", "abcdefghijklmnopqrstuvwyz" },
					{ "ALPHA", "ABCDEFGHIJKLMNOPQRSTUVWYZ" },
					{ "digit", "0123456789" },
					{ "0123456789", "digit" },
					{ "special", "`1~!@#$%^&*()_+-={':[,]}|;.</>?" },
					{ "hex", "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A" },
					{ "true", true },
					{ "false", false },
					{ "null", null },
					{ "array", new object[0] },
					{ "object", new Dictionary<string, object>() },
					{ "address", "50 St. James Street" },
					{ "url", "http://www.JSON.org/" },
					{ "comment", "// /* <!-- --" },
					{ "# -- --> */", " " },
					{ " s p a c e d ", new [] { 1,2,3,4,5,6,7 } },
					{ "compact", new [] { 1,2,3,4,5,6,7 } },
					{ "jsontext", "{\"object with 1 member\":[\"array with 1 element\"]}" },
					{ "quotes", "&#34; \u0022 %22 0x22 034 &#x22;" },
					{ "/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?", "A key can be any string" }
				},
				0.5,
				98.6,
				99.44,
				1066,
				1e1,
				0.1e1,
				1e-1,
				1e00,
				2e+00,
				2e-00,
				"rosebud"
			};

			var expected = new[]
			{
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenPrimitive("JSON Test Pattern pass1"),
				ModelGrammar.TokenObjectBegin("object"),
				ModelGrammar.TokenProperty("object with 1 member"),
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenPrimitive("array with 1 element"),
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenObjectEnd,
				ModelGrammar.TokenObjectBegin("object"),
				ModelGrammar.TokenObjectEnd,
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenPrimitive(-42),
				ModelGrammar.TokenTrue,
				ModelGrammar.TokenFalse,
				ModelGrammar.TokenNull,
				ModelGrammar.TokenObjectBegin("object"),
				ModelGrammar.TokenProperty("integer"),
				ModelGrammar.TokenPrimitive(1234567890),
				ModelGrammar.TokenProperty("real"),
				ModelGrammar.TokenPrimitive(-9876.543210),
				ModelGrammar.TokenProperty("e"),
				ModelGrammar.TokenPrimitive(0.123456789e-12),
				ModelGrammar.TokenProperty("E"),
				ModelGrammar.TokenPrimitive(1.234567890E+34),
				ModelGrammar.TokenProperty(""),
				ModelGrammar.TokenPrimitive(23456789012E66),
				ModelGrammar.TokenProperty("zero"),
				ModelGrammar.TokenPrimitive(0),
				ModelGrammar.TokenProperty("one"),
				ModelGrammar.TokenPrimitive(1),
				ModelGrammar.TokenProperty("space"),
				ModelGrammar.TokenPrimitive(" "),
				ModelGrammar.TokenProperty("quote"),
				ModelGrammar.TokenPrimitive("\""),
				ModelGrammar.TokenProperty("backslash"),
				ModelGrammar.TokenPrimitive("\\"),
				ModelGrammar.TokenProperty("controls"),
				ModelGrammar.TokenPrimitive("\b\f\n\r\t"),
				ModelGrammar.TokenProperty("slash"),
				ModelGrammar.TokenPrimitive("/ & /"),
				ModelGrammar.TokenProperty("alpha"),
				ModelGrammar.TokenPrimitive("abcdefghijklmnopqrstuvwyz"),
				ModelGrammar.TokenProperty("ALPHA"),
				ModelGrammar.TokenPrimitive("ABCDEFGHIJKLMNOPQRSTUVWYZ"),
				ModelGrammar.TokenProperty("digit"),
				ModelGrammar.TokenPrimitive("0123456789"),
				ModelGrammar.TokenProperty("0123456789"),
				ModelGrammar.TokenPrimitive("digit"),
				ModelGrammar.TokenProperty("special"),
				ModelGrammar.TokenPrimitive("`1~!@#$%^&*()_+-={':[,]}|;.</>?"),
				ModelGrammar.TokenProperty("hex"),
				ModelGrammar.TokenPrimitive("\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"),
				ModelGrammar.TokenProperty("true"),
				ModelGrammar.TokenTrue,
				ModelGrammar.TokenProperty("false"),
				ModelGrammar.TokenFalse,
				ModelGrammar.TokenProperty("null"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenProperty("array"),
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenProperty("object"),
				ModelGrammar.TokenObjectBegin("object"),
				ModelGrammar.TokenObjectEnd,
				ModelGrammar.TokenProperty("address"),
				ModelGrammar.TokenPrimitive("50 St. James Street"),
				ModelGrammar.TokenProperty("url"),
				ModelGrammar.TokenPrimitive("http://www.JSON.org/"),
				ModelGrammar.TokenProperty("comment"),
				ModelGrammar.TokenPrimitive("// /* <!-- --"),
				ModelGrammar.TokenProperty("# -- --> */"),
				ModelGrammar.TokenPrimitive(" "),
				ModelGrammar.TokenProperty(" s p a c e d "),
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenPrimitive(1),
				ModelGrammar.TokenPrimitive(2),
				ModelGrammar.TokenPrimitive(3),
				ModelGrammar.TokenPrimitive(4),
				ModelGrammar.TokenPrimitive(5),
				ModelGrammar.TokenPrimitive(6),
				ModelGrammar.TokenPrimitive(7),
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenProperty("compact"),
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenPrimitive(1),
				ModelGrammar.TokenPrimitive(2),
				ModelGrammar.TokenPrimitive(3),
				ModelGrammar.TokenPrimitive(4),
				ModelGrammar.TokenPrimitive(5),
				ModelGrammar.TokenPrimitive(6),
				ModelGrammar.TokenPrimitive(7),
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenProperty("jsontext"),
				ModelGrammar.TokenPrimitive("{\"object with 1 member\":[\"array with 1 element\"]}"),
				ModelGrammar.TokenProperty("quotes"),
				ModelGrammar.TokenPrimitive("&#34; \u0022 %22 0x22 034 &#x22;"),
				ModelGrammar.TokenProperty("/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"),
				ModelGrammar.TokenPrimitive("A key can be any string"),
				ModelGrammar.TokenObjectEnd,
				ModelGrammar.TokenPrimitive(0.5),
				ModelGrammar.TokenPrimitive(98.6),
				ModelGrammar.TokenPrimitive(99.44),
				ModelGrammar.TokenPrimitive(1066),
				ModelGrammar.TokenPrimitive(10.0),
				ModelGrammar.TokenPrimitive(1.0),
				ModelGrammar.TokenPrimitive(0.1),
				ModelGrammar.TokenPrimitive(1.0),
				ModelGrammar.TokenPrimitive(2.0),
				ModelGrammar.TokenPrimitive(2.0),
				ModelGrammar.TokenPrimitive("rosebud"),
				ModelGrammar.TokenArrayEnd
			};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_DynamicExample_ReturnsDynamicObject()
		{
			dynamic input = new DynamicExample();
			input.foo = "hello world";
			input.number = 42;
			input.boolean = false;
			input.@null = null;

			var expected = new[]
			{
				ModelGrammar.TokenObjectBegin("DynamicExample"),
				ModelGrammar.TokenProperty("foo"),
				ModelGrammar.TokenPrimitive("hello world"),
				ModelGrammar.TokenProperty("number"),
				ModelGrammar.TokenPrimitive(42),
				ModelGrammar.TokenProperty("boolean"),
				ModelGrammar.TokenPrimitive(false),
				ModelGrammar.TokenProperty("null"),
				ModelGrammar.TokenPrimitive(null),
				ModelGrammar.TokenObjectEnd
			};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual, false);
		}
		public void GetTokens_GraphCycleTypeIgnore_ReplacesCycleStartWithNull()
		{
			var input = new Person
			{
				Name = "John, Jr.",
				Father = new Person
				{
					Name = "John, Sr."
				},
				Mother = new Person
				{
					Name = "Sally"
				}
			};

			// create multiple cycles
			input.Father.Children = input.Mother.Children = new Person[]
			{
				input
			};

			var walker = new ModelWalker(new DataWriterSettings
			{
				GraphCycles = GraphCycleType.Ignore
			});

			var expected = new[]
			{
				ModelGrammar.TokenObjectBegin("Person"),
				ModelGrammar.TokenProperty("Name"),
				ModelGrammar.TokenPrimitive("John, Jr."),

				ModelGrammar.TokenProperty("Father"),
				ModelGrammar.TokenObjectBegin("Person"),
				ModelGrammar.TokenProperty("Name"),
				ModelGrammar.TokenPrimitive("John, Sr."),
				ModelGrammar.TokenProperty("Father"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenProperty("Mother"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenProperty("Children"),
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenObjectEnd,

				ModelGrammar.TokenProperty("Mother"),
				ModelGrammar.TokenObjectBegin("Person"),
				ModelGrammar.TokenProperty("Name"),
				ModelGrammar.TokenPrimitive("Sally"),
				ModelGrammar.TokenProperty("Father"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenProperty("Mother"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenProperty("Children"),
				ModelGrammar.TokenArrayBegin("array"),
				ModelGrammar.TokenNull,
				ModelGrammar.TokenArrayEnd,
				ModelGrammar.TokenObjectEnd,

				ModelGrammar.TokenProperty("Children"),
				ModelGrammar.TokenNull,

				ModelGrammar.TokenObjectEnd
			};

			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_EmptyDictionary_ReturnsEmptyObjectTokens()
		{
			var input = new Dictionary<string, object>(0);

			var expected = new[]
				{
					ModelGrammar.TokenObjectBegin("object"),
					ModelGrammar.TokenObjectEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
        public void GetTokens_MultipleConventions_ReturnsSingleDataName()
        {
            var input = new NamingTest
            {
                Little_BITOfEverything123456789MixedIn = "Foo."
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("Naming Test"),
                ModelGrammar.TokenProperty("Little BIT Of Everything 123456789 Mixed In"),
                ModelGrammar.TokenPrimitive("Foo."),
                ModelGrammar.TokenObjectEnd
            };

            var resolver = new CombinedResolverStrategy(
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.NoChange, " "),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.PascalCase),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, "-"),
                new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Uppercase, "_"));

            var actual = new ModelWalker(new DataWriterSettings(resolver)).GetTokens(input).ToArray();

            Assert.Equal(expected, actual, false);
        }
		public void GetTokens_GraphCycleTypeReferences_ThrowsGraphCycleException()
		{
			var input = new Person
			{
				Name = "John, Jr.",
				Father = new Person
				{
					Name = "John, Sr."
				},
				Mother = new Person
				{
					Name = "Sally"
				}
			};

			// create multiple cycles
			input.Father.Children = input.Mother.Children = new Person[]
			{
				input
			};

			var walker = new ModelWalker(new DataWriterSettings
			{
				GraphCycles = GraphCycleType.Reference
			});

			GraphCycleException ex = Assert.Throws<GraphCycleException>(
				delegate
				{
					walker.GetTokens(input).ToArray();
				});

			Assert.Equal(GraphCycleType.Reference, ex.CycleType);
		}
		public void GetTokens_ExpandoObject_ReturnsObjectTokens()
		{
			dynamic input = new ExpandoObject();
			input.One = 1;
			input.Two = 2;
			input.Three = 3;

			var expected = new[]
				{
					ModelGrammar.TokenObjectBegin("object"),
					ModelGrammar.TokenProperty("One"),
					ModelGrammar.TokenPrimitive(1),
					ModelGrammar.TokenProperty("Two"),
					ModelGrammar.TokenPrimitive(2),
					ModelGrammar.TokenProperty("Three"),
					ModelGrammar.TokenPrimitive(3),
					ModelGrammar.TokenObjectEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens((object)input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void Ctor_NullSettings_ThrowsArgumentNullException()
		{
			ArgumentNullException ex = Assert.Throws<ArgumentNullException>(
				delegate
				{
					var walker = new ModelWalker(null);
				});

			// verify exception is coming from expected param
			Assert.Equal("settings", ex.ParamName);
		}
		public void GetTokens_Null_ReturnsNullToken()
		{
			var input = (object)null;

			var expected = new[]
				{
					ModelGrammar.TokenNull
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_ObjectAnonymous_ReturnsObjectTokens()
		{
			var input = new
			{
				One = 1,
				Two = 2,
				Three = 3,
				Four = new
				{
					A = 'a',
					B = 'b',
					C = 'c'
				}
			};

			var expected = new[]
				{
					ModelGrammar.TokenObjectBegin("object"),
					ModelGrammar.TokenProperty("One"),
					ModelGrammar.TokenPrimitive(1),
					ModelGrammar.TokenProperty("Two"),
					ModelGrammar.TokenPrimitive(2),
					ModelGrammar.TokenProperty("Three"),
					ModelGrammar.TokenPrimitive(3),
					ModelGrammar.TokenProperty("Four"),
					ModelGrammar.TokenObjectBegin("object"),
					ModelGrammar.TokenProperty("A"),
					ModelGrammar.TokenPrimitive('a'),
					ModelGrammar.TokenProperty("B"),
					ModelGrammar.TokenPrimitive('b'),
					ModelGrammar.TokenProperty("C"),
					ModelGrammar.TokenPrimitive('c'),
					ModelGrammar.TokenObjectEnd,
					ModelGrammar.TokenObjectEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_ObjectDictionary_ReturnsObjectTokens()
		{
			var input = new Dictionary<string, object>
			{
				{ "One", 1 },
				{ "Two", 2 },
				{ "Three", 3 }
			};

			var expected = new[]
				{
					ModelGrammar.TokenObjectBegin("object"),
					ModelGrammar.TokenProperty("One"),
					ModelGrammar.TokenPrimitive(1),
					ModelGrammar.TokenProperty("Two"),
					ModelGrammar.TokenPrimitive(2),
					ModelGrammar.TokenProperty("Three"),
					ModelGrammar.TokenPrimitive(3),
					ModelGrammar.TokenObjectEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_MultipleConventions_ReturnsTokens()
		{
			var input = new CustomNamedObject
			{
				UpperPropertyName = "Foo.",
				OtherPropertyName = "Bar."
			};

			var expected = new[]
			{
				ModelGrammar.TokenObjectBegin("CustomNamedObject"),
				ModelGrammar.TokenProperty("upperPropertyName"),
				ModelGrammar.TokenPrimitive("Foo."),
				ModelGrammar.TokenProperty("arbitraryOther"),
				ModelGrammar.TokenPrimitive("Bar."),
				ModelGrammar.TokenObjectEnd
			};

			var resolver = new CombinedResolverStrategy(
				new JsonResolverStrategy(),
				new DataContractResolverStrategy(),
				new XmlResolverStrategy(),
				new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.PascalCase),
				new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase),
				new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, "-"),
				new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Uppercase, "_"));

			var actual = new ModelWalker(new DataWriterSettings(resolver)).GetTokens(input).ToArray();

			Assert.Equal(expected, actual, false);
		}
		public void GetTokens_SingleNegInfinity_ReturnsNegInfinityToken()
		{
			var input = Single.NegativeInfinity;

			var expected = new[]
				{
					ModelGrammar.TokenPrimitive(Double.NegativeInfinity)
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
Beispiel #37
0
        public void GetTokens_GraphCycleTypeIgnore_ReplacesCycleStartWithNull()
        {
            var input = new Person
            {
                Name   = "John, Jr.",
                Father = new Person
                {
                    Name = "John, Sr."
                },
                Mother = new Person
                {
                    Name = "Sally"
                }
            };

            // create multiple cycles
            input.Father.Children = input.Mother.Children = new Person[]
            {
                input
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.Ignore
            });

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("Person"),
                ModelGrammar.TokenProperty("Name"),
                ModelGrammar.TokenPrimitive("John, Jr."),

                ModelGrammar.TokenProperty("Father"),
                ModelGrammar.TokenObjectBegin("Person"),
                ModelGrammar.TokenProperty("Name"),
                ModelGrammar.TokenPrimitive("John, Sr."),
                ModelGrammar.TokenProperty("Father"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenProperty("Mother"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenProperty("Children"),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenObjectEnd,

                ModelGrammar.TokenProperty("Mother"),
                ModelGrammar.TokenObjectBegin("Person"),
                ModelGrammar.TokenProperty("Name"),
                ModelGrammar.TokenPrimitive("Sally"),
                ModelGrammar.TokenProperty("Father"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenProperty("Mother"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenProperty("Children"),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenObjectEnd,

                ModelGrammar.TokenProperty("Children"),
                ModelGrammar.TokenNull,

                ModelGrammar.TokenObjectEnd
            };

            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
		public void GetTokens_True_ReturnsTrueToken()
		{
			var input = true;

			var expected = new[]
				{
					ModelGrammar.TokenTrue
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_GraphCycleTypeMaxDepthNoMaxDepth_ThrowsArgumentException()
		{
			var input = new Person
			{
				Name = "John, Jr.",
				Father = new Person
				{
					Name = "John, Sr."
				},
				Mother = new Person
				{
					Name = "Sally"
				}
			};

			// create multiple cycles
			input.Father.Children = input.Mother.Children = new Person[]
			{
				input
			};

			var walker = new ModelWalker(new DataWriterSettings
			{
				GraphCycles = GraphCycleType.MaxDepth,
				MaxDepth = 0
			});

			ArgumentException ex = Assert.Throws<ArgumentException>(
				delegate
				{
					walker.GetTokens(input).ToArray();
				});

			Assert.Equal("maxDepth", ex.ParamName);
		}
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            try
            {
                XSharpModel.ModelWalker.Suspend();
                if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                //
                var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
                if (!tp.HasValue)
                {
                    return;
                }
                var triggerPoint = tp.Value;

                // LookUp for the BaseType, reading the TokenList (From left to right)
                var location = _textBuffer.FindLocation(triggerPoint);
                if (location == null)
                {
                    return;
                }

                CompletionState state;
                var             tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);
                var             result    = new List <IXSymbol>();
                result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true));
                //
                if (result.Count > 0)
                {
                    if (result[0] is XSourceSymbol symbol)
                    {
                        peekableItems.Add(new XSharpDefinitionPeekItem(symbol, _peekResultFactory));
                    }
                    else if (result[0] is XPESymbol pesymbol)
                    {
                        XPETypeSymbol petype;
                        if (pesymbol is XPETypeSymbol)
                        {
                            petype = (XPETypeSymbol)pesymbol;
                        }
                        else if (pesymbol is XPEMemberSymbol member)
                        {
                            petype = (XPETypeSymbol)member.Parent;
                        }
                        else
                        {
                            return;
                        }
                        var file   = XSharpGotoDefinition.CreateFileForSystemType(petype, pesymbol);
                        var entity = XSharpGotoDefinition.FindElementInFile(file, petype, pesymbol);
                        if (entity != null)
                        {
                            peekableItems.Add(new XSharpDefinitionPeekItem(entity, _peekResultFactory));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "XSharpPeekItemSource.AugmentPeekSession failed : ");
            }
            finally
            {
                ModelWalker.Resume();
            }
        }
Beispiel #41
0
        public void GetTokens_GraphComplex_ReturnsObjectTokens()
        {
            var input = new object[] {
                "JSON Test Pattern pass1",
                new Dictionary <string, object>
                {
                    { "object with 1 member", new[] { "array with 1 element" } },
                },
                new Dictionary <string, object>(),
                new object[0],
                -42,
                true,
                false,
                null,
                new Dictionary <string, object> {
                    { "integer", 1234567890 },
                    { "real", -9876.543210 },
                    { "e", 0.123456789e-12 },
                    { "E", 1.234567890E+34 },
                    { "", 23456789012E66 },
                    { "zero", 0 },
                    { "one", 1 },
                    { "space", " " },
                    { "quote", "\"" },
                    { "backslash", "\\" },
                    { "controls", "\b\f\n\r\t" },
                    { "slash", "/ & /" },
                    { "alpha", "abcdefghijklmnopqrstuvwyz" },
                    { "ALPHA", "ABCDEFGHIJKLMNOPQRSTUVWYZ" },
                    { "digit", "0123456789" },
                    { "0123456789", "digit" },
                    { "special", "`1~!@#$%^&*()_+-={':[,]}|;.</>?" },
                    { "hex", "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A" },
                    { "true", true },
                    { "false", false },
                    { "null", null },
                    { "array", new object[0] },
                    { "object", new Dictionary <string, object>() },
                    { "address", "50 St. James Street" },
                    { "url", "http://www.JSON.org/" },
                    { "comment", "// /* <!-- --" },
                    { "# -- --> */", " " },
                    { " s p a c e d ", new [] { 1, 2, 3, 4, 5, 6, 7 } },
                    { "compact", new [] { 1, 2, 3, 4, 5, 6, 7 } },
                    { "jsontext", "{\"object with 1 member\":[\"array with 1 element\"]}" },
                    { "quotes", "&#34; \u0022 %22 0x22 034 &#x22;" },
                    { "/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?", "A key can be any string" }
                },
                0.5,
                98.6,
                99.44,
                1066,
                1e1,
                0.1e1,
                1e-1,
                1e00,
                2e+00,
                2e-00,
                "rosebud"
            };

            var expected = new[]
            {
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenPrimitive("JSON Test Pattern pass1"),
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("object with 1 member"),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenPrimitive("array with 1 element"),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenPrimitive(-42),
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenFalse,
                ModelGrammar.TokenNull,
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("integer"),
                ModelGrammar.TokenPrimitive(1234567890),
                ModelGrammar.TokenProperty("real"),
                ModelGrammar.TokenPrimitive(-9876.543210),
                ModelGrammar.TokenProperty("e"),
                ModelGrammar.TokenPrimitive(0.123456789e-12),
                ModelGrammar.TokenProperty("E"),
                ModelGrammar.TokenPrimitive(1.234567890E+34),
                ModelGrammar.TokenProperty(""),
                ModelGrammar.TokenPrimitive(23456789012E66),
                ModelGrammar.TokenProperty("zero"),
                ModelGrammar.TokenPrimitive(0),
                ModelGrammar.TokenProperty("one"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenProperty("space"),
                ModelGrammar.TokenPrimitive(" "),
                ModelGrammar.TokenProperty("quote"),
                ModelGrammar.TokenPrimitive("\""),
                ModelGrammar.TokenProperty("backslash"),
                ModelGrammar.TokenPrimitive("\\"),
                ModelGrammar.TokenProperty("controls"),
                ModelGrammar.TokenPrimitive("\b\f\n\r\t"),
                ModelGrammar.TokenProperty("slash"),
                ModelGrammar.TokenPrimitive("/ & /"),
                ModelGrammar.TokenProperty("alpha"),
                ModelGrammar.TokenPrimitive("abcdefghijklmnopqrstuvwyz"),
                ModelGrammar.TokenProperty("ALPHA"),
                ModelGrammar.TokenPrimitive("ABCDEFGHIJKLMNOPQRSTUVWYZ"),
                ModelGrammar.TokenProperty("digit"),
                ModelGrammar.TokenPrimitive("0123456789"),
                ModelGrammar.TokenProperty("0123456789"),
                ModelGrammar.TokenPrimitive("digit"),
                ModelGrammar.TokenProperty("special"),
                ModelGrammar.TokenPrimitive("`1~!@#$%^&*()_+-={':[,]}|;.</>?"),
                ModelGrammar.TokenProperty("hex"),
                ModelGrammar.TokenPrimitive("\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"),
                ModelGrammar.TokenProperty("true"),
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenProperty("false"),
                ModelGrammar.TokenFalse,
                ModelGrammar.TokenProperty("null"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenProperty("array"),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenProperty("object"),
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenProperty("address"),
                ModelGrammar.TokenPrimitive("50 St. James Street"),
                ModelGrammar.TokenProperty("url"),
                ModelGrammar.TokenPrimitive("http://www.JSON.org/"),
                ModelGrammar.TokenProperty("comment"),
                ModelGrammar.TokenPrimitive("// /* <!-- --"),
                ModelGrammar.TokenProperty("# -- --> */"),
                ModelGrammar.TokenPrimitive(" "),
                ModelGrammar.TokenProperty(" s p a c e d "),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenPrimitive(4),
                ModelGrammar.TokenPrimitive(5),
                ModelGrammar.TokenPrimitive(6),
                ModelGrammar.TokenPrimitive(7),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenProperty("compact"),
                ModelGrammar.TokenArrayBegin("array"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenPrimitive(4),
                ModelGrammar.TokenPrimitive(5),
                ModelGrammar.TokenPrimitive(6),
                ModelGrammar.TokenPrimitive(7),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenProperty("jsontext"),
                ModelGrammar.TokenPrimitive("{\"object with 1 member\":[\"array with 1 element\"]}"),
                ModelGrammar.TokenProperty("quotes"),
                ModelGrammar.TokenPrimitive("&#34; \u0022 %22 0x22 034 &#x22;"),
                ModelGrammar.TokenProperty("/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"),
                ModelGrammar.TokenPrimitive("A key can be any string"),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenPrimitive(0.5),
                ModelGrammar.TokenPrimitive(98.6),
                ModelGrammar.TokenPrimitive(99.44),
                ModelGrammar.TokenPrimitive(1066),
                ModelGrammar.TokenPrimitive(10.0),
                ModelGrammar.TokenPrimitive(1.0),
                ModelGrammar.TokenPrimitive(0.1),
                ModelGrammar.TokenPrimitive(1.0),
                ModelGrammar.TokenPrimitive(2.0),
                ModelGrammar.TokenPrimitive(2.0),
                ModelGrammar.TokenPrimitive("rosebud"),
                ModelGrammar.TokenArrayEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
		public void GetTokens_ArrayEmpty_ReturnsEmptyArrayTokens()
		{
			var input = new object[0];

			var expected = new[]
				{
					ModelGrammar.TokenArrayBegin("array"),
					ModelGrammar.TokenArrayEnd
				};

			var walker = new ModelWalker(new DataWriterSettings());
			var actual = walker.GetTokens(input).ToArray();

			Assert.Equal(expected, actual);
		}
		public void GetTokens_GraphCycleTypeMaxDepthFalsePositive_ThrowsGraphCycleException()
		{
			// input from fail18.json in test suite at http://www.json.org/JSON_checker/
			var input = new[]
			{
				new []
				{
					new []
					{
						new []
						{
							new []
							{
								new []
								{
									new []
									{
										new []
										{
											new []
											{
												new []
												{
													new []
													{
														new []
														{
															new []
															{
																new []
																{
																	new []
																	{
																		new []
																		{
																			new []
																			{
																				new []
																				{
																					new []
																					{
																						new []
																						{
																							"Too deep"
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			};

			var walker = new ModelWalker(new DataWriterSettings
			{
				GraphCycles = GraphCycleType.MaxDepth,
				MaxDepth = 19
			});

			GraphCycleException ex = Assert.Throws<GraphCycleException>(
				delegate
				{
					walker.GetTokens(input).ToArray();
				});

			Assert.Equal(GraphCycleType.MaxDepth, ex.CycleType);
		}
        //static bool skipFirst = true;

        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            if (XSettings.DebuggerIsRunning || XSettings.DisableQuickInfo)
            {
                await session.DismissAsync();

                return(null);
            }
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                await session.DismissAsync();

                return(null);
            }
            try
            {
                ModelWalker.Suspend();
                var ssp = triggerPoint.Value;
                // Map the trigger point down to our buffer.
                ITextSnapshot currentSnapshot = ssp.Snapshot;
                bool          abort           = false;
                var           tokens          = _textBuffer.GetDocument();
                if (tokens == null)
                {
                    return(null);
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                if (!abort)
                {
                    WriteOutputMessage($"Triggerpoint: {triggerPoint.Value.Position}");
                    // We don't want to lex the buffer. So get the tokens from the last lex run
                    // and when these are too old, then simply bail out
                    abort = tokens == null || tokens.SnapShot.Version != currentSnapshot.Version;
                }
                if (abort)
                {
                    await session.DismissAsync();

                    return(null);
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                var             location = _textBuffer.FindLocation(ssp);
                CompletionState state;
                var             tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                var lookupresult = new List <IXSymbol>();
                lookupresult.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true));
                var lastToken = tokenList.LastOrDefault();
                //
                if (lookupresult.Count > 0)
                {
                    var element   = lookupresult[0];
                    var qiContent = new List <object>();

                    if (element.Kind == Kind.Constructor && lastToken?.Type != XSharpLexer.CONSTRUCTOR && lastToken?.Type != XSharpLexer.LPAREN)
                    {
                        if (element.Parent != null)
                        {
                            var xtype = element.Parent as IXTypeSymbol;
                            var qitm  = new XTypeAnalysis(xtype);
                            AddImage(qiContent, qitm.Image);
                            var description = new ClassifiedTextElement(qitm.WPFDescription);
                            qiContent.Add(description);
                        }
                    }
                    else if (element is IXMemberSymbol mem)
                    {
                        QuickInfoTypeMember qitm = new QuickInfoTypeMember(mem);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    else if (element is IXVariableSymbol var)
                    {
                        QuickInfoVariable qitm = new QuickInfoVariable(var);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    else if (element is IXTypeSymbol xtype)
                    {
                        var qitm = new XTypeAnalysis(xtype);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    else
                    {
                        var qitm = new XAnalysis(element);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(null);
                    }
                    var result   = new ContainerElement(ContainerElementStyle.Wrapped, qiContent);
                    var line     = ssp.GetContainingLine();
                    var lineSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive);

                    return(new QuickInfoItem(lineSpan, result));
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "XSharpQuickInfo.AugmentQuickInfoSession failed : ");
            }
            finally
            {
                ModelWalker.Resume();
            }
            await session.DismissAsync();

            return(null);
        }
Beispiel #45
0
        public void GetTokens_GraphCycleTypeMaxDepthFalsePositive_ThrowsGraphCycleException()
        {
            // input from fail18.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                new []
                {
                    new []
                    {
                        new []
                        {
                            new []
                            {
                                new []
                                {
                                    new []
                                    {
                                        new []
                                        {
                                            new []
                                            {
                                                new []
                                                {
                                                    new []
                                                    {
                                                        new []
                                                        {
                                                            new []
                                                            {
                                                                new []
                                                                {
                                                                    new []
                                                                    {
                                                                        new []
                                                                        {
                                                                            new []
                                                                            {
                                                                                new []
                                                                                {
                                                                                    new []
                                                                                    {
                                                                                        new []
                                                                                        {
                                                                                            "Too deep"
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.MaxDepth,
                MaxDepth    = 19
            });

            GraphCycleException ex = Assert.Throws <GraphCycleException>(
                delegate
            {
                walker.GetTokens(input).ToArray();
            });

            Assert.Equal(GraphCycleType.MaxDepth, ex.CycleType);
        }
Beispiel #46
0
        internal static void GotoDefn(ITextView TextView)
        {
            try
            {
                if (XSettings.DisableGotoDefinition)
                {
                    return;
                }
                var file = TextView.TextBuffer.GetFile();
                if (file == null || file.XFileType != XFileType.SourceCode)
                {
                    return;
                }
                WriteOutputMessage("CommandFilter.GotoDefn()");
                ModelWalker.Suspend();


                var snapshot = TextView.TextBuffer.CurrentSnapshot;

                // We don't want to lex the buffer. So get the tokens from the last lex run
                // and when these are too old, then simply bail out
                var tokens = TextView.TextBuffer.GetDocument();
                if (tokens != null)
                {
                    if (tokens.SnapShot.Version != snapshot.Version)
                    {
                        return;
                    }
                }
                string currentNS = TextView.FindNamespace();
                var    location  = TextView.FindLocation();
                var    state     = CompletionState.General | CompletionState.Types | CompletionState.Namespaces;
                var    tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);

                // LookUp for the BaseType, reading the TokenList (From left to right)
                var result = new List <IXSymbol>();

                result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed));
                //
                Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
                if (result.Count > 0)
                {
                    var element = result[0];
                    if (element is XSourceEntity source)
                    {
                        source.OpenEditor();
                    }
                    else if (element is XPETypeSymbol petype)
                    {
                        GotoSystemType(TextView, petype, petype);
                    }
                    else if (element is XPEMemberSymbol pemember)
                    {
                        var petype2 = pemember.Parent as XPETypeSymbol;
                        GotoSystemType(TextView, petype2, pemember);
                    }
                    return;
                }
                //
                if (tokenList.Count > 1)
                {
                    // try again with just the last element in the list
                    var token = tokenList[tokenList.Count - 1];
                    tokenList.Clear();
                    tokenList.Add(token);
                    location = location.With(currentNS);
                    result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out notProcessed));
                }
                if (result.Count > 0)
                {
                    var element = result[0];
                    if (element is XSourceEntity source)
                    {
                        source.OpenEditor();
                    }
                    //else
                    //{
                    //    openInObjectBrowser(element.FullName);
                    //}
                    //return;
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "Goto failed");
            }
            finally
            {
                ModelWalker.Resume();
            }
        }