public void TestParse_LessorThanImmeditely_TransitToStartTagFoundState() { var target = new InitialState(); var next = target.Parse(new StringReader("<")); Assert.That(next, Is.TypeOf <StartTagFoundState>()); }
private static void TestParseCore( string content, string expected, bool writeBom ) { using ( var buffer = new MemoryStream() ) { if ( writeBom ) { var bom = Encoding.UTF8.GetPreamble(); buffer.Write( bom, 0, bom.Length ); } var contentBytes = Encoding.UTF8.GetBytes( content ); buffer.Write( contentBytes, 0, contentBytes.Length ); buffer.Position = 0; SvcDirectiveParserState target = new InitialState(); using ( var reader = new StreamReader( buffer ) ) { do { target = target.Parse( reader ); } while ( !target.IsFinished ); } Assert.That( target.Directive.Service, Is.EqualTo( expected ) ); } }
private static void TestParseCore(string content, string expected, bool writeBom) { using (var buffer = new MemoryStream()) { if (writeBom) { var bom = Encoding.UTF8.GetPreamble(); buffer.Write(bom, 0, bom.Length); } var contentBytes = Encoding.UTF8.GetBytes(content); buffer.Write(contentBytes, 0, contentBytes.Length); buffer.Position = 0; SvcDirectiveParserState target = new InitialState(); using (var reader = new StreamReader(buffer)) { do { target = target.Parse(reader); }while (!target.IsFinished); } Assert.That(target.Directive.Service, Is.EqualTo(expected)); } }
/// <summary> /// Parses content as <see cref="ServiceHostDirective"/>. /// </summary> /// <param name="input"><see cref="TextReader"/> to read the content.</param> /// <returns>Parsed <see cref="ServiceHostDirective"/>.</returns> public static ServiceHostDirective Parse(TextReader input) { Contract.Assert(input != null); SvcDirectiveParserState state = new InitialState(); while (!state.IsFinished) { state = state.Parse(input); } return(state.Directive); }
/// <summary> /// Parses content as <see cref="ServiceHostDirective"/>. /// </summary> /// <param name="input"><see cref="TextReader"/> to read the content.</param> /// <returns>Parsed <see cref="ServiceHostDirective"/>.</returns> public static ServiceHostDirective Parse( TextReader input ) { Contract.Assert( input != null ); SvcDirectiveParserState state = new InitialState(); while ( !state.IsFinished ) { state = state.Parse( input ); } return state.Directive; }
public void TestParse_TrailingWhitespace_ProceedsByOneAndFinallyTransitToStartTagFoundState() { SvcDirectiveParserState target = new InitialState(); var reader = new StringReader( " \u3000\t<" ); for ( int i = 0; i < 4; i++ ) { Assert.That( target.IsFinished, Is.False ); Assert.That( target, Is.TypeOf<InitialState>() ); target = target.Parse( reader ); } Assert.That( target, Is.TypeOf<StartTagFoundState>() ); }
public void TestParse_TrailingWhitespace_ProceedsByOneAndFinallyTransitToStartTagFoundState() { SvcDirectiveParserState target = new InitialState(); var reader = new StringReader(" \u3000\t<"); for (int i = 0; i < 4; i++) { Assert.That(target.IsFinished, Is.False); Assert.That(target, Is.TypeOf <InitialState>()); target = target.Parse(reader); } Assert.That(target, Is.TypeOf <StartTagFoundState>()); }
public void TestParse_LineNumberAndPosition() { SvcDirectiveParserState target = new InitialState(); var reader = new StringReader( " \r\n <" ); Assert.That( target.Position, Is.EqualTo( 0 ) ); Assert.That( target.LineNumber, Is.EqualTo( 1 ) ); target = target.Parse( reader ); Assert.That( target.Position, Is.EqualTo( 1 ) ); Assert.That( target.LineNumber, Is.EqualTo( 1 ) ); target = target.Parse( reader ); Assert.That( target.Position, Is.EqualTo( 2 ) ); Assert.That( target.LineNumber, Is.EqualTo( 1 ) ); target = target.Parse( reader ); Assert.That( target.Position, Is.EqualTo( 3 ) ); Assert.That( target.LineNumber, Is.EqualTo( 1 ) ); target = target.Parse( reader ); Assert.That( target.Position, Is.EqualTo( 0 ) ); Assert.That( target.LineNumber, Is.EqualTo( 2 ) ); target = target.Parse( reader ); Assert.That( target.Position, Is.EqualTo( 1 ) ); Assert.That( target.LineNumber, Is.EqualTo( 2 ) ); target = target.Parse( reader ); Assert.That( target.Position, Is.EqualTo( 2 ) ); Assert.That( target.LineNumber, Is.EqualTo( 2 ) ); Assert.That( target, Is.TypeOf<StartTagFoundState>() ); }
public void TestParse_LineNumberAndPosition() { SvcDirectiveParserState target = new InitialState(); var reader = new StringReader(" \r\n <"); Assert.That(target.Position, Is.EqualTo(0)); Assert.That(target.LineNumber, Is.EqualTo(1)); target = target.Parse(reader); Assert.That(target.Position, Is.EqualTo(1)); Assert.That(target.LineNumber, Is.EqualTo(1)); target = target.Parse(reader); Assert.That(target.Position, Is.EqualTo(2)); Assert.That(target.LineNumber, Is.EqualTo(1)); target = target.Parse(reader); Assert.That(target.Position, Is.EqualTo(3)); Assert.That(target.LineNumber, Is.EqualTo(1)); target = target.Parse(reader); Assert.That(target.Position, Is.EqualTo(0)); Assert.That(target.LineNumber, Is.EqualTo(2)); target = target.Parse(reader); Assert.That(target.Position, Is.EqualTo(1)); Assert.That(target.LineNumber, Is.EqualTo(2)); target = target.Parse(reader); Assert.That(target.Position, Is.EqualTo(2)); Assert.That(target.LineNumber, Is.EqualTo(2)); Assert.That(target, Is.TypeOf <StartTagFoundState>()); }
public void TestParse_NonWhitespace() { var target = new InitialState(); var next = target.Parse(new StringReader("a")); }
public void TestParse_NonWhitespace() { var target = new InitialState(); var next = target.Parse( new StringReader( "a" ) ); }
public void TestParse_LessorThanImmeditely_TransitToStartTagFoundState() { var target = new InitialState(); var next = target.Parse( new StringReader( "<" ) ); Assert.That( next, Is.TypeOf<StartTagFoundState>() ); }