/// <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 PropertyIdentifierWithInvalidCharactersIsInvalid() { Assert.AreEqual(SgfPropertyType.Invalid, SgfProperty.GetPropertyType(":-")); }
public void ValidUnknownPropertyWithMoreLettersIsRecognized() { Assert.AreEqual(SgfPropertyType.Unknown, SgfProperty.GetPropertyType("SSSSSS")); }
public void PropertyIdentifierWithNonCaptialLettersIsInvalid() { Assert.AreEqual(SgfPropertyType.Invalid, SgfProperty.GetPropertyType("ab")); }
public void NoTypePropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.NoType, SgfProperty.GetPropertyType("LN")); }
public void DeprecatedPropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.Deprecated, SgfProperty.GetPropertyType("RG")); }
public void SetupPropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.Setup, SgfProperty.GetPropertyType("AB")); }
public void MovePropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.Move, SgfProperty.GetPropertyType("DO")); }
public void RootPropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.Root, SgfProperty.GetPropertyType("CA")); }
public void GameInfoPropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.GameInfo, SgfProperty.GetPropertyType("ON")); }
public void NullPropertyTypeIsInvalid() { Assert.AreEqual(SgfPropertyType.Invalid, SgfProperty.GetPropertyType(null)); }