parse.test.h
Go to the documentation of this file.
// -*- C++ -*-
#include <wibble/parse.h>
#include <wibble/test.h>
using namespace wibble;
struct TestParse {
enum TokenId { Invalid, Number };
typedef wibble::Token< TokenId > Token;
struct IOStream {
std::istream &i;
std::string remove() {
char block[1024];
i.read( block, 1023 );
block[i.gcount()] = 0;
return block;
}
bool eof() {
return i.eof();
}
IOStream( std::istream &i ) : i( i ) {}
};
struct Lexer : wibble::Lexer< Token, IOStream >
{
Token remove() {
this->skipWhitespace();
this->match( isdigit, isdigit, Number );
return this->decide();
}
Lexer( IOStream &s )
: wibble::Lexer< Token, IOStream >( s )
{}
};
Test lexer() {
std::stringstream s;
IOStream is( s );
Token t;
Lexer l( is );
s << "1 2";
t = l.remove();
assert_eq( t.id, Number );
assert_eq( t.data, "1" );
t = l.remove();
assert_eq( t.id, Number );
assert_eq( t.data, "2" );
t = l.remove();
assert_eq( t.id, Invalid );
}
};
TestParse::Lexer::remove
Token remove()
Definition: parse.test.h:32
wibble::Token::data
std::string data
Definition: parse.h:32
wibble::Lexer
Definition: parse.h:65
Test
void Test
Definition: test.h:178
parse.h
test.h
TestParse::IOStream::eof
bool eof()
Definition: parse.test.h:23
assert_eq
#define assert_eq(x, y)
Definition: test.h:33
TestParse::IOStream::i
std::istream & i
Definition: parse.test.h:14
TestParse::Token
wibble::Token< TokenId > Token
Definition: parse.test.h:11
TestParse::TokenId
TokenId
Definition: parse.test.h:10
TestParse::lexer
Test lexer()
Definition: parse.test.h:43
wibble::Token
Definition: parse.h:29
wibble
Definition: amorph.h:17
wibble::Token::id
Id id
Definition: parse.h:31
TestParse::IOStream::IOStream
IOStream(std::istream &i)
Definition: parse.test.h:27
TestParse::Lexer::Lexer
Lexer(IOStream &s)
Definition: parse.test.h:38
TestParse
Definition: parse.test.h:9
TestParse::Lexer
Definition: parse.test.h:30
TestParse::IOStream
Definition: parse.test.h:13