use crate::ByteSpan;
use crate::GraphQLParser;
use crate::ParseResult;
use crate::SourceMap;
use crate::ast;
use crate::token::GraphQLToken;
use crate::token::GraphQLTokenKind;
use crate::token::GraphQLTokenSource;
use smallvec::smallvec;
pub fn mock_token(kind: GraphQLTokenKind<'static>) -> GraphQLToken<'static> {
GraphQLToken {
kind,
preceding_trivia: smallvec![],
span: ByteSpan::new(0, 0),
}
}
pub fn mock_name_token(name: &str) -> GraphQLToken<'static> {
mock_token(GraphQLTokenKind::name_owned(name.to_string()))
}
pub fn mock_eof_token() -> GraphQLToken<'static> {
mock_token(GraphQLTokenKind::Eof)
}
pub struct MockTokenSource {
tokens: std::vec::IntoIter<GraphQLToken<'static>>,
source_map: SourceMap<'static>,
}
impl MockTokenSource {
pub fn new(tokens: Vec<GraphQLToken<'static>>) -> Self {
Self {
tokens: tokens.into_iter(),
source_map: SourceMap::empty(),
}
}
}
impl Iterator for MockTokenSource {
type Item = GraphQLToken<'static>;
fn next(&mut self) -> Option<Self::Item> {
self.tokens.next()
}
}
impl GraphQLTokenSource<'static> for MockTokenSource {
fn source_map(&self) -> &SourceMap<'static> {
&self.source_map
}
fn into_source_map(self) -> SourceMap<'static> {
self.source_map
}
}
pub(super) fn parse_schema(source: &str) -> ParseResult<'_, ast::Document<'_>> {
GraphQLParser::new(source).parse_schema_document()
}
pub(super) fn parse_executable(
source: &str,
) -> ParseResult<'_, ast::Document<'_>> {
GraphQLParser::new(source).parse_executable_document()
}
pub(super) fn parse_mixed(source: &str) -> ParseResult<'_, ast::Document<'_>> {
GraphQLParser::new(source).parse_mixed_document()
}