Ejemplo n.º 1
0
        public void Parse_Exception_BigSize()
        {
            NoteParser parser = new NoteParser();

            Exception exception = Assert.Throws <Exception>(() => parser.Parse(2, 4, 4, 4, 8, 8, 8, 4).ToList());

            Assert.That(exception.Message == NoteParser.NOTE_BIG_SIZE_ERROR);
        }
Ejemplo n.º 2
0
        public void Parse_GroupCount_3()
        {
            NoteParser parser = new NoteParser();

            List <ParseNoteResult> list = parser.Parse(2, 4, 4, 4, 8, 8, 4, 8, 4, 8).ToList();

            Assert.AreEqual(3, list.Count);
        }
Ejemplo n.º 3
0
        public void it_parses_note(string text, Note.Keys key, Note.Octaves octave)
        {
            var noteParser = new NoteParser();

            var note = noteParser.Parse(text);

            Assert.That(note.Key, Is.EqualTo(key));
            Assert.That(note.Octave, Is.EqualTo(octave));
        }
Ejemplo n.º 4
0
    public void LoadNotePattern()
    {
        if (csv_FileName == "")
        {
            Debug.Log("파일 이름을 적어주세요.");
            return;
        }

        noteDic.Clear();

        NoteParser theParser = GetComponent <NoteParser>();

        NoteData[] notes = theParser.Parse(csv_FileName);
        for (int i = 0; i < notes.Length; i++)
        {
            noteDic.Add(i + 1, notes[i]);
        }
        loadFinish = true;
    }
Ejemplo n.º 5
0
        public void Parse(ILineProvider lineProvider)
        {
            GedcomLine lastLine = default;

            var firstRawLine = lineProvider.ReadLine();

            if (firstRawLine == null)
            {
                throw new InvalidOperationException("File empty");
            }

            var firstLine = ParserHelper.ParseLine(firstRawLine);

            if (firstLine.Level != 0 && !ParserHelper.Equals(firstLine.GetFirstItem(), "HEAD"))
            {
                throw new InvalidOperationException("GEDCOM Header Not Found");
            }

            var gedcomHeaderParse = HeaderParser.Parse(firstLine, lineProvider);

            _headerCallback?.Invoke(gedcomHeaderParse.Result);

            var newLine = gedcomHeaderParse.Line;

            lastLine = newLine;

            while (newLine.LineContent.Length > 0)
            {
                var content = newLine.GetLineContent();
                if (content.Length == 0)
                {
                    var unrecognisedRawLine = lineProvider.ReadLine();
                    if (unrecognisedRawLine != null)
                    {
                        newLine  = ParserHelper.ParseLine(unrecognisedRawLine);
                        lastLine = newLine;
                    }
                    else
                    {
                        newLine = default;
                    }
                    continue;
                }

                var unknown = false;

                if (ParserHelper.Equals(content, "INDI"))
                {
                    var individualParseResult = IndividualParser.Parse(newLine, lineProvider);
                    _individualCallback?.Invoke(individualParseResult.Result);
                    newLine  = individualParseResult.Line;
                    lastLine = newLine;
                }
                else if (ParserHelper.Equals(content, "FAM"))
                {
                    var familyParseResult = FamilyParser.Parse(newLine, lineProvider);
                    _familyCallback?.Invoke(familyParseResult.Result);
                    newLine  = familyParseResult.Line;
                    lastLine = newLine;
                }
                else if (ParserHelper.Equals(content, "NOTE"))
                {
                    var noteParseResult = NoteParser.Parse(newLine, lineProvider);
                    _noteCallback?.Invoke(noteParseResult.Result);
                    newLine  = noteParseResult.Line;
                    lastLine = newLine;
                }
                else if (ParserHelper.Equals(content, "OBJE"))
                {
                    var objParserResult = ObjectParser.Parse(newLine, lineProvider);
                    _imageCallback?.Invoke(objParserResult.Result);
                    newLine  = objParserResult.Line;
                    lastLine = newLine;
                }
                else
                {
                    var unrecognisedRawLine = lineProvider.ReadLine();
                    if (unrecognisedRawLine != null)
                    {
                        newLine  = ParserHelper.ParseLine(unrecognisedRawLine);
                        lastLine = newLine;
                    }
                    else
                    {
                        newLine = default;
                    }
                    unknown = true;
                }

                if (unknown)
                {
                    continue;
                }
            }

            if (lastLine.LineContent.Length == 0)
            {
                throw new InvalidOperationException("file contains no content");
            }

            if (lastLine.Level != 0 || !ParserHelper.Equals(lastLine.GetFirstItem(), "TRLR"))
            {
                throw new InvalidOperationException("GEDCOM TRLR not found");
            }
        }