Ejemplo n.º 1
0
        private static string HashLogToString(IIonValue hashLog)
        {
            bool          multipleEntries = hashLog.Count > 1;
            StringBuilder sb = new StringBuilder();

            sb.Append("(");
            IEnumerator <IIonValue> enumerator = hashLog.GetEnumerator();

            while (enumerator.MoveNext())
            {
                IIonValue hashCall = enumerator.Current;
                if (multipleEntries)
                {
                    sb.Append("\n  ");
                }

                foreach (SymbolToken annotation in hashCall.GetTypeAnnotations())
                {
                    sb.Append(annotation.Text).Append("::");
                }

                sb.Append("(");
                int cnt = 0;
                IEnumerator <IIonValue> bytesEnum = hashCall.GetEnumerator();
                while (bytesEnum.MoveNext())
                {
                    IIonValue i = bytesEnum.Current;
                    if (cnt++ > 0)
                    {
                        sb.Append(" ");
                    }

                    sb.Append(i.IntValue.ToString("x2"));
                }

                sb.Append(")");
            }

            if (multipleEntries)
            {
                sb.Append("\n");
            }

            sb.Append(")");
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public IEnumerable <object[]> GetData(MethodInfo methodInfo)
        {
            var dataList = new List <object[]>();

            var loader          = IonLoader.Default;
            var file            = DirStructure.IonHashDotnetTestFile("ion_hash_tests.ion");
            var ionHashTests    = loader.Load(file);
            var testsEnumerator = ionHashTests.GetEnumerator();

            while (testsEnumerator.MoveNext())
            {
                IIonValue testCase = testsEnumerator.Current;

                string testName = "unknown";
                if (testCase.ContainsField("ion"))
                {
                    testName = testCase.GetField("ion").ToPrettyString();
                }

                IReadOnlyCollection <SymbolToken> annotations = testCase.GetTypeAnnotations();
                if (annotations.Count > 0)
                {
                    testName = annotations.ElementAt(0).Text;
                }

                IIonValue expect           = testCase.GetField("expect");
                var       expectEnumerator = expect.GetEnumerator();
                while (expectEnumerator.MoveNext())
                {
                    IIonValue expectedHashLog = expectEnumerator.Current;
                    String    hasherName      = expectedHashLog.FieldNameSymbol.Text;

                    object[] data = new object[] {
                        hasherName.Equals("identity") ? testName : testName + "." + hasherName,
                        testCase,
                        expectedHashLog,
                        TestIonHasherProvider.GetInstance(hasherName)
                    };
                    dataList.Add(data);
                }
            }

            return(dataList);
        }
Ejemplo n.º 3
0
        private static IIonValue FilterHashLog(IIonValue actualHashLog, IIonValue expectedHashLog)
        {
            HashSet <string>        methodCalls = new HashSet <string>();
            IEnumerator <IIonValue> enumerator  = expectedHashLog.GetEnumerator();

            while (enumerator.MoveNext())
            {
                IIonValue v = enumerator.Current;
                foreach (SymbolToken annotation in v.GetTypeAnnotations())
                {
                    methodCalls.Add(annotation.Text);
                }
            }

            IValueFactory valueFactory = new ValueFactory();
            IIonValue     result       = valueFactory.NewEmptySexp();

            if (methodCalls.Count == 1 && methodCalls.Contains("final_digest"))
            {
                IIonValue finalDigest = actualHashLog.GetElementAt(actualHashLog.Count - 1);
                finalDigest.ClearAnnotations();
                finalDigest.AddTypeAnnotation("final_digest");
                result.Add(finalDigest);
            }
            else
            {
                enumerator = actualHashLog.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    IIonValue v          = enumerator.Current;
                    String    methodCall = v.GetTypeAnnotations().ElementAt(0).Text;
                    if (methodCalls.Contains(methodCall))
                    {
                        result.Add(v);
                    }
                }
            }

            return(result);
        }