Beispiel #1
0
        public void TestIonReaderContract()
        {
            FileInfo  file         = DirStructure.IonHashDotnetTestFile("ion_hash_tests.ion");
            IIonValue ionHashTests = loader.Load(file);

            IIonReader ir = IonReaderBuilder.Build(ionHashTests);

            IIonHashReader ihr = IonHashReaderBuilder
                                 .Standard()
                                 .WithHasherProvider(new IdentityIonHasherProvider())
                                 .WithReader(IonReaderBuilder.Build(ionHashTests))
                                 .Build();

            ReaderCompare.Compare(ir, ihr);
        }
        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.GetTypeAnnotationSymbols();
                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);
        }
Beispiel #3
0
            public IEnumerable <object[]> GetData(MethodInfo methodInfo)
            {
                List <object[]> list = new List <object[]>();

                try
                {
                    var file       = DirStructure.IonHashTestFile("big_list_of_naughty_strings.txt");
                    var fileStream = file.OpenRead();
                    using (StreamReader sr = new StreamReader(fileStream))
                    {
                        while (!sr.EndOfStream)
                        {
                            String line = sr.ReadLine();
                            if (line.StartsWith("#") || string.IsNullOrEmpty(line))
                            {
                                continue;
                            }
                            TestValue tv = new TestValue(line);

                            list.Add(new object[] { tv, tv.AsSymbol() });
                            list.Add(new object[] { tv, tv.AsString() });
                            list.Add(new object[] { tv, tv.AsLongString() });
                            list.Add(new object[] { tv, tv.AsClob() });
                            list.Add(new object[] { tv, tv.AsBlob() });

                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsSymbol() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsString() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsLongString() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsClob() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsBlob() });

                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsSymbol() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsString() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsLongString() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsClob() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsBlob() + "}" });

                            if (tv.IsValidIon())
                            {
                                list.Add(new object[] { tv, tv.AsIon() });
                                list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsIon() });
                                list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsIon() + "}" });
                                list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsSymbol() + "::" + tv.AsIon() + "}" });
                            }

                            // list
                            list.Add(new object[]
                            {
                                tv,
                                tv.AsSymbol() + "::["
                                + tv.AsSymbol() + ", "
                                + tv.AsString() + ", "
                                + tv.AsLongString() + ", "
                                + tv.AsClob() + ", "
                                + tv.AsBlob() + ", "
                                + (tv.IsValidIon() ? tv.AsIon() : "")
                                + "]"
                            });

                            // sexp
                            list.Add(new object[]
                            {
                                tv,
                                tv.AsSymbol() + "::("
                                + tv.AsSymbol() + " "
                                + tv.AsString() + " "
                                + tv.AsLongString() + " "
                                + tv.AsClob() + " "
                                + tv.AsBlob() + " "
                                + (tv.IsValidIon() ? tv.AsIon() : "")
                                + ")"
                            });

                            // multiple annotations
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsSymbol() + "::" + tv.AsSymbol() + "::" + tv.AsString() });
                        }
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("The file could not be read:");
                    Console.WriteLine(e.Message);
                }
                return(list);
            }