public void ValidPropertyWithValidComposeValuesIsCreatedSuccessfully() { var sgfProperty = SgfProperty.ParseValuesAndCreate("LB", "ab:Hello world!", "ac:Goodbye!"); Assert.AreEqual("LB", sgfProperty.Identifier); Assert.AreEqual(2, sgfProperty.ComposeValues <SgfPoint, string>().Count()); }
public void ValidPropertyWithValidValuesIsCreatedSuccessfully() { var sgfProperty = SgfProperty.ParseValuesAndCreate("AW", "ab", "ac", "bb", "bc"); Assert.AreEqual("AW", sgfProperty.Identifier); Assert.AreEqual(4, sgfProperty.SimpleValues <SgfPointRectangle>().Count()); }
/// <summary> /// Parses a SGF property /// </summary> /// <param name="input">Input</param> /// <param name="inputPosition">Current input position</param> /// <returns>SGF property</returns> private SgfProperty ParseProperty(string input, ref int inputPosition) { if (!char.IsLetter(input[inputPosition]) || !char.IsUpper(input[inputPosition])) { throw new SgfParseException($"No valid property starts on input position {inputPosition}"); } //get property name StringBuilder identifierBuilder = new StringBuilder(); while (inputPosition < input.Length && input[inputPosition] != '[') { identifierBuilder.Append(input[inputPosition]); inputPosition++; } string identifier = identifierBuilder.ToString(); var propertyType = SgfProperty.GetPropertyType(identifier); if (propertyType == SgfPropertyType.Invalid) { throw new SgfParseException($"Invalid SGF property identifier encountered at {inputPosition}"); } //add warning for deprecated property if (propertyType == SgfPropertyType.Deprecated) { _warnings.Add(new SgfParseWarning(SgfParseWarningKind.DeprecatedProperty, inputPosition)); } //add warning for unknown property if (propertyType == SgfPropertyType.Unknown) { _warnings.Add(new SgfParseWarning(SgfParseWarningKind.UnknownProperty, inputPosition)); } SkipInputWhitespace(input, ref inputPosition); List <string> values = new List <string>(); //parse values while (inputPosition < input.Length && input[inputPosition] == '[') { string value = ParseValue(input, ref inputPosition); values.Add(value); SkipInputWhitespace(input, ref inputPosition); } //at least one value required if (values.Count == 0) { throw new SgfParseException($"No property values provided for property at {inputPosition}"); } return(SgfProperty.ParseValuesAndCreate(identifier, values.ToArray())); }
public void ValueTypeOfListPropertyIsCorrectlyReturned() { var sgfProperty = SgfProperty.ParseValuesAndCreate("AW", "ab", "ac", "bb", "bc"); Assert.AreEqual(SgfValueType.PointRectangle, sgfProperty.ValueType); }