internal static void CheckResetException(Analyzer a, string input)
{
TokenStream ts = a.TokenStream("bogus", new StringReader(input));
try
{
if (ts.IncrementToken())
{
ts.ReflectAsString(false);
Assert.Fail("didn't get expected exception when reset() not called");
}
}
catch (InvalidOperationException expected)
{
//ok
}
catch (AssertionException expected)
{
// ok: MockTokenizer
Assert.IsTrue(expected.Message != null && expected.Message.Contains("wrong state"), expected.Message);
}
catch (Exception unexpected)
{
//unexpected.printStackTrace(System.err);
Console.Error.WriteLine(unexpected.StackTrace);
Assert.Fail("got wrong exception when reset() not called: " + unexpected);
}
finally
{
// consume correctly
ts.Reset();
while (ts.IncrementToken())
{
}
ts.End();
ts.Dispose();
}
// check for a missing Close()
ts = a.TokenStream("bogus", new StringReader(input));
ts.Reset();
while (ts.IncrementToken())
{
}
ts.End();
try
{
ts = a.TokenStream("bogus", new StringReader(input));
Assert.Fail("didn't get expected exception when Close() not called");
}
catch (Exception)
{
// ok
}
finally
{
ts.Dispose();
}
}