Ejemplo n.º 1
0
 public void HasMoreTokensTest()
 {
     string str = "Fhqwhgads";
     StringTokenizer tok = new StringTokenizer(str);
     Assert.IsTrue(tok.HasMoreTokens());
     tok.NextToken();
     Assert.IsFalse(tok.HasMoreTokens());
     tok = new StringTokenizer("");
     Assert.IsFalse(tok.HasMoreTokens());
 }
Ejemplo n.º 2
0
 public void NextTokenTest()
 {
     string str = "The first thing we do, let's kill all the lawyers.";
     StringTokenizer tok = new StringTokenizer(str);
     Assert.IsTrue(tok.NextToken().Equals("The"));
     Assert.IsTrue(tok.NextToken().Equals("first"));
     Assert.IsTrue(tok.NextToken().Equals("thing"));
     Assert.IsTrue(tok.NextToken().Equals("we"));
     Assert.IsTrue(tok.NextToken().Equals("do,"));
     Assert.IsTrue(tok.NextToken().Equals("let's"));
     Assert.IsTrue(tok.NextToken().Equals("kill"));
     Assert.IsTrue(tok.NextToken().Equals("all"));
     Assert.IsTrue(tok.NextToken().Equals("the"));
     Assert.IsTrue(tok.NextToken().Equals("lawyers."));
     Assert.IsTrue(tok.NextToken() == null);
     str = "I doubt, therefore I might be.";
     tok = new StringTokenizer(str, ",");
     Assert.IsTrue(tok.NextToken().Equals("I doubt"));
     Assert.IsTrue(tok.NextToken().Equals(" therefore I might be."));
     Assert.IsTrue(tok.NextToken() == null);
     str = "Meow mix, meow mix, please deliver!";
     Regex pattern = new Regex(", ");
     tok = new StringTokenizer(str, pattern);
     Assert.IsTrue(tok.NextToken().Equals("Meow mix"));
     Assert.IsTrue(tok.NextToken().Equals("meow mix"));
     Assert.IsTrue(tok.NextToken().Equals("please deliver!"));
     Assert.IsTrue(tok.NextToken() == null);
     str = "aaa";
     pattern = new Regex("aa");
     tok = new StringTokenizer(str, pattern);
     Assert.IsTrue(tok.NextToken().Equals("a"));
     tok = new StringTokenizer("");
     Assert.IsTrue(tok.NextToken() == null);
     tok = new StringTokenizer("Meow", "!");
     Assert.IsTrue(tok.NextToken().Equals("Meow"));
     Assert.IsTrue(tok.NextToken() == null);
 }
Ejemplo n.º 3
0
 public void CountTokensTest()
 {
     string str = "1 2 3 4 5";
     StringTokenizer tok = new StringTokenizer(str);
     Assert.AreEqual(tok.CountTokens(), 5);
     str = "1 2\n\f3 \t4 5 ";
     tok = new StringTokenizer(str);
     Assert.AreEqual(tok.CountTokens(), 5);
     tok = new StringTokenizer("");
     Assert.AreEqual(tok.CountTokens(), 0);
     str = "0 0 1 2 3 4 5";
     tok = new StringTokenizer(str);
     tok.NextToken();
     tok.NextToken();
     Assert.AreEqual(tok.CountTokens(), 5);
 }