예제 #1
0
        public void XliffWriter_Ignorable()
        {
            File      file;
            Ignorable ignorable;
            Unit      unit;
            string    actualValue;

            file = new File();
            this._document.Files.Add(file);

            unit = new Unit();
            file.Containers.Add(unit);

            ignorable = new Ignorable();
            unit.Resources.Add(ignorable);

            Console.WriteLine("Test with default values.");
            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.IgnorableWithDefaultValues), actualValue);

            Console.WriteLine("Test with empty values.");
            ignorable.Id = String.Empty;
            actualValue  = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.IgnorableWithEmptyValues), actualValue);

            Console.WriteLine("Test with valid values.");
            ignorable.Id = "id";
            actualValue  = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.IgnorableWithValidValues), actualValue);
        }
예제 #2
0
        public void DefaultValue_Ignorable()
        {
            Ignorable ignorable;

            ignorable = new Ignorable("id");
            Assert.AreEqual("id", ignorable.Id, "Id is incorrect.");
            Assert.IsNull(ignorable.Source, "Source is incorrect.");
            Assert.IsNull(ignorable.Target, "Target is incorrect.");
        }
예제 #3
0
        public static BaseChangeMessage <TChange> TryAdd <TChange>(this BaseChangeMessage <TChange> message, TChange change, Ignorable <double> value)
        {
            switch (value.State)
            {
            case Ignorable <double> .ValueState.Ignore:
                break;

            case Ignorable <double> .ValueState.Clear:
                message.Add(change, 0m);
                break;

            case Ignorable <double> .ValueState.Use:
                message.TryAdd(change, value.Value.ToDecimal());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(message);
        }
 public void TestInitialize()
 {
     this._element = new Ignorable();
     this._provider = this._element;
 }
        public void DefaultValue_Ignorable()
        {
            Ignorable ignorable;

            ignorable = new Ignorable("id");
            Assert.AreEqual("id", ignorable.Id, "Id is incorrect.");
            Assert.IsNull(ignorable.Source, "Source is incorrect.");
            Assert.IsNull(ignorable.Target, "Target is incorrect.");
        }
        public void XliffElement_SelectElement()
        {
            File file;
            Group group;
            Unit unit;
            Segment segment;
            Ignorable ignorable;
            TestXliffElement element;

            element = new TestXliffElement();
            element.Document = new XliffDocument();

            Console.WriteLine("Test with no items.");
            Assert.IsNull(element.CallSelectElement("#/file"));

            Console.WriteLine("Test with file items.");
            file = new File("file");
            element.Document.Files.Add(file);
            Assert.AreEqual(file, element.CallSelectElement("#/f=file"));

            Console.WriteLine("Test with relative path to file item.");
            Assert.AreEqual(file, element.Document.Select("#f=file"));

            Console.WriteLine("Test with many items.");
            group = new Group("group");
            file.Containers.Add(new Group());
            file.Containers.Add(group);

            unit = new Unit("unit");
            group.Containers.Add(unit);
            group.Containers.Add(new Group());
            group.Containers.Add(new Unit());
            Assert.AreEqual(unit, element.CallSelectElement("#/f=file/g=group/u=unit"));

            Console.WriteLine("Test with segment.");
            segment = new Segment("segment");
            unit.Resources.Add(segment);
            Assert.AreEqual(segment, element.CallSelectElement("#/f=file/g=group/u=unit/segment"));

            Console.WriteLine("Test with relative path to segment.");
            Assert.AreEqual(segment, group.Select("#u=unit/segment"));

            Console.WriteLine("Test with invalid relative path to segment.");
            try
            {
                group.Select("u=unit/segment");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            Console.WriteLine("Test with ignorable.");
            ignorable = new Ignorable("ignorable");
            unit.Resources.Add(ignorable);
            Assert.AreEqual(ignorable, element.CallSelectElement("#/f=file/g=group/u=unit/ignorable"));

            Console.WriteLine("Test with data.");
            unit.OriginalData = new OriginalData();
            unit.OriginalData.AddData("data", "text");
            Assert.AreEqual(unit.OriginalData.DataElements[0],
                            element.CallSelectElement("#/f=file/g=group/u=unit/d=data"));

            Console.WriteLine("Test with note.");
            file.AddNote("note").Id = "note";
            Assert.AreEqual(file.Notes[0], element.CallSelectElement("#/f=file/n=note"));

            //
            // This test should still work even though it's an invalid document.
            //

            Console.WriteLine("Test with duplicate names.");
            element.Document.Files.Add(new File("file"));
            Assert.AreEqual(file, element.CallSelectElement("#/f=file"), "Found wrong item.");

            Console.WriteLine("Test with bogus names.");
            Assert.IsNull(element.CallSelectElement("#/f=foo"), "Item should not have been found.");

            Console.WriteLine("Test with bogus path.");
            Assert.IsNull(element.CallSelectElement("#/blah"), "Item should not have been found.");

            Console.WriteLine("Test with empty string.");
            // This returns null because SelectElement is called directly which doesn't search for the leading '#'.
            Assert.IsNull(element.CallSelectElement(String.Empty));

            Console.WriteLine("Test with empty path.");
            Assert.IsNull(element.CallSelectElement("/"), "Item should not have been found.");

            Console.WriteLine("Test with inline element.");
            segment.Source = new Source();
            segment.Source.Text.Add(new MarkedSpan("ms1"));
            Assert.AreEqual(segment.Source.Text[0],
                            element.CallSelectElement("#/f=file/g=group/u=unit/ms1"),
                            "Item should have been found.");

            Console.WriteLine("Test with inline element.");
            segment.Target = new Target();
            segment.Target.Text.Add(new MarkedSpan("ms2"));
            Assert.AreEqual(segment.Target.Text[0],
                            element.CallSelectElement("#/f=file/g=group/u=unit/t=ms2"),
                            "Item should have been found.");

            Console.WriteLine("Test with relative path to inline element from file.");
            Assert.AreEqual(segment.Target.Text[0],
                            file.Select("#g=group/u=unit/t=ms2"),
                            "Item should have been found.");

            Console.WriteLine("Test with relative path to inline element from unit.");
            Assert.AreEqual(segment.Target.Text[0],
                            unit.Select("#t=ms2"),
                            "Item should have been found.");
        }
예제 #7
0
        public void XliffElement_SelectElement()
        {
            File             file;
            Group            group;
            Unit             unit;
            Segment          segment;
            Ignorable        ignorable;
            TestXliffElement element;

            element          = new TestXliffElement();
            element.Document = new XliffDocument();

            Console.WriteLine("Test with no items.");
            Assert.IsNull(element.CallSelectElement("#/file"));

            Console.WriteLine("Test with file items.");
            file = new File("file");
            element.Document.Files.Add(file);
            Assert.AreEqual(file, element.CallSelectElement("#/f=file"));

            Console.WriteLine("Test with relative path to file item.");
            Assert.AreEqual(file, element.Document.Select("#f=file"));

            Console.WriteLine("Test with many items.");
            group = new Group("group");
            file.Containers.Add(new Group());
            file.Containers.Add(group);

            unit = new Unit("unit");
            group.Containers.Add(unit);
            group.Containers.Add(new Group());
            group.Containers.Add(new Unit());
            Assert.AreEqual(unit, element.CallSelectElement("#/f=file/g=group/u=unit"));

            Console.WriteLine("Test with segment.");
            segment = new Segment("segment");
            unit.Resources.Add(segment);
            Assert.AreEqual(segment, element.CallSelectElement("#/f=file/g=group/u=unit/segment"));

            Console.WriteLine("Test with relative path to segment.");
            Assert.AreEqual(segment, group.Select("#u=unit/segment"));

            Console.WriteLine("Test with invalid relative path to segment.");
            try
            {
                group.Select("u=unit/segment");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            Console.WriteLine("Test with ignorable.");
            ignorable = new Ignorable("ignorable");
            unit.Resources.Add(ignorable);
            Assert.AreEqual(ignorable, element.CallSelectElement("#/f=file/g=group/u=unit/ignorable"));

            Console.WriteLine("Test with data.");
            unit.OriginalData = new OriginalData();
            unit.OriginalData.AddData("data", "text");
            Assert.AreEqual(unit.OriginalData.DataElements[0],
                            element.CallSelectElement("#/f=file/g=group/u=unit/d=data"));

            Console.WriteLine("Test with note.");
            file.AddNote("note").Id = "note";
            Assert.AreEqual(file.Notes[0], element.CallSelectElement("#/f=file/n=note"));

            //
            // This test should still work even though it's an invalid document.
            //

            Console.WriteLine("Test with duplicate names.");
            element.Document.Files.Add(new File("file"));
            Assert.AreEqual(file, element.CallSelectElement("#/f=file"), "Found wrong item.");

            Console.WriteLine("Test with bogus names.");
            Assert.IsNull(element.CallSelectElement("#/f=foo"), "Item should not have been found.");

            Console.WriteLine("Test with bogus path.");
            Assert.IsNull(element.CallSelectElement("#/blah"), "Item should not have been found.");

            Console.WriteLine("Test with empty string.");
            // This returns null because SelectElement is called directly which doesn't search for the leading '#'.
            Assert.IsNull(element.CallSelectElement(String.Empty));

            Console.WriteLine("Test with empty path.");
            Assert.IsNull(element.CallSelectElement("/"), "Item should not have been found.");

            Console.WriteLine("Test with inline element.");
            segment.Source = new Source();
            segment.Source.Text.Add(new MarkedSpan("ms1"));
            Assert.AreEqual(segment.Source.Text[0],
                            element.CallSelectElement("#/f=file/g=group/u=unit/ms1"),
                            "Item should have been found.");

            Console.WriteLine("Test with inline element.");
            segment.Target = new Target();
            segment.Target.Text.Add(new MarkedSpan("ms2"));
            Assert.AreEqual(segment.Target.Text[0],
                            element.CallSelectElement("#/f=file/g=group/u=unit/t=ms2"),
                            "Item should have been found.");

            Console.WriteLine("Test with relative path to inline element from file.");
            Assert.AreEqual(segment.Target.Text[0],
                            file.Select("#g=group/u=unit/t=ms2"),
                            "Item should have been found.");

            Console.WriteLine("Test with relative path to inline element from unit.");
            Assert.AreEqual(segment.Target.Text[0],
                            unit.Select("#t=ms2"),
                            "Item should have been found.");
        }
예제 #8
0
        public void XliffWriter_FullDocument()
        {
            File      file;
            Group     group1;
            Group     group2;
            Ignorable ignorable;
            Note      note;
            Segment   segment;
            Skeleton  skeleton;
            Unit      unit;
            string    actualValue;

            this._document.SourceLanguage = "en-us";
            this._document.Space          = Preservation.Default;
            this._document.TargetLanguage = "de-de";
            this._document.Version        = "version";

            file = new File();
            file.CanResegment         = true;
            file.Id                   = "id";
            file.Original             = "original";
            file.SourceDirectionality = ContentDirectionality.LTR;
            file.Space                = Preservation.Preserve;
            file.TargetDirectionality = ContentDirectionality.RTL;
            file.Translate            = true;
            this._document.Files.Add(file);

            group1 = new Group();
            group1.CanResegment         = true;
            group1.Id                   = "id";
            group1.Name                 = "name";
            group1.SourceDirectionality = ContentDirectionality.RTL;
            group1.Space                = Preservation.Preserve;
            group1.TargetDirectionality = ContentDirectionality.Auto;
            group1.Translate            = true;
            group1.Type                 = "type";
            file.Containers.Add(group1);

            group2 = new Group();
            group2.CanResegment         = false;
            group2.Id                   = "id2";
            group2.Name                 = "name2";
            group2.SourceDirectionality = ContentDirectionality.LTR;
            group2.Space                = Preservation.Default;
            group2.TargetDirectionality = ContentDirectionality.RTL;
            group2.Translate            = false;
            group2.Type                 = "type2";
            file.Containers.Add(group2);

            unit = new Unit();
            unit.CanResegment = false;
            unit.Id           = "id";
            unit.Name         = "name";
            unit.Notes.Add(new Note("text"));
            unit.SourceDirectionality = ContentDirectionality.LTR;
            unit.Space = Preservation.Default;
            unit.TargetDirectionality = ContentDirectionality.Auto;
            unit.Translate            = true;
            unit.Type = "type";
            group2.Containers.Add(unit);

            unit.OriginalData = new OriginalData();
            unit.OriginalData.AddData("id", "data1");
            unit.OriginalData.DataElements[0].Directionality = ContentDirectionality.RTL;
            unit.OriginalData.DataElements[0].Space          = Preservation.Preserve;
            unit.OriginalData.DataElements[0].Text.Add(new CodePoint(1));

            unit = new Unit();
            unit.CanResegment = false;
            unit.Id           = "id2";
            unit.Name         = "name2";
            unit.Notes.Add(new Note("text2"));
            unit.SourceDirectionality = ContentDirectionality.RTL;
            unit.Space = Preservation.Preserve;
            unit.TargetDirectionality = ContentDirectionality.LTR;
            unit.Translate            = false;
            unit.Type = "type2";
            group2.Containers.Add(unit);

            unit.OriginalData = new OriginalData();
            unit.OriginalData.AddData("id1", "data1");
            unit.OriginalData.DataElements[0].Directionality = ContentDirectionality.LTR;
            unit.OriginalData.DataElements[0].Space          = Preservation.Preserve;
            unit.OriginalData.DataElements[0].Text.Add(new CodePoint(2));
            unit.OriginalData.AddData("id2", "data2");
            unit.OriginalData.DataElements[1].Directionality = ContentDirectionality.RTL;
            unit.OriginalData.DataElements[1].Space          = Preservation.Preserve;
            unit.OriginalData.DataElements[1].Text.Add(new CodePoint(1));

            ignorable        = new Ignorable();
            ignorable.Id     = "id";
            ignorable.Source = new Source("text");
            ignorable.Target = new Target("text");
            unit.Resources.Add(ignorable);

            segment = new Segment();
            segment.CanResegment    = true;
            segment.Id              = "id";
            segment.Source          = new Source();
            segment.State           = TranslationState.Reviewed;
            segment.SubState        = "substate";
            segment.Target          = new Target();
            segment.Source.Language = "en-us";
            segment.Source.Space    = Preservation.Default;
            segment.Source.Text.Add(new CodePoint(1));
            segment.Source.Text.Add(new PlainText("text"));
            segment.Target.Language = "en-us";
            segment.Target.Order    = 100;
            segment.Target.Space    = Preservation.Default;
            segment.Target.Text.Add(new CodePoint(12));
            segment.Target.Text.Add(new PlainText("text2"));
            unit.Resources.Add(segment);

            note           = new Note();
            note.AppliesTo = TranslationSubject.Source;
            note.Category  = "category";
            note.Id        = "id";
            note.Priority  = 2;
            note.Text      = "text";
            file.Notes.Add(note);

            file.Notes.Add(new Note("text2"));

            skeleton      = new Skeleton();
            skeleton.HRef = "href";
            skeleton.NonTranslatableText = "text";
            file.Skeleton = skeleton;

            file = new File();
            file.CanResegment = false;
            file.Id           = "id2";
            file.Notes.Add(new Note("text"));
            file.Original             = "original2";
            file.SourceDirectionality = ContentDirectionality.Auto;
            file.Space = Preservation.Default;
            file.TargetDirectionality = ContentDirectionality.LTR;
            file.Translate            = false;
            this._document.Files.Add(file);

            skeleton      = new Skeleton();
            skeleton.HRef = "href";
            skeleton.NonTranslatableText = "text";
            file.Skeleton = skeleton;

            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.FullDocument), actualValue);
        }
예제 #9
0
 public void TestInitialize()
 {
     this._element  = new Ignorable();
     this._provider = this._element;
 }
예제 #10
0
        public void RoundtripExample1()
        {
            JliffDocument model = new JliffDocument("en", "fr", new Localization.Jliff.Graph.File("f1"));

            var u1 = new Unit("u1");

            u1.OriginalData.Add("d1", "[C1/]");
            u1.OriginalData.Add("d2", "[C2]");
            u1.OriginalData.Add("d3", "[/C2]");

            var seg = new Segment();

            seg.State        = Enumerations.State.translated.ToString();
            seg.CanResegment = "yes";

            var ph1 = new PhElement("c1");

            ph1.DataRef = "d1";
            var tph1 = new PhElement("c1");

            tph1.DataRef = "d1";

            var sc1 = new ScElement("c2");

            sc1.DataRef = "d2";
            var tsc1 = new ScElement("c2");

            tsc1.DataRef = "d2";

            var te3  = new TextElement("text");
            var tte3 = new TextElement("AAA");

            var ec1 = new EcElement();

            ec1.DataRef  = "d3";
            ec1.StartRef = new Nmtoken("c2");
            var tec1 = new EcElement();

            tec1.DataRef  = "d3";
            tec1.StartRef = new Nmtoken("c2");

            var te1  = new TextElement("aaa");
            var tte1 = new TextElement("AAA");

            var te2 = new TextElement(". ");

            var i1 = new Ignorable();

            i1.Source.Add(te2);

            seg.Source.Add(ph1);
            seg.Source.Add(te1);
            seg.Source.Add(sc1);
            seg.Source.Add(te3);
            seg.Source.Add(ec1);
            seg.Target.Add(tph1);
            seg.Target.Add(tte1);
            seg.Target.Add(tsc1);
            seg.Target.Add(tte3);
            seg.Target.Add(tec1);

            u1.Subunits.Add(seg);
            u1.Subunits.Add(i1);

            model.Files[0].Subfiles.Add(u1);

            var g = new Group("g1");

            var u2 = new Unit("u2");

            var g2 = new Group("g2");

            model.Files[0].Subfiles.Add(g);

            g.Subgroups.Add(u2);
            g.Subgroups.Add(g2);

            model.Context = new Context21();

            var dllPath    = Assembly.GetAssembly(typeof(ModelTests)).Location;
            var dllName    = Assembly.GetAssembly(typeof(ModelTests)).GetName().Name;
            var outputPath = dllPath.Replace(dllName + ".dll", "");


            Converter.Serialize(Path.Combine(outputPath, "example1.json"), model);

            Converter.Deserialize(new FileInfo(Path.Combine(outputPath, "example1.json")));

            JsonSchema schema  = JsonSchema.Parse(schemaDef);
            var        obGraph = JObject.FromObject(model);

            Assert.IsTrue(obGraph.IsValid(schema));
        }