/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using System.IO; namespace Avro.Test.Utils { [TestFixture] public class CaseFinderTests { [Test] public void TestBadDocLabel1() { List result = new List(); Assert.Throws( () => CaseFinder.Find(Mk("< result = new List(); Assert.Throws( () => CaseFinder.Find(Mk("< result = new List(); Assert.Throws( () => CaseFinder.Find(Mk("< result = new List(); Assert.Throws( () => CaseFinder.Find(Mk("< expectedOutput) { List result = new List(); CaseFinder.Find(Mk(input), label, result); Assert.True(Eq(result, expectedOutput), Pr(result)); } private static List OutputTestCases() { List result = new List(); result.Add(new Object[] { "", "foo", new List { } }); result.Add(new Object[] { "< { new object[] {"a","b"} } }); result.Add(new Object[] { "< { new object[] { "a", "b" } } }); result.Add(new Object[] { "< { new object[] { "a", "b" } } }); result.Add(new Object[] { "< { new object[] { "a", "b" } } }); result.Add(new Object[] { "// This is a test\n< { new object[] { "a", "b" } } }); result.Add(new Object[] { "< { new object[] { "a", "b" } } }); result.Add(new Object[] { "< { new object[] { "a", "b\n" } } }); result.Add(new Object[] { "< { new object[] { "a", "\n b \n" } } }); result.Add(new Object[] { "< { new object[] { "a", "b" }, new object[] { "c", "d" } } }); result.Add(new Object[] { "< { new object[] { "a", "b" }, new object[] { "c", "d" } } }); result.Add(new Object[] { "< { new object[] { "a", "z" } } }); result.Add(new Object[] { "< { new object[] { "a", null }, new object[] { "c", null }, new object[] { "e", null } } }); return result; } private StreamReader Mk(string s) { byte[] byteArray = Encoding.ASCII.GetBytes(s); MemoryStream stream = new MemoryStream(byteArray); return new StreamReader(stream); } private string Pr(List t) { StringBuilder sb = new StringBuilder(); sb.Append("{ "); bool firstTime = true; foreach (var obj in t) { if (!firstTime) { sb.Append(", "); } else { firstTime = false; } sb.Append("{ \"").Append(obj[0]).Append("\", \"").Append(obj[1]).Append("\" }"); } sb.Append("}"); return sb.ToString(); } private bool Eq(List l1, List l2) { if (l1 == null || l2 == null) { return l1 == l2; } if (l1.Count != l2.Count) { return false; } for (int i = 0; i < l1.Count; i++) { if (!ArraysEqual(l1[i], l2[i])) { return false; } } return true; } static bool ArraysEqual(T[] a1, T[] a2) { if (ReferenceEquals(a1, a2)) return true; if (a1 == null || a2 == null) return false; if (a1.Length != a2.Length) return false; EqualityComparer comparer = EqualityComparer.Default; for (int i = 0; i < a1.Length; i++) { if (!comparer.Equals(a1[i], a2[i])) return false; } return true; } } }