Advertisement
Guest User

Untitled

a guest
May 20th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public static AOption processOptionToken(ParsingContext context, IDocumentTemplate template, OptionToken optionToken)
  2. {
  3. if (context.CurrentSection == null)
  4. throw new FormatException($"Option \"{optionToken.Identifier}\" does not belong to any section");
  5.  
  6. // TODO option requires separate value parsing
  7. // at first we try to get the type from teplate. If its not there, then we use string.
  8.  
  9.  
  10. var optionType = template.GetOptionTypeOrThrow(context.CurrentSection.Identifier, optionToken.Identifier);
  11.  
  12. var option = parseOptionAccordingToType(optionToken, optionType);
  13. //context.AddOption(option);
  14. return option;
  15. }
  16.  
  17.  
  18. //test
  19. [TestMethod]
  20. public void ParseStringValues()
  21. {
  22. ITokenParser tokenParser = new TokenParser();
  23. var parserResult = tokenParser.TryParseOption("Options=this,is,string", 1, out OptionToken optionToken);
  24. var parsingContext = new ParsingContext(new WinIniDocument());
  25. ConfigLoader.Builders.Templates.DocumentTemplate.RelaxedDocumentTemplate doc = new ConfigLoader.Builders.Templates.DocumentTemplate.RelaxedDocumentTemplate();
  26. AOption aopt = OptionParser.processOptionToken(parsingContext, doc, optionToken);
  27. StringOption sa = (StringOption)aopt;
  28.  
  29. Assert.AreEqual("Options", sa.Identifier);
  30. Assert.AreEqual("this", sa[0]);
  31. Assert.AreEqual("is", sa[1]);
  32. Assert.AreEqual("string", sa[2]);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement