public void StandardValidator_FormatStyle_Attributes() { Core.File file; Segment segment; SpanningCodeEnd end; SpanningCodeStart start; Unit unit; segment = new Segment("sx"); segment.Source = new Source(); unit = new Unit("ux"); unit.Resources.Add(segment); file = new Core.File("fx"); file.Containers.Add(unit); this.DeserializeDocument(); this._document.Files.Add(file); start = new SpanningCodeStart(); start.Id = "sc1"; segment.Source.Text.Add(start); end = new SpanningCodeEnd(); end.Isolated = false; end.FormatStyle = FormatStyleValue.Anchor; end.StartReference = start.Id; segment.Source.Text.Add(end); Console.WriteLine("Test fs with ec not isolated."); this.VerifyValidationException(ValidationError.FormatStyleWithSpanEndNotIsolated); end.Isolated = true; end.StartReference = null; start.Isolated = true; Console.WriteLine("Test subfs without fs."); end.FormatStyle = null; end.SubFormatStyle.Add("key", "value"); this.VerifyValidationException(ValidationError.FormatStyleSubFormatWithoutFormat); Console.WriteLine("Test with valid data."); end.FormatStyle = FormatStyleValue.Anchor; StandardValidatorTests._validator.Validate(this._document); }
public void XliffWriter_SpanningCodeEnd() { File file; Segment segment; SpanningCodeEnd span; Unit unit; string actualValue; file = new File(); this._document.Files.Add(file); unit = new Unit("unit1"); file.Containers.Add(unit); segment = new Segment("seg1"); segment.Source = new Source(); span = new SpanningCodeEnd(); segment.Source.Text.Add(span); unit.Resources.Add(segment); Console.WriteLine("Test with null Id."); actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.SpanningCodeEndWithNullId), actualValue); Console.WriteLine("Test with empty Id."); span.Id = string.Empty; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.SpanningCodeEndWithNullId), actualValue); Console.WriteLine("Test with valid Id."); span.Id = "span1"; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.SpanningCodeEndWithValidId), actualValue); }
public void StandardValidator_SpanningCodeEnd() { SpanningCodeEnd span; SpanningCodeStart startSpan; Segment segment; Unit unit; span = new SpanningCodeEnd(); span.Isolated = true; Console.WriteLine("Test with null Id."); this.DeserializeDocument(); unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit); segment = (Segment)unit.Resources.First(r => r is Segment); segment.Source.Text.Add(span); StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with empty Id."); span.Id = String.Empty; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with duplicate Id."); segment.Id = "duplicateId"; span.Id = segment.Id; this.VerifyValidationException(ValidationError.ElementIdDuplicate); Console.WriteLine("Test with item on target not matching source."); span.Id = "newSpanId"; segment.Target.Text.Add(new MarkedSpan("bogus")); StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with DataReference matching data."); span = new SpanningCodeEnd("spanId"); span.Isolated = true; span.Type = CodeType.Formatting; this.DeserializeDocument(); unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit); unit.OriginalData = new OriginalData(); unit.OriginalData.AddData("dataId", "text"); segment = (Segment)unit.Resources.First(r => r is Segment); segment.Source.Text.Add(span); span.DataReference = "dataId"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with DataReference not matching data."); span.DataReference = "bogus"; this.VerifyValidationException(ValidationError.SpanningCodeEndInvalidDataRef); Console.WriteLine("Test with DataReference is null."); span.DataReference = null; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with DataReference is empty."); span.DataReference = String.Empty; this.VerifyValidationException(ValidationError.SpanningCodeEndInvalidDataRef); span.DataReference = "dataId"; Console.WriteLine("Test with StartReference matching sc."); span = new SpanningCodeEnd("spanId"); span.Type = CodeType.Formatting; this.DeserializeDocument(); unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit); unit.OriginalData = new OriginalData(); unit.OriginalData.AddData("dataId", "text"); segment = (Segment)unit.Resources.First(r => r is Segment); startSpan = new SpanningCodeStart("scId"); startSpan.DataReference = "dataId"; startSpan.Type = CodeType.Formatting; segment.Source.Text.Add(startSpan); segment.Source.Text.Add(span); span.DataReference = "dataId"; span.StartReference = "scId"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with StartReference not matching sc."); span.StartReference = "bogus"; this.VerifyValidationException(ValidationError.TagStartRefInvalid); Console.WriteLine("Test with StartReference is null."); startSpan.Isolated = true; span.Isolated = true; span.StartReference = null; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with StartReference is empty."); span.Isolated = false; span.StartReference = String.Empty; this.VerifyValidationException(ValidationError.TagStartRefInvalid); Console.WriteLine("Test with SubFlows is null."); span = new SpanningCodeEnd("spanId"); span.Isolated = true; span.Type = CodeType.Formatting; this.DeserializeDocument(); unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit); unit.OriginalData = new OriginalData(); unit.OriginalData.AddData("dataId", "text"); segment = (Segment)unit.Resources.First(r => r is Segment); segment.Source.Text.Add(span); span.DataReference = "dataId"; span.SubFlows = null; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubFlows is empty."); span.SubFlows = String.Empty; this.VerifyValidationException(ValidationError.SpanningCodeEndSubFlowsInvalid); Console.WriteLine("Test with SubFlows matching a unit."); span.SubFlows = "u1"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubFlows matching multiple units."); span.SubFlows = "u1 u2 u3"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubFlows multiple units with one not matching."); span.SubFlows = "u1 u200 u3"; this.VerifyValidationException(ValidationError.SpanningCodeEndSubFlowsInvalid); Console.WriteLine("Test with SubType not like prefix:value."); span = new SpanningCodeEnd("spanId"); span.Isolated = true; span.Type = CodeType.Formatting; this.DeserializeDocument(); unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit); unit.OriginalData = new OriginalData(); unit.OriginalData.AddData("dataId", "text"); segment = (Segment)unit.Resources.First(r => r is Segment); segment.Source.Text.Add(span); span.DataReference = "dataId"; span.SubType = "a"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubType using xlf:value."); span.SubType = "Xlf:value"; this.VerifyValidationException(ValidationError.CodeBaseSubTypeInvalid); Console.WriteLine("Test with SubType using prefix:value:value is ok."); span.SubType = "prefix:value:value"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubType set and Type not."); span.SubType = "prefix:value"; span.Type = null; this.VerifyValidationException(ValidationError.CodeBaseTypeNotSpecified); Console.WriteLine("Test with SubType is null."); span.SubType = null; span.Type = CodeType.Formatting; StandardValidatorTests._validator.Validate(this._document); foreach (string name in new string[] { "lb", "pb", "b", "i", "u" }) { Console.WriteLine("Test with SubType set to {0} and Type set to fmt.", name); span.SubType = "xlf:" + name; span.Type = CodeType.Formatting; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubType set to {0} and Type not set to fmt.", name); span.Type = CodeType.Image; this.VerifyValidationException(ValidationError.CodeBaseSubTypeMismatchFormatting); } Console.WriteLine("Test with SubType set to var and Type set to var."); span.SubType = "xlf:var"; span.Type = CodeType.UserInterface; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with SubType set to var and Type not set to var."); span.Type = CodeType.Image; this.VerifyValidationException(ValidationError.CodeBaseSubTypeMismatchUserInterface); }
/// <summary> /// Creates a <see cref="SpanningCodeEnd"/> with every element and attribute. /// </summary> /// <param name="copyOf">The Id of the element to copy, or null.</param> /// <param name="startRef">The reference to the start tag.</param> /// <returns>The created <see cref="SpanningCodeEnd"/>.</returns> private SpanningCodeEnd CreateEc(string copyOf, string startRef) { SpanningCodeEnd result; result = new SpanningCodeEnd("ec" + this.GetNextId(typeof(SpanningCodeEnd))); result.CanCopy = true; result.CanDelete = true; result.CanOverlap = true; result.CanReorder = CanReorderValue.Yes; result.CopyOf = copyOf; result.DataReference = null; result.Directionality = ContentDirectionality.Auto; result.DisplayText = "display"; result.EquivalentText = "equiv"; result.Isolated = (startRef == null); result.StartReference = startRef; result.SubFlows = "u1"; result.SubType = "pre:subtype"; result.Type = CodeType.Formatting; if (startRef == null) { result.EquivalentStorage = "storage"; result.FormatStyle = FormatStyleValue.Anchor; result.SizeInfo = "size"; result.SubFormatStyle.Add("key1", "value1"); result.SubFormatStyle.Add("key2", "value2"); } else { // Id and StartReference cannot both be present. result.Id = null; } return result; }