libgraphql-parser 0.0.5

A blazing fast, error-focused, lossless GraphQL parser for schema, executable, and mixed documents.
Documentation
//! Tests for [`crate::ast::SelectionSet`] and
//! [`crate::ast::SelectionSetSyntax`].

use crate::ast::FieldSelection;
use crate::ast::Selection;
use crate::ast::SelectionSet;
use crate::ast::tests::ast_test_utils::make_byte_span;
use crate::ast::tests::ast_test_utils::make_name;

/// Verify `SelectionSet` stores a vector of `Selection`
/// items and slices correctly.
///
/// Relevant spec section:
/// https://spec.graphql.org/September2025/#sec-Selection-Sets
///
/// Written by Claude Code, reviewed by a human.
#[test]
fn selection_set_construct_and_source_slice() {
    let source = "{ name }";
    let ss = SelectionSet {
        span: make_byte_span(0, 8),
        selections: vec![Selection::Field(FieldSelection {
            span: make_byte_span(2, 6),
            alias: None,
            name: make_name("name", 2, 6),
            arguments: vec![],
            directives: vec![],
            selection_set: None,
            syntax: None,
        })],
        syntax: None,
    };
    assert_eq!(ss.selections.len(), 1);

    let mut sink = String::new();
    ss.append_source(&mut sink, Some(source));
    assert_eq!(sink, "{ name }");
}