示例#1
0
            public void ReturnSegmentWithImbricatedStartAndEndTagAndInBetweenText_WhenSegmentHasImbricatedStartAndEndTagsAndInBetweenText()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("I ");
                segment.Add(new Tag(TagType.Start, "1", 1));
                segment.Add("have ");
                segment.Add(new Tag(TagType.Start, "2", 2));
                segment.Add("one ");
                segment.Add(new Tag(TagType.End, "2", 2));
                segment.Add("new");
                segment.Add(new Tag(TagType.End, "1", 1));
                segment.Add("tag");
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var result = converter.ConvertTargetTextToSegment("Ich<tg1-1>habe<tg2-2>einen</tg2-2>neues</tg1-1>tag");

                //Assert
                Assert.Equal(9, result.Elements.Count);
                Assert.Equal("Ich <1 id=1>habe <2 id=2>einen </2>neues</1>tag", result.ToString());
            }
示例#2
0
            public void ReturnSegmentWithNoElement_WhenTextIsNull()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("This is a test");
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var result = converter.ConvertTargetTextToSegment(null);

                //Assert
                Assert.Empty(result.Elements);
            }
示例#3
0
            public void ReturnsSegmentWithStartTag_WhenTranslatedTextHasOnlyStartTag()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("I contain");
                segment.Add(new Tag(TagType.Start, "1", 1));
                segment.Add("one tag");
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var result = converter.ConvertTargetTextToSegment("Ich habe<tg1-1>einen tag");

                //Assert
                Assert.Equal(3, result.Elements.Count);
                Assert.Equal("Ich habe<1 id=1>einen tag", result.ToString());
            }
示例#4
0
            public void RemovesBomCharacters_WhenTextHasBomCharactersTags()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("Hello");

                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var translatedText = "Hallo" + (char)8203;
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.Single(result.Elements);
                Assert.Equal("Hallo", result.Elements[0].ToString());
            }
示例#5
0
            public void ReturnsDecodedSingleElementSegment_WhenTextHasNoTags()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("Hello G%C3%BCnter");

                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var translatedText = "Hallo G&#252;nter";
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.Single(result.Elements);
                Assert.Equal("Hallo Günter", result.Elements[0].ToString());
            }
示例#6
0
            public void ReturnsSingleElementSegment_WhenTextHasNoTags()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("This is a test");

                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var translatedText = "Das ist ein Test";
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.Single(result.Elements);
                Assert.Equal(translatedText, result.Elements[0].ToString());
            }
示例#7
0
            public void ReturnSegmentWithSingleTag_WhenTagIsAtTheEnd(TagType tagType)
            {
                //Arrange
                var segment = new Segment();

                segment.Add("I contain one tag");
                segment.Add(new Tag(tagType, "1", 1));
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var translatedText = "Ich habe einen tag<tg1-1/>";
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.True(segment.HasTags);
                Assert.Equal(2, result.Elements.Count);
                Assert.Equal(tagType, (result.Elements[1] as Tag).Type);
            }
示例#8
0
            public void ReturnsCorrectSpacing_WhenSegmentHasTagsWithTheSameId()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("Bold ");
                segment.Add(new Tag(TagType.Standalone, "110", 1));
                segment.Add("  Italics   ");
                segment.Add(new Tag(TagType.Standalone, "110", 2));
                segment.Add("    Single Underline");
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var result = converter.ConvertTargetTextToSegment("Bold <tg110-1/>  Italics   <tg110-2/>    Single Underline");

                //Assert
                Assert.Equal(5, result.Elements.Count);
                Assert.Equal("Bold <1 id=110/>  Italics   <2 id=110/>    Single Underline", result.ToString());
            }
示例#9
0
            public void ReturnSegmentWithTheSameNumberOfSpaces_WhenTagIsAtTheBeginningAndIsFollowedBySpace(TagType tagType, int noSpaces)
            {
                //Arrange
                var segment = new Segment();

                segment.Add(new Tag(tagType, "1", 1));
                segment.Add("I contain one tag".PadLeft(noSpaces));
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var startText      = "Ich habe einen tag";
                var translatedText = "<tg1-1/>" + startText;
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.True(segment.HasTags);
                Assert.Equal(2, result.Elements.Count);
                Assert.Equal(startText.PadLeft(noSpaces), result.Elements[1].ToString());
                Assert.Equal(tagType, (result.Elements[0] as Tag).Type);
            }
示例#10
0
            public void ReturnSegmentWithCorrectTag_WhenTagIdContainsLetters()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("I contain");
                segment.Add(new Tag(TagType.Standalone, "ph14", 1));
                segment.Add("one tag");
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var beforeTag      = "Ich habe";
                var afterTag       = "einen tag";
                var translatedText = beforeTag + "<tgph14-1/>" + afterTag;
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.True(segment.HasTags);
                Assert.Equal(3, result.Elements.Count);
                Assert.Equal("ph14", (result.Elements[1] as Tag).TagID);
            }
示例#11
0
            public void ReturnSegmentithImbricatedStartAndEndTag_WhenTranslatedTextHasImbricatedStartAndEndTags()
            {
                //Arrange
                var segment = new Segment();

                segment.Add("I contain ");
                segment.Add(new Tag(TagType.Start, "1", 1));
                segment.Add(new Tag(TagType.Start, "2", 2));
                segment.Add("one ");
                segment.Add(new Tag(TagType.End, "2", 2));
                segment.Add(new Tag(TagType.End, "1", 1));
                segment.Add("tag");
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var result = converter.ConvertTargetTextToSegment("Ich habe<tg1-1><tg2-2>einen</tg2-2></tg1-1>tag");

                //Assert
                Assert.Equal(7, result.Elements.Count);
                Assert.Equal("Ich habe <1 id=1><2 id=2>einen </2></1>tag", result.ToString());
            }
示例#12
0
            public void ReturnSegmentWithTheSameNumberOfSpaces_WhenTagIsAtTheMiddleAndIsSurroundedBySpace(TagType tagType, int noSpacesLeft, int noSpacesRight)
            {
                //Arrange
                var segment = new Segment();

                segment.Add("I contain".PadRight(noSpacesLeft));
                segment.Add(new Tag(tagType, "1", 1));
                segment.Add("one tag".PadLeft(noSpacesRight));
                var converter = new SegmentConverter(segment);

                converter.ConvertSourceSegmentToText();

                //Act
                var beforeTag      = "Ich habe";
                var afterTag       = "einen tag";
                var translatedText = beforeTag + "<tg1-1/>" + afterTag;
                var result         = converter.ConvertTargetTextToSegment(translatedText);

                //Assert
                Assert.True(segment.HasTags);
                Assert.Equal(3, result.Elements.Count);
                Assert.Equal(beforeTag.PadRight(noSpacesLeft), result.Elements[0].ToString());
                Assert.Equal(afterTag.PadLeft(noSpacesRight), result.Elements[2].ToString());
            }