Exemple #1
0
        public void PullDownNamespaces(SCG.IEnumerable <SCG.IEnumerable <string> > Namespaces)
        {
            // collect everything into a non lazy structure first
            var insertions = new SCG.List <SuggestionTree <Pay> .IntermFResult.single_suggestion>();

            foreach (var ns in Namespaces)
            {
                var namespace_node_res = FindSequence(ns.ToArray(), last_query_is_exact: true);
                if (namespace_node_res.type == SuggestionTree <Pay> .FRType.unique_fit)
                {
                    SuggestionTree <Pay> namespaceNode = namespace_node_res.suggs[0].val;
                    foreach (var single_sugg  in namespaceNode.FindAllWithPayload())
                    {
                        insertions.Add(single_sugg);
                    }
                }
                else
                {
                    throw new Exception("no exact match for Namespace-pulling : " + string.Join(".", ns.ToArray()));    // <- turn this into consumer catchable Exception as soon as user defined "usings" are a thing
                }
            }
            //  second iteration to not intertwine access and modifying - and avoid reasoning headaches
            foreach (var single_sugg in insertions)
            {
                Add(single_sugg.steps, single_sugg.val.payload);      // Add overrides the payload
            }
        }
        public void TestToString()
        {
            var set = new J2N.Collections.Generic.HashSet <IDictionary <string, string> >
            {
                new SCG.Dictionary <string, string> {
                    { "1", "one" }, { "2", "two" }, { "3", "three" }
                },
                new SCG.Dictionary <string, string> {
                    { "4", "four" }, { "5", "five" }, { "6", "six" }
                },
                new SCG.Dictionary <string, string> {
                    { "7", "seven" }, { "8", "eight" }, { "9", "nine" }
                },
            };
            var setExpected = "[{1=one, 2=two, 3=three}, {4=four, 5=five, 6=six}, {7=seven, 8=eight, 9=nine}]";

            Assert.AreEqual(setExpected, CollectionUtil.ToString(set, StringFormatter.InvariantCulture));


            var set2 = new J2N.Collections.Generic.HashSet <ISet <string> >
            {
                new J2N.Collections.Generic.HashSet <string> {
                    "1", "2", "3"
                },
                new J2N.Collections.Generic.HashSet <string> {
                    "4", "5", "6"
                },
                new System.Collections.Generic.HashSet <string> {
                    "7", "8", "9"
                },
            };
            var set2Expected = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]";

            Assert.AreEqual(set2Expected, CollectionUtil.ToString(set2, StringFormatter.InvariantCulture));


            var map = new SCG.Dictionary <string, IDictionary <int, double> >
            {
                { "first", new SCG.Dictionary <int, double> {
                      { 1, 1.23 }, { 2, 2.23 }, { 3, 3.23 }
                  } },
                { "second", new SCG.Dictionary <int, double> {
                      { 4, 1.24 }, { 5, 2.24 }, { 6, 3.24 }
                  } },
                { "third", new SCG.Dictionary <int, double> {
                      { 7, 1.25 }, { 8, 2.25 }, { 9, 3.25 }
                  } },
            };
            var mapExpectedPortuguese = "{first={1=1,23, 2=2,23, 3=3,23}, second={4=1,24, 5=2,24, 6=3,24}, third={7=1,25, 8=2,25, 9=3,25}}";
            var mapExpectedUSEnglish  = "{first={1=1.23, 2=2.23, 3=3.23}, second={4=1.24, 5=2.24, 6=3.24}, third={7=1.25, 8=2.25, 9=3.25}}";

            Assert.AreEqual(mapExpectedPortuguese, CollectionUtil.ToString(map, new StringFormatter(new CultureInfo("pt"))));
            Assert.AreEqual(mapExpectedUSEnglish, CollectionUtil.ToString(map, new StringFormatter(new CultureInfo("en-US"))));

            var array = new SCG.List <SCG.Dictionary <string, string> >[]
            {
                new SCG.List <SCG.Dictionary <string, string> > {
                    new SCG.Dictionary <string, string> {
                        { "foo", "bar" }, { "foobar", "barfoo" }
                    }
                },
                new SCG.List <SCG.Dictionary <string, string> > {
                    new SCG.Dictionary <string, string> {
                        { "orange", "yellow" }, { "red", "black" }
                    },
                    new SCG.Dictionary <string, string> {
                        { "rain", "snow" }, { "sleet", "sunshine" }
                    }
                },
            };
            var arrayExpected = "[[{foo=bar, foobar=barfoo}], [{orange=yellow, red=black}, {rain=snow, sleet=sunshine}]]";

            Assert.AreEqual(arrayExpected, CollectionUtil.ToString(array, StringFormatter.InvariantCulture));
        }