private void consume(HaystackToken expected) { if (expected != null) { verify(expected); } m_tokCur = m_tokPeek; m_curVal = m_peekVal; m_tokPeek = m_tokenizer.next(); m_peekVal = m_tokenizer.Val; }
private void verifyToks(string zinc, object[] toks) { List <object> acc = new List <object>(); // Streamreader thing MemoryStream msRdr = new MemoryStream(Encoding.UTF8.GetBytes(zinc)); HaystackTokenizer t = new HaystackTokenizer(new StreamReader(msRdr)); while (true) { HaystackToken x = t.next(); Assert.AreEqual(x, t.Token); if (x == HaystackToken.eof) { break; } acc.Add(t.Token); acc.Add(t.Val); } object[] actual = acc.ToArray(); // NOTE: this requires higher than .NET 3.5 for SequenceEqual // SequenceEqual will not work for this bool bEquals = true; if (toks.Length != actual.Length) { bEquals = false; } else { for (int iIndex = 0; iIndex < toks.Length; iIndex++) { if (toks[iIndex] == null) { if (acc[iIndex] != null) { bEquals = false; break; } } else if (acc[iIndex] == null) { bEquals = false; break; } else if (toks[iIndex].ToString().CompareTo(actual[iIndex].ToString()) != 0) { bEquals = false; break; } } } if (!bEquals) { string toksStr = ""; string accStr = ""; bool first = true; foreach (object tok in toks) { if (!first) { toksStr += ","; } toksStr += "[" + tok.ToString() + "]"; first = false; } first = true; foreach (object tok in actual) { if (!first) { accStr += ","; } accStr += "[" + tok.ToString() + "]"; first = false; } // Sending it to debug and trace - vs2013 and vs2017 change the use of testcontext making // TestContext.writeline not a reliable output Debug.WriteLine("expected: " + toksStr); Trace.WriteLine("expected: " + toksStr); Debug.WriteLine("actual: " + accStr); Trace.WriteLine("actual: " + accStr); } }