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())); }
/// <summary> /// Serializes a SGF property /// </summary> /// <param name="property">SGF property to serialize</param> /// <returns>Serialized SGF property</returns> private string SerializeProperty(SgfProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } StringBuilder builder = new StringBuilder(); builder.Append(property.Identifier); foreach (var propertyValue in property.PropertyValues) { builder.Append(SerializePropertyValue(propertyValue)); } return(builder.ToString()); }
/// <summary> /// Parses a SGF node /// </summary> /// <param name="input">Input</param> /// <param name="inputPosition">Current input position</param> /// <returns>SGF node</returns> private SgfNode ParseNode(string input, ref int inputPosition) { if (input[inputPosition] != ';') { throw new SgfParseException($"No node starts on input position {inputPosition}"); } inputPosition++; SkipInputWhitespace(input, ref inputPosition); List <SgfProperty> properties = new List <SgfProperty>(); while (inputPosition < input.Length && char.IsLetter(input[inputPosition])) { SgfProperty property = ParseProperty(input, ref inputPosition); properties.Add(property); SkipInputWhitespace(input, ref inputPosition); } return(new SgfNode(properties)); }
public void SetupPropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.Setup, SgfProperty.GetPropertyType("AB")); }
public void ValueTypeOfListPropertyIsCorrectlyReturned() { var sgfProperty = SgfProperty.ParseValuesAndCreate("AW", "ab", "ac", "bb", "bc"); Assert.AreEqual(SgfValueType.PointRectangle, sgfProperty.ValueType); }
public void PropertyIdentifierWithNonCaptialLettersIsInvalid() { Assert.AreEqual(SgfPropertyType.Invalid, SgfProperty.GetPropertyType("ab")); }
public void PropertyIdentifierWithInvalidCharactersIsInvalid() { Assert.AreEqual(SgfPropertyType.Invalid, SgfProperty.GetPropertyType(":-")); }
public void DeprecatedPropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.Deprecated, SgfProperty.GetPropertyType("RG")); }
public void ValidUnknownPropertyWithMoreLettersIsRecognized() { Assert.AreEqual(SgfPropertyType.Unknown, SgfProperty.GetPropertyType("SSSSSS")); }
public void ValueTypeOfNonePropertyIsCorrectlyReturned() { var sgfProperty = new SgfProperty("KO"); Assert.AreEqual(SgfValueType.None, sgfProperty.ValueType); }
public void NoTypePropertyIsRecognized() { Assert.AreEqual(SgfPropertyType.NoType, SgfProperty.GetPropertyType("LN")); }
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)); }
public void NullPropertyIdentiferIsInvalid() { Assert.IsFalse(SgfProperty.IsPropertyIdentifierValid(null)); }