/// <summary> /// Creates console argument reader on given token /// </summary> /// <param name="tokenizer"></param> /// <param name="mode"></param> public ConsoleArgumentReader(ConsoleArgumentTokenizer tokenizer, ConsoleArgumentReaderMode mode = ConsoleArgumentReaderMode.Default) { if (null == tokenizer) { throw new ConsoleArgumentsReaderException("tokenizer not defined"); } _tokenizer = tokenizer; Mode = mode; }
public void DetectsInvalidArgumentStrings(string invalidarg) { Assert.Throws <ConsoleArgumentTokenizer.ConsoleTokenizerException>(() => { var t = ConsoleArgumentTokenizer.Create(invalidarg); while ((t.Next()).Type != ConsoleArgumentTokenizer.TokenType.Null) { } }); }
public void CanParseStringWithEscapes(string argstring, string result) { var t = ConsoleArgumentTokenizer.Create("\"" + argstring + "\""); var fst = t.Next(); var sec = t.Next(); Assert.AreEqual(ConsoleArgumentTokenizer.Token.Null, sec, "does not sygnal end of parsing"); Assert.AreEqual(ConsoleArgumentTokenizer.TokenType.Value, fst.Type, "invalid type returned " + fst.Type); Assert.AreEqual(result, fst.Value, "invalid value returned " + fst.Value); }
public void CanParseSimpleValues(string argstring) { var t = ConsoleArgumentTokenizer.Create(argstring); var fst = t.Next(); var sec = t.Next(); Assert.AreEqual(ConsoleArgumentTokenizer.Token.Null, sec, "does not sygnal end of parsing"); Assert.AreEqual(ConsoleArgumentTokenizer.TokenType.Value, fst.Type, "invalid type returned " + fst.Type); Assert.AreEqual(argstring, fst.Value, "invalid value returned " + fst.Value); }
public void CanParseSingleNamedArgument(string argstring, string name, string value) { var t = ConsoleArgumentTokenizer.Create(argstring); var n = t.Next(); var v = t.Next(); var sec = t.Next(); Assert.AreEqual(ConsoleArgumentTokenizer.Token.Null, sec, "does not sygnal end of parsing " + sec.Type + " : " + sec.Value); Assert.AreEqual(ConsoleArgumentTokenizer.TokenType.Name, n.Type, "invalid type returned for name" + n.Type); Assert.AreEqual(ConsoleArgumentTokenizer.TokenType.Value, v.Type, "invalid type returned for value" + v.Type); Assert.AreEqual(name, n.Value, "invalid name returned " + n.Value); Assert.AreEqual(value, v.Value, "invalid value returned " + v.Value); }
public void ComplexTestOnLongCall() { const string test = "myfile.txt \"other file.txt\" --copy --dir /mydir --override -- pattern"; var testarray = new[] { new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Value, "myfile.txt"), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Value, "other file.txt"), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Name, "copy"), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Name, "dir"), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Value, "/mydir"), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Name, "override"), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Name, ""), new ConsoleArgumentTokenizer.Token(ConsoleArgumentTokenizer.TokenType.Value, "pattern"), }; var result = ConsoleArgumentTokenizer.Create(test).Read().ToArray(); CollectionAssert.AreEqual(testarray, result); }
/// <summary> /// Creates console argument reader over string enumeration /// </summary> /// <param name="arglines"></param> /// <param name="mode"></param> public ConsoleArgumentReader(IEnumerable <string> arglines, ConsoleArgumentReaderMode mode = ConsoleArgumentReaderMode.Default) { _tokenizer = ConsoleArgumentTokenizer.Create(arglines); Mode = mode; }
/// <summary> /// Creates console argument reader over string /// </summary> /// <param name="argline"></param> /// <param name="mode"></param> public ConsoleArgumentReader(string argline, ConsoleArgumentReaderMode mode = ConsoleArgumentReaderMode.Default) { _tokenizer = ConsoleArgumentTokenizer.Create(argline); Mode = mode; }