Exemplo n.º 1
0
        public void Check_ValidPatternsAreNotReported()
        {
            PuncPatternsList puncPatterns = new PuncPatternsList();
            PuncPattern      pattern      = new PuncPattern();

            pattern.Pattern    = "._";
            pattern.ContextPos = ContextPosition.WordFinal;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            pattern            = new PuncPattern();
            pattern.Pattern    = ",";
            pattern.ContextPos = ContextPosition.WordBreaking;
            pattern.Status     = PuncPatternStatus.Invalid;
            puncPatterns.Add(pattern);
            m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
            m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

            PunctuationCheck check = new PunctuationCheck(m_dataSource);

            m_dataSource.Text = "\\p This is nice. By nice,I mean really nice!";

            check.Check(m_dataSource.TextTokens(), RecordError);

            Assert.AreEqual(2, m_errors.Count);
            CheckError(0, "This is nice. By nice,I mean really nice!", 21, ",", "Invalid punctuation pattern");
            CheckError(1, "This is nice. By nice,I mean really nice!", 40, "!", "Unspecified use of punctuation pattern");
        }
Exemplo n.º 2
0
        public void Check_PatternsWithSpaceSeparatedQuoteMarks()
        {
            PuncPatternsList puncPatterns = new PuncPatternsList();
            PuncPattern      pattern      = new PuncPattern();

            pattern.Pattern    = ",_";
            pattern.ContextPos = ContextPosition.WordFinal;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            pattern            = new PuncPattern();
            pattern.Pattern    = "_\u201C";
            pattern.ContextPos = ContextPosition.WordInitial;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            pattern            = new PuncPattern();
            pattern.Pattern    = "_\u2018";
            pattern.ContextPos = ContextPosition.WordInitial;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
            m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

            PunctuationCheck check = new PunctuationCheck(m_dataSource);

            m_dataSource.Text = "\\p Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D";

            check.Check(m_dataSource.TextTokens(), RecordError);

            Assert.AreEqual(1, m_errors.Count);
            CheckError(0, "Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D", 29, "!\u2019\u202F\u201D", "Unspecified use of punctuation pattern");
        }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ContextInfo"/> class.
        /// </summary>
        /// <param name="pattern">The punctuation pattern.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="context">The context (a string with the line contents).</param>
        /// <param name="reference">The reference (line number).</param>
        /// ------------------------------------------------------------------------------------
        internal ContextInfo(PuncPattern pattern, int offset, string context, string reference)
        {
            m_position = pattern.ContextPos;
            string chr = pattern.Pattern;

            // For punctuation patterns the position indicated by offset refers to the place where
            // the first punctuation character occurs. There can be a leading character indicating
            // that the pattern was found preceded by a space or at the start of a paragraph.
            if (pattern.Pattern.Length > 1)
            {
                if (m_position == ContextPosition.WordInitial || m_position == ContextPosition.Isolated)
                {
                    Debug.Assert(context[offset] == chr[1]);
                    // Adjust offset to account for leading space which is actually in the data
                    offset--;
                }
            }
            Initialize(chr, offset, context, reference);
        }
Exemplo n.º 4
0
        public void Check_ParaWithSingleQuotationMark()
        {
            PuncPatternsList puncPatterns = new PuncPatternsList();
            PuncPattern      pattern      = new PuncPattern();

            pattern.Pattern    = "._";
            pattern.ContextPos = ContextPosition.WordFinal;
            pattern.Status     = PuncPatternStatus.Valid;
            puncPatterns.Add(pattern);
            m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
            m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

            PunctuationCheck check = new PunctuationCheck(m_dataSource);

            m_dataSource.Text = "\\p wow\u201D\\p \u2019";

            check.Check(m_dataSource.TextTokens(), RecordError);

            Assert.AreEqual(2, m_errors.Count);
            CheckError(0, "wow\u201D", 3, "\u201D", "Unspecified use of punctuation pattern");
            CheckError(1, "\u2019", 0, "\u2019", "Unspecified use of punctuation pattern");
        }
