<commit_before>/// The MIT License (MIT)
/// Copyright (c) 2016 Bazinga Technologies Inc

module FSharp.Data.GraphQL.Tests.AstExtensionsTests

open Xunit
open FSharp.Data.GraphQL.Parser
open FSharp.Data.GraphQL.Ast.Extensions

/// Converts line breaks to a single standard to avoid different SO line break termination issues.
let normalize (str : string) = str.Replace("\r\n", "\n")

/// Generates an Ast.Document from a query string, prints it to another
/// query string and expects it to be equal. Input query must be formatted (with line breaks and identation).
/// Identation unit is two empty spaces.
let private printAndAssert (query : string) =
    let document = parse query
    let expected = normalize query
    let actual = normalize <| document.ToQueryString()
    actual |> equals expected

[<Fact>]
let ``Should be able to print a simple query`` () =
    printAndAssert """query q {
  hero {
    name
  }
}"""

[<Fact>]
let ``Should be able to print a simple query with 2 fields`` () =
    printAndAssert """query q {
  hero {
    id
    name
  }
}"""

[<Fact>]
let ``Should be able to print a query with variables`` () =
    printAndAssert """query q($id: String!) {
  hero(id: $id) {
    id
    name
  }
}"""<commit_msg>Added test cases for object inputs for graphql functions like are used by TopBraid EDG. Note these currently fail.<commit_after>/// The MIT License (MIT)
/// Copyright (c) 2016 Bazinga Technologies Inc

module FSharp.Data.GraphQL.Tests.AstExtensionsTests

open Xunit
open FSharp.Data.GraphQL.Parser
open FSharp.Data.GraphQL.Ast.Extensions

/// Converts line breaks to a single standard to avoid different SO line break termination issues.
let normalize (str : string) = str.Replace("\r\n", "\n")

/// Generates an Ast.Document from a query string, prints it to another
/// query string and expects it to be equal. Input query must be formatted (with line breaks and identation).
/// Identation unit is two empty spaces.
let private printAndAssert (query : string) =
    let document = parse query
    let expected = normalize query
    let actual = normalize <| document.ToQueryString()
    actual |> equals expected

[<Fact>]
let ``Should be able to print a simple query`` () =
    printAndAssert """query q {
  hero {
    name
  }
}"""

[<Fact>]
let ``Should be able to print a simple query with 2 fields`` () =
    printAndAssert """query q {
  hero {
    id
    name
  }
}"""

[<Fact>]
let ``Should be able to print a query with variables`` () =
    printAndAssert """query q($id: String!) {
  hero(id: $id) {
    id
    name
  }
}"""

[<Fact>]
let ``Should be able to parse a query with an object input in the internal method`` () =
    printAndAssert """mutation q($id: String!, $name: String!) {
  addHero(input: {id: $id, label: $name })
}"""

[<Fact>]
let ``Should be able to parse a query with an object having array properties input in the internal method`` () =
    printAndAssert """mutation q($id: String!, $name: String!, $friend1: String!) {
  addHero(input: {id: $id, label: $name, friends: [$friend1] })
}"""
{'fraction_non_alphanumeric': 0.12308194580476657, 'fraction_numerical': 0.0039177277179236044, 'mean_word_length': 3.5191740412979353, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2647827', 'n_tokens_mistral': 932, 'n_tokens_neox': 893, 'n_words': 377}