public void SourceText_NextName_InvalidNames( string text, int offset, int errorAbsoluteIndex, int errorLine, int errorLineIndex) { try { // query against the validation directly // to force some exceptions that would not occur due to extraction delimiters var source = new SourceText(text.AsMemory(), offset); var location = source.RetrieveCurrentLocation(); var slice = source.Next(text.Length - offset); NameValidator.Instance.ValidateOrThrow(source, slice, location); } catch (GraphQLSyntaxException ex) { Assert.IsNotNull(ex.Location); Assert.AreEqual(errorAbsoluteIndex, ex.Location.AbsoluteIndex); Assert.AreEqual(errorLine, ex.Location.LineNumber); Assert.AreEqual(errorLineIndex, ex.Location.LineIndex); return; } catch (Exception e) { Assert.Fail($"Expected a {typeof(GraphQLSyntaxException).Name} to be thrown but recieved {e.GetType().Name}."); return; } Assert.Fail($"Expected a {typeof(GraphQLSyntaxException).Name} to be thrown but no throw occured."); }
public void SourceText_Peek_AtEndOfText_ReturnsEmpty() { var source = new SourceText("123".AsMemory()); while (source.HasData) { source.Next(); } Assert.IsTrue(ReadOnlySpan <char> .Empty == source.Peek(3)); }
public void SourceText_NextFilter_FromEndOfLength() { var source = new SourceText("123".AsMemory()); var result = source.Next(source.Length); Assert.AreEqual("123", result.ToString()); Assert.AreEqual(3, source.Cursor); result = source.NextFilter(char.IsDigit); Assert.AreEqual(string.Empty, result.ToString()); Assert.AreEqual(3, source.Cursor); }
public void SourceText_Next(string text, int offset, int count, string expectedText, int expectedCursorIndex) { if (count >= 0) { var source = new SourceText(text.AsMemory(), offset); var next = source.Next(count); Assert.AreEqual(expectedText, next.ToString()); Assert.AreEqual(expectedCursorIndex, source.Cursor); } else { Assert.Throws <ArgumentOutOfRangeException>(() => { var source = new SourceText(text.AsMemory(), offset); var next = source.Next(count); }); } }
public void SourceText_Next_ContinuesToReturnDataTillEmpty() { var text = "12345"; var source = new SourceText(text.AsMemory()); var i = 0; while (source.HasData) { if (i > 5) { Assert.Fail("Source Text did not properly signal it had emptied its data queue at the appropriate time"); } var data = source.Next(); Assert.AreEqual(1, data.Length); Assert.AreEqual(text[i], data[0]); i++; } // esnure 5 iterations occured Assert.AreEqual(5, i); Assert.AreEqual(5, source.Cursor); }
public void SourceText_NextComment_InvalidString(string text) { // direct test of error conditions against hte validator as the source extractor // should disallow all conditions by the nature of extracting the next line try { var source = new SourceText(text.AsMemory()); var location = source.RetrieveCurrentLocation(); var result = source.Next(source.Length); CommentPhraseValidator.Instance.ValidateOrThrow(source, result, location); } catch (GraphQLSyntaxException ex) { Assert.IsNotNull(ex.Location); return; } catch (Exception e) { Assert.Fail($"Expected a {typeof(GraphQLSyntaxException).Name} to be thrown but recieved {e.GetType().Name}."); return; } Assert.Fail($"Expected a {typeof(GraphQLSyntaxException).Name} to be thrown but no throw occured."); }