Exemplo n.º 5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="ContextInfo"/> class.
 /// </summary>
 /// <param name="pattern">The punctuation pattern.</param>
 /// <param name="tts">The TextTokenSubstring.</param>
 /// ------------------------------------------------------------------------------------
 internal ContextInfo(PuncPattern pattern, TextTokenSubstring tts) :
     this(pattern, tts.Offset, tts.FullTokenText, tts.FirstToken.ScrRefString)
 {
 }
		public void Check_ParaWithSingleQuotationMark()
		{
			PuncPatternsList puncPatterns = new PuncPatternsList();
			PuncPattern pattern = new PuncPattern();
			pattern.Pattern = "._";
			pattern.ContextPos = ContextPosition.WordFinal;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
			m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

			PunctuationCheck check = new PunctuationCheck(m_dataSource);
			m_dataSource.Text = "\\p wow\u201D\\p \u2019";

			check.Check(m_dataSource.TextTokens(), RecordError);

			Assert.AreEqual(2, m_errors.Count);
			CheckError(0, "wow\u201D", 3, "\u201D", "Unspecified use of punctuation pattern");
			CheckError(1, "\u2019", 0, "\u2019", "Unspecified use of punctuation pattern");
		}
		public void Check_PatternsWithSpaceSeparatedQuoteMarks()
		{
			PuncPatternsList puncPatterns = new PuncPatternsList();
			PuncPattern pattern = new PuncPattern();
			pattern.Pattern = ",_";
			pattern.ContextPos = ContextPosition.WordFinal;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			pattern = new PuncPattern();
			pattern.Pattern = "_\u201C";
			pattern.ContextPos = ContextPosition.WordInitial;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			pattern = new PuncPattern();
			pattern.Pattern = "_\u2018";
			pattern.ContextPos = ContextPosition.WordInitial;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
			m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

			PunctuationCheck check = new PunctuationCheck(m_dataSource);

			m_dataSource.Text = "\\p Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D";

			check.Check(m_dataSource.TextTokens(), RecordError);

			Assert.AreEqual(1, m_errors.Count);
			CheckError(0, "Tom replied, \u201CBill said, \u2018Yes!\u2019\u202F\u201D", 29, "!\u2019\u202F\u201D", "Unspecified use of punctuation pattern");
		}
		public void Check_ValidPatternsAreNotReported()
		{
			PuncPatternsList puncPatterns = new PuncPatternsList();
			PuncPattern pattern = new PuncPattern();
			pattern.Pattern = "._";
			pattern.ContextPos = ContextPosition.WordFinal;
			pattern.Status = PuncPatternStatus.Valid;
			puncPatterns.Add(pattern);
			pattern = new PuncPattern();
			pattern.Pattern = ",";
			pattern.ContextPos = ContextPosition.WordBreaking;
			pattern.Status = PuncPatternStatus.Invalid;
			puncPatterns.Add(pattern);
			m_dataSource.SetParameterValue("PunctuationPatterns", puncPatterns.XmlString);
			m_dataSource.SetParameterValue("PunctCheckLevel", "Intermediate");

			PunctuationCheck check = new PunctuationCheck(m_dataSource);

			m_dataSource.Text = "\\p This is nice. By nice,I mean really nice!";

			check.Check(m_dataSource.TextTokens(), RecordError);

			Assert.AreEqual(2, m_errors.Count);
			CheckError(0, "This is nice. By nice,I mean really nice!", 21, ",", "Invalid punctuation pattern");
			CheckError(1, "This is nice. By nice,I mean really nice!", 40, "!", "Unspecified use of punctuation pattern");
		}
Exemplo n.º 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="ContextInfo"/> class.
		/// </summary>
		/// <param name="pattern">The punctuation pattern.</param>
		/// <param name="offset">The offset.</param>
		/// <param name="context">The context (a string with the line contents).</param>
		/// <param name="reference">The reference (line number).</param>
		/// ------------------------------------------------------------------------------------
		internal ContextInfo(PuncPattern pattern, int offset, string context, string reference)
		{
			m_position = pattern.ContextPos;
			string chr = pattern.Pattern;

			// For punctuation patterns the position indicated by offset refers to the place where
			// the first punctuation character occurs. There can be a leading character indicating
			// that the pattern was found preceded by a space or at the start of a paragraph.
			if (pattern.Pattern.Length > 1)
			{
				if (m_position == ContextPosition.WordInitial || m_position == ContextPosition.Isolated)
				{
					Debug.Assert(context[offset] == chr[1]);
					// Adjust offset to account for leading space which is actually in the data
					offset--;
				}
			}
			Initialize(chr, offset, context, reference);
		}
Exemplo n.º 10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="ContextInfo"/> class.
		/// </summary>
		/// <param name="pattern">The punctuation pattern.</param>
		/// <param name="tts">The TextTokenSubstring.</param>
		/// ------------------------------------------------------------------------------------
		internal ContextInfo(PuncPattern pattern, TextTokenSubstring tts) :
			this(pattern, tts.Offset, tts.FullTokenText, tts.FirstToken.ScrRefString)
		{
		}