fork(4) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string correct = "VIEW start page";
  10. string incorrect = "VIEW something else";
  11. string error = "something else";
  12.  
  13. checkInput(correct);
  14. checkInput(incorrect);
  15. checkInput(error);
  16. }
  17.  
  18. static void checkInput(string input) {
  19. Console.Write("Testing '{0}'...\n",input);
  20. Match match = Regex.Match(input, @"^VIEW\s+(?:(start\s+page|end)|(.*))$");
  21.  
  22. if (match.Success) {
  23. if ( match.Groups[1].Success)
  24. Console.Write("Success!\n");
  25. if ( match.Groups[2].Success)
  26. Console.Write("Expected start page or end after VIEW\n");
  27. } else {
  28. Console.Write("usage: VIEW [start page|end]\n");
  29. }
  30. }
  31. }
Success #stdin #stdout 0.12s 24824KB
stdin
Standard input is empty
stdout
Testing 'VIEW start page'...
Success!
Testing 'VIEW something else'...
Expected start page or end after VIEW
Testing 'something else'...
usage: VIEW [start page|end